annotate vendor/chi-teck/drupal-code-generator/templates/d8/plugin/views/field.twig @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
rev   line source
Chris@5 1 {% import 'lib/di.twig' as di %}
Chris@0 2 <?php
Chris@0 3
Chris@0 4 namespace Drupal\{{ machine_name }}\Plugin\views\field;
Chris@0 5
Chris@5 6 {% sort %}
Chris@0 7 use Drupal\views\Plugin\views\field\FieldPluginBase;
Chris@0 8 use Drupal\views\ResultRow;
Chris@5 9 {% if configurable %}
Chris@5 10 use Drupal\Core\Form\FormStateInterface;
Chris@5 11 {% endif %}
Chris@5 12 {% if services %}
Chris@5 13 {{ di.use(services) }}
Chris@5 14 use Symfony\Component\DependencyInjection\ContainerInterface;
Chris@5 15 {% endif %}
Chris@5 16 {% endsort %}
Chris@0 17
Chris@0 18 /**
Chris@0 19 * Provides {{ plugin_label }} field handler.
Chris@0 20 *
Chris@0 21 * @ViewsField("{{ plugin_id }}")
Chris@5 22 *
Chris@5 23 * @DCG
Chris@5 24 * The plugin needs to be assigned to a specific table column through
Chris@5 25 * hook_views_data() or hook_views_data_alter().
Chris@5 26 * For non-existent columns (i.e. computed fields) you need to override
Chris@5 27 * self::query() method.
Chris@0 28 */
Chris@0 29 class {{ class }} extends FieldPluginBase {
Chris@0 30
Chris@5 31 {% if services %}
Chris@5 32 {{ di.properties(services) }}
Chris@5 33
Chris@5 34 /**
Chris@5 35 * Constructs a new {{ class }} instance.
Chris@5 36 *
Chris@5 37 * @param array $configuration
Chris@5 38 * The plugin configuration, i.e. an array with configuration values keyed
Chris@5 39 * by configuration option name. The special key 'context' may be used to
Chris@5 40 * initialize the defined contexts by setting it to an array of context
Chris@5 41 * values keyed by context names.
Chris@5 42 * @param string $plugin_id
Chris@5 43 * The plugin_id for the plugin instance.
Chris@5 44 * @param mixed $plugin_definition
Chris@5 45 * The plugin implementation definition.
Chris@5 46 {{ di.annotation(services) }}
Chris@5 47 */
Chris@5 48 public function __construct(array $configuration, $plugin_id, $plugin_definition, {{ di.signature(services) }}) {
Chris@5 49 parent::__construct($configuration, $plugin_id, $plugin_definition);
Chris@5 50 {{ di.assignment(services) }}
Chris@5 51 }
Chris@5 52
Chris@5 53 /**
Chris@5 54 * {@inheritdoc}
Chris@5 55 */
Chris@5 56 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
Chris@5 57 return new static(
Chris@5 58 $configuration,
Chris@5 59 $plugin_id,
Chris@5 60 $plugin_definition,
Chris@5 61 {{ di.container(services) }}
Chris@5 62 );
Chris@5 63 }
Chris@5 64
Chris@5 65 {% endif %}
Chris@5 66 {% if configurable %}
Chris@0 67 /**
Chris@0 68 * {@inheritdoc}
Chris@0 69 */
Chris@0 70 protected function defineOptions() {
Chris@0 71 $options = parent::defineOptions();
Chris@5 72 $options['example'] = ['default' => ''];
Chris@0 73 return $options;
Chris@0 74 }
Chris@0 75
Chris@0 76 /**
Chris@0 77 * {@inheritdoc}
Chris@0 78 */
Chris@0 79 public function buildOptionsForm(&$form, FormStateInterface $form_state) {
Chris@0 80 parent::buildOptionsForm($form, $form_state);
Chris@5 81 $form['example'] = [
Chris@0 82 '#type' => 'textfield',
Chris@5 83 '#title' => $this->t('Example'),
Chris@5 84 '#default_value' => $this->options['example'],
Chris@0 85 ];
Chris@0 86 }
Chris@0 87
Chris@5 88 {% endif %}
Chris@0 89 /**
Chris@0 90 * {@inheritdoc}
Chris@0 91 */
Chris@0 92 public function render(ResultRow $values) {
Chris@5 93 $value = parent::render($values);
Chris@5 94 // @DCG Modify or replace the rendered value here.
Chris@5 95 return $value;
Chris@0 96 }
Chris@0 97
Chris@0 98 }