{% extends "base/class.php.twig" %} {% block file_path %} \Drupal\{{module}}\Plugin\views\field\{{class_name}}. {% endblock %} {% block namespace_class %} namespace Drupal\{{module}}\Plugin\views\field; {% endblock %} {% block use_class %} use Drupal\Core\Form\FormStateInterface; use Drupal\Component\Utility\Random; use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\views\ResultRow; {% endblock %} {% block class_declaration %} /** * A handler to provide a field that is completely custom by the administrator. * * @ingroup views_field_handlers * * @ViewsField("{{ class_machine_name }}") */ class {{ class_name }} extends FieldPluginBase {% endblock %} {% block class_methods %} /** * {@inheritdoc} */ public function usesGroupBy() { return FALSE; } /** * {@inheritdoc} */ public function query() { // Do nothing -- to override the parent query. } /** * {@inheritdoc} */ protected function defineOptions() { $options = parent::defineOptions(); $options['hide_alter_empty'] = ['default' => FALSE]; return $options; } /** * {@inheritdoc} */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); } /** * {@inheritdoc} */ public function render(ResultRow $values) { // Return a random text, here you can include your custom logic. // Include any namespace required to call the method required to generate // the desired output. $random = new Random(); return $random->name(); } {% endblock %}