Commit 4fc16f8e authored by alexpott's avatar alexpott

Issue #2035315 by dawehner: Add a dedicated @FieldWidget annotation.

parent 5d649f8b
......@@ -6,7 +6,7 @@
namespace Drupal\datetime\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
......@@ -20,9 +20,8 @@
/**
* Plugin implementation of the 'datetime_datelist' widget.
*
* @Plugin(
* @FieldWidget(
* id = "datetime_datelist",
* module = "datetime",
* label = @Translation("Select list"),
* field_types = {
* "datetime"
......
......@@ -6,7 +6,7 @@
namespace Drupal\datetime\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
......@@ -19,9 +19,8 @@
/**
* Plugin implementation of the 'datetime_default' widget.
*
* @Plugin(
* @FieldWidget(
* id = "datetime_default",
* module = "datetime",
* label = @Translation("Date and time"),
* field_types = {
* "datetime"
......
......@@ -7,16 +7,15 @@
namespace Drupal\email\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
/**
* Plugin implementation of the 'email_default' widget.
*
* @Plugin(
* @FieldWidget(
* id = "email_default",
* module = "email",
* label = @Translation("E-mail"),
* field_types = {
* "email"
......
......@@ -7,16 +7,15 @@
namespace Drupal\entity_reference\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Drupal\entity_reference\Plugin\field\widget\AutocompleteWidgetBase;
/**
* Plugin implementation of the 'entity_reference autocomplete-tags' widget.
*
* @Plugin(
* @FieldWidget(
* id = "entity_reference_autocomplete_tags",
* module = "entity_reference",
* label = @Translation("Autocomplete (Tags style)"),
* description = @Translation("An autocomplete text field."),
* field_types = {
......
......@@ -7,7 +7,7 @@
namespace Drupal\entity_reference\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Drupal\entity_reference\Plugin\field\widget\AutocompleteWidgetBase;
......@@ -19,9 +19,8 @@
* the two widgets, and the Field API doesn't update default settings when
* the widget changes.
*
* @Plugin(
* @FieldWidget(
* id = "entity_reference_autocomplete",
* module = "entity_reference",
* label = @Translation("Autocomplete"),
* description = @Translation("An autocomplete text field."),
* field_types = {
......
<?php
/**
* @file
* Contains \Drupal\field\Annotation\FieldWidget.
*/
namespace Drupal\field\Annotation;
use Drupal\Component\Annotation\Plugin;
/**
* Defines a FieldWidget annotation object.
*
* Widgets handle how fields are displayed in edit forms.
*
* Additional annotation keys for formatters can be defined in
* hook_field_widget_info_alter().
*
* @Annotation
*
* @see \Drupal\field\Plugin\Type\Widget\WidgetPluginManager
* @see \Drupal\field\Plugin\Type\Widget\WidgetInterface
*/
class FieldWidget extends Plugin {
/**
* The plugin ID.
*
* @var string
*/
public $id;
/**
* The human-readable name of the widget type.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public $label;
/**
* A short description of the widget type.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public $description;
/**
* The name of the widget class.
*
* This is not provided manually, it will be added by the discovery mechanism.
*
* @var string
*/
public $class;
/**
* An array of field types the widget supports.
*
* @var array
*/
public $field_types = array();
/**
* An array whose keys are the names of the settings available to the widget
* type, and whose values are the default values for those settings.
*
* @var array
*/
public $settings = array();
/**
* Does the field widget handles multiple values at once.
*
* @var bool
*/
public $multiple_values = FALSE;
/**
* An integer to determine the weight of this widget relative to other widgets
* in the Field UI when selecting a widget for a given field instance.
*
* @var int optional
*/
public $weight = NULL;
}
......@@ -7,6 +7,7 @@
namespace Drupal\field\Plugin\Type\Widget;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Discovery\ProcessDecorator;
use Drupal\Core\Cache\CacheBackendInterface;
......@@ -29,16 +30,6 @@ class WidgetPluginManager extends DefaultPluginManager {
*/
protected $widgetOptions;
/**
* Overrides Drupal\Component\Plugin\PluginManagerBase:$defaults.
*/
protected $defaults = array(
'field_types' => array(),
'settings' => array(),
'multiple_values' => FALSE,
'default_value' => TRUE,
);
/**
* Constructs a WidgetPluginManager object.
*
......@@ -53,7 +44,9 @@ class WidgetPluginManager extends DefaultPluginManager {
* The language manager.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager) {
parent::__construct('field/widget', $namespaces);
$annotation_namespaces = array('Drupal\field\Annotation' => $namespaces['Drupal\field']);
parent::__construct('field/widget', $namespaces, $annotation_namespaces, 'Drupal\field\Annotation\FieldWidget');
$this->setCacheBackend($cache_backend, $language_manager, 'field_widget_types');
$this->alterInfo($module_handler, 'field_widget_info');
......@@ -110,6 +103,22 @@ public function getInstance(array $options) {
return $this->createInstance($plugin_id, $configuration);
}
/**
* {@inheritdoc}
*/
public function createInstance($plugin_id, array $configuration = array()) {
$plugin_definition = $this->discovery->getDefinition($plugin_id);
$plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition);
// If the plugin provides a factory method, pass the container to it.
if (is_subclass_of($plugin_class, 'Drupal\Core\Plugin\ContainerFactoryPluginInterface')) {
return $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition);
}
return new $plugin_class($plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings']);
}
/**
* Merges default values for widget configuration.
*
......
......@@ -7,16 +7,15 @@
namespace Drupal\field\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
/**
* Plugin implementation of the 'Hidden' widget.
*
* @Plugin(
* @FieldWidget(
* id = "hidden",
* module = "field",
* label = @Translation("- Hidden -"),
* multiple_values = TRUE,
* weight = 50
......
......@@ -7,7 +7,7 @@
namespace Drupal\field_test\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
use Symfony\Component\Validator\ConstraintViolationInterface;
......@@ -15,9 +15,8 @@
/**
* Plugin implementation of the 'test_field_widget' widget.
*
* @Plugin(
* @FieldWidget(
* id = "test_field_widget",
* module = "field_test",
* label = @Translation("Test widget"),
* field_types = {
* "test_field",
......
......@@ -7,7 +7,8 @@
namespace Drupal\field_test\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
use Symfony\Component\Validator\ConstraintViolationInterface;
......@@ -19,9 +20,8 @@
*
* @see field_test_field_widget_info_alter()
*
* @Plugin(
* @FieldWidget(
* id = "test_field_widget_multiple",
* module = "field_test",
* label = @Translation("Test widget - multiple"),
* settings = {
* "test_widget_setting_multiple" = "dummy test string"
......
......@@ -7,16 +7,15 @@
namespace Drupal\field_test\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
/**
* Plugin implementation of the 'test_field_widget_no_default' widget.
*
* @Plugin(
* @FieldWidget(
* id = "test_field_widget_no_default",
* module = "field_test",
* label = @Translation("Test widget - no default"),
* field_types = {
* "test_field"
......
......@@ -7,7 +7,7 @@
namespace Drupal\file\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
use Drupal\Core\Entity\EntityInterface;
......@@ -15,9 +15,8 @@
/**
* Plugin implementation of the 'file_generic' widget.
*
* @Plugin(
* @FieldWidget(
* id = "file_generic",
* module = "file",
* label = @Translation("File"),
* field_types = {
* "file"
......
......@@ -7,7 +7,7 @@
namespace Drupal\image\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
use Drupal\file\Plugin\field\widget\FileWidget;
......@@ -16,9 +16,8 @@
/**
* Plugin implementation of the 'image_image' widget.
*
* @Plugin(
* @FieldWidget(
* id = "image_image",
* module = "image",
* label = @Translation("Image"),
* field_types = {
* "image"
......
......@@ -7,16 +7,15 @@
namespace Drupal\link\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
/**
* Plugin implementation of the 'link' widget.
*
* @Plugin(
* @FieldWidget(
* id = "link_default",
* module = "link",
* label = @Translation("Link"),
* field_types = {
* "link"
......
......@@ -7,7 +7,7 @@
namespace Drupal\number\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
use Symfony\Component\Validator\ConstraintViolationInterface;
......@@ -15,9 +15,8 @@
/**
* Plugin implementation of the 'number' widget.
*
* @Plugin(
* @FieldWidget(
* id = "number",
* module = "number",
* label = @Translation("Text field"),
* field_types = {
* "number_integer",
......
......@@ -7,15 +7,14 @@
namespace Drupal\options\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
/**
* Plugin implementation of the 'options_buttons' widget.
*
* @Plugin(
* @FieldWidget(
* id = "options_buttons",
* module = "options",
* label = @Translation("Check boxes/radio buttons"),
* field_types = {
* "list_integer",
......
......@@ -7,15 +7,14 @@
namespace Drupal\options\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
/**
* Plugin implementation of the 'options_onoff' widget.
*
* @Plugin(
* @FieldWidget(
* id = "options_onoff",
* module = "options",
* label = @Translation("Single on/off checkbox"),
* field_types = {
* "list_boolean"
......
......@@ -7,15 +7,14 @@
namespace Drupal\options\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
/**
* Plugin implementation of the 'options_select' widget.
*
* @Plugin(
* @FieldWidget(
* id = "options_select",
* module = "options",
* label = @Translation("Select list"),
* field_types = {
* "list_integer",
......
......@@ -7,16 +7,15 @@
namespace Drupal\taxonomy\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
/**
* Plugin implementation of the 'taxonomy_autocomplete' widget.
*
* @Plugin(
* @FieldWidget(
* id = "taxonomy_autocomplete",
* module = "taxonomy",
* label = @Translation("Autocomplete term widget (tagging)"),
* field_types = {
* "taxonomy_term_reference"
......
......@@ -7,16 +7,15 @@
namespace Drupal\telephone\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
/**
* Plugin implementation of the 'telephone_default' widget.
*
* @Plugin(
* @FieldWidget(
* id = "telephone_default",
* module = "telephone",
* label = @Translation("Telephone number"),
* field_types = {
* "telephone"
......
......@@ -7,16 +7,15 @@
namespace Drupal\text\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
/**
* Plugin implementation of the 'text_textarea' widget.
*
* @Plugin(
* @FieldWidget(
* id = "text_textarea",
* module = "text",
* label = @Translation("Text area (multiple rows)"),
* field_types = {
* "text_long"
......
......@@ -7,16 +7,15 @@
namespace Drupal\text\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Symfony\Component\Validator\ConstraintViolationInterface;
/**
* Plugin implementation of the 'text_textarea_with_summary' widget.
*
* @Plugin(
* @FieldWidget(
* id = "text_textarea_with_summary",
* module = "text",
* label = @Translation("Text area with a summary"),
* field_types = {
* "text_with_summary"
......
......@@ -7,16 +7,15 @@
namespace Drupal\text\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\Annotation\FieldWidget;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
/**
* Plugin implementation of the 'text_textfield' widget.
*
* @Plugin(
* @FieldWidget(
* id = "text_textfield",
* module = "text",
* label = @Translation("Text field"),
* field_types = {
* "text"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment