X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Ftemplates%2Fmodule%2Fsrc%2FPlugin%2FField%2FFieldWidget%2Ffieldwidget.php.twig;fp=vendor%2Fdrupal%2Fconsole%2Ftemplates%2Fmodule%2Fsrc%2FPlugin%2FField%2FFieldWidget%2Ffieldwidget.php.twig;h=86e88fc908b171a0fdef22f99da5d40fa8236162;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/templates/module/src/Plugin/Field/FieldWidget/fieldwidget.php.twig b/vendor/drupal/console/templates/module/src/Plugin/Field/FieldWidget/fieldwidget.php.twig new file mode 100644 index 000000000..86e88fc90 --- /dev/null +++ b/vendor/drupal/console/templates/module/src/Plugin/Field/FieldWidget/fieldwidget.php.twig @@ -0,0 +1,97 @@ +{% extends "base/class.php.twig" %} + +{% block file_path %} +\Drupal\{{ module }}\Plugin\Field\FieldWidget\{{ class_name }}. +{% endblock %} + +{% block namespace_class %} +namespace Drupal\{{ module }}\Plugin\Field\FieldWidget; +{% endblock %} + +{% block use_class %} +use Drupal\Core\Field\FieldItemListInterface; +use Drupal\Core\Field\WidgetBase; +use Drupal\Core\Form\FormStateInterface; +{% endblock %} + +{% block class_declaration %} +/** + * Plugin implementation of the '{{ plugin_id }}' widget. + * + * @FieldWidget( + * id = "{{ plugin_id }}", + * label = @Translation("{{ label }}"){% if field_type %}, + * field_types = { + * "{{ field_type }}" + * } +{% else %} + + * At least one field_types annotation array entry is necessary to display this formatter in the UI. + * ex. field_types = { "field_type" } +{% endif %} + * ) + */ +class {{ class_name }} extends WidgetBase {% endblock %} +{% block class_methods %} + /** + * {@inheritdoc} + */ + public static function defaultSettings() { + return [ + 'size' => 60, + 'placeholder' => '', + ] + parent::defaultSettings(); + } + + /** + * {@inheritdoc} + */ + public function settingsForm(array $form, FormStateInterface $form_state) { + $elements = []; + + $elements['size'] = [ + '#type' => 'number', + '#title' => t('Size of textfield'), + '#default_value' => $this->getSetting('size'), + '#required' => TRUE, + '#min' => 1, + ]; + $elements['placeholder'] = [ + '#type' => 'textfield', + '#title' => t('Placeholder'), + '#default_value' => $this->getSetting('placeholder'), + '#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'), + ]; + + return $elements; + } + + /** + * {@inheritdoc} + */ + public function settingsSummary() { + $summary = []; + + $summary[] = t('Textfield size: @size', ['@size' => $this->getSetting('size')]); + if (!empty($this->getSetting('placeholder'))) { + $summary[] = t('Placeholder: @placeholder', ['@placeholder' => $this->getSetting('placeholder')]); + } + + return $summary; + } + + /** + * {@inheritdoc} + */ + public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { + $element['value'] = $element + [ + '#type' => 'textfield', + '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL, + '#size' => $this->getSetting('size'), + '#placeholder' => $this->getSetting('placeholder'), + '#maxlength' => $this->getFieldSetting('max_length'), + ]; + + return $element; + } +{% endblock %}