class Custom
Same name and namespace in other branches
- 11.x core/modules/views/src/Plugin/views/field/Custom.php \Drupal\views\Plugin\views\field\Custom
- 10 core/modules/views/src/Plugin/views/field/Custom.php \Drupal\views\Plugin\views\field\Custom
- 8.9.x core/modules/views/src/Plugin/views/field/Custom.php \Drupal\views\Plugin\views\field\Custom
A handler to provide a field that is completely custom by the administrator.
Plugin annotation
@ViewsField("custom");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
- class \Drupal\views\Plugin\views\PluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\views\Plugin\views\HandlerBase implements \Drupal\views\Plugin\views\ViewsHandlerInterface extends \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\field\FieldPluginBase implements \Drupal\views\Plugin\views\field\FieldHandlerInterface extends \Drupal\views\Plugin\views\HandlerBase
- class \Drupal\views\Plugin\views\field\Custom extends \Drupal\views\Plugin\views\field\FieldPluginBase
- class \Drupal\views\Plugin\views\field\FieldPluginBase implements \Drupal\views\Plugin\views\field\FieldHandlerInterface extends \Drupal\views\Plugin\views\HandlerBase
- class \Drupal\views\Plugin\views\HandlerBase implements \Drupal\views\Plugin\views\ViewsHandlerInterface extends \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\PluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of Custom
Related topics
135 string references to 'Custom'
- BlockSettingsTest::providerTestTransform in core/
modules/ block/ tests/ src/ Unit/ Plugin/ migrate/ process/ BlockSettingsTest.php - Provides data for testTransform.
- Boolean::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ field/ Boolean.php - Boolean::init in core/
modules/ views/ src/ Plugin/ views/ field/ Boolean.php - Boolean::render in core/
modules/ views/ src/ Plugin/ views/ field/ Boolean.php - BooleanFormatter::getOutputFormats in core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldFormatter/ BooleanFormatter.php - Gets the available format options.
File
-
core/
modules/ views/ src/ Plugin/ views/ field/ Custom.php, line 17
Namespace
Drupal\views\Plugin\views\fieldView source
class Custom extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function usesGroupBy() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function query() {
// do nothing -- to override the parent query.
}
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
// Override the alter text option to always alter the text.
$options['alter']['contains']['alter_text'] = [
'default' => TRUE,
];
$options['hide_alter_empty'] = [
'default' => FALSE,
];
return $options;
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
// Remove the checkbox
unset($form['alter']['alter_text']);
unset($form['alter']['text']['#states']);
unset($form['alter']['help']['#states']);
$form['#pre_render'][] = [
$this,
'preRenderCustomForm',
];
}
/**
* {@inheritdoc}
*/
public static function trustedCallbacks() {
$callbacks = parent::trustedCallbacks();
$callbacks[] = 'preRenderCustomForm';
return $callbacks;
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
// Return the text, so the code never thinks the value is empty.
return ViewsRenderPipelineMarkup::create(Xss::filterAdmin($this->options['alter']['text']));
}
/**
* Prerender function to move the textarea to the top of a form.
*
* @param array $form
* The form build array.
*
* @return array
* The modified form build array.
*/
public function preRenderCustomForm($form) {
$form['text'] = $form['alter']['text'];
$form['help'] = $form['alter']['help'];
unset($form['alter']['text']);
unset($form['alter']['help']);
return $form;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.