{% import '@lib/di.twig' as di %} t('Example'), * 'help' => t('Custom example field.'), * 'id' => 'foo_example', * ]; * } * @endcode */ #[ViewsField('{{ plugin_id }}')] final class {{ class }} extends FieldPluginBase { {% if services %} /** * Constructs a new {{ class }} instance. */ public function __construct( array $configuration, $plugin_id, $plugin_definition, {{ di.signature(services) }} ) { parent::__construct($configuration, $plugin_id, $plugin_definition); } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): self { return new self( $configuration, $plugin_id, $plugin_definition, {{ di.container(services) }} ); } {% endif %} {% if configurable %} /** * {@inheritdoc} */ protected function defineOptions(): array { $options = parent::defineOptions(); $options['example'] = ['default' => '']; return $options; } /** * {@inheritdoc} */ public function buildOptionsForm(&$form, FormStateInterface $form_state): void { parent::buildOptionsForm($form, $form_state); $form['example'] = [ '#type' => 'textfield', '#title' => $this->t('Example'), '#default_value' => $this->options['example'], ]; } {% endif %} /** * {@inheritdoc} */ public function query(): void { // For non-existent columns (i.e. computed fields) this method must be // empty. } /** * {@inheritdoc} */ public function render(ResultRow $values): string|MarkupInterface { $value = parent::render($values); // @todo Modify or replace the rendered value here. return $value; } }