class FieldWidgetComponentType in Flexiform 8
Plugin for field widget component types.
Plugin annotation
@FormComponentType(
id = "field_widget",
label = @Translation("Field Widget"),
component_class = "Drupal\flexiform\Plugin\FormComponentType\FieldWidgetComponent",
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\flexiform\FormComponent\FormComponentTypeBase implements FormComponentTypeInterface
- class \Drupal\flexiform\Plugin\FormComponentType\FieldWidgetComponentType implements ContainerFactoryPluginInterface
- class \Drupal\flexiform\FormComponent\FormComponentTypeBase implements FormComponentTypeInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of FieldWidgetComponentType
File
- src/
Plugin/ FormComponentType/ FieldWidgetComponentType.php, line 25
Namespace
Drupal\flexiform\Plugin\FormComponentTypeView source
class FieldWidgetComponentType extends FormComponentTypeBase implements ContainerFactoryPluginInterface {
/**
* The widget plugin manager.
*
* @var \Drupal\Core\Field\WidgetPluginManager
*/
protected $pluginManager;
/**
* Field type definitions.
*
* @var array
*/
protected $fieldTypes;
/**
* Field defintiions.
*
* @var array
*/
protected $fieldDefinitions;
/**
* The entity field manager.
*
* @var array
*/
protected $entityFieldManager;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('plugin.manager.field.widget'), $container
->get('plugin.manager.field.field_type'), $container
->get('entity_field.manager'));
}
/**
* Construct a new FieldWidgetComponentType object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Field\WidgetPluginManager $plugin_manager
* The plugin type manager.
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
* The field type plugin manager.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, WidgetPluginManager $plugin_manager, FieldTypePluginManagerInterface $field_type_manager, EntityFieldManagerInterface $entity_field_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->fieldTypes = $field_type_manager
->getDefinitions();
$this->pluginManager = $plugin_manager;
$this->entityFieldManager = $entity_field_manager;
}
/**
* Get the field definitions.
*/
protected function getFieldDefinitions() {
if (empty($this->fieldDefinitions)) {
foreach ($this
->getFormEntityManager()
->getFormEntities() as $namespace => $form_entity) {
foreach ($this->entityFieldManager
->getFieldDefinitions($form_entity
->getEntityType(), $form_entity
->getBundle()) as $field_name => $field_definition) {
if ($this
->getFormDisplay()
->getMode() === EntityDisplayBase::CUSTOM_MODE || $field_definition
->getDisplayOptions('form')) {
// Give field definitions a clone for form entities so that
// overrides don't copy accross two different fields.
$component_name = !empty($namespace) ? "{$namespace}:{$field_name}" : $field_name;
$this->fieldDefinitions[$component_name] = clone $field_definition;
// Apply overrides.
$component_options = $this
->getFormDisplay()
->getComponent($component_name);
if (!empty($component_options['third_party_settings']['flexiform']['field_definition'])) {
$def_overrides = $component_options['third_party_settings']['flexiform']['field_definition'];
if (!empty($def_overrides['label'])) {
$this->fieldDefinitions[$component_name]
->setLabel($def_overrides['label']);
}
if (!empty($def_overrides['settings'])) {
$settings = $this->fieldDefinitions[$component_name]
->getSettings();
$settings = NestedArray::mergeDeep($settings, $def_overrides['settings']);
$this->fieldDefinitions[$component_name]
->setSettings($settings);
}
}
}
}
}
}
return $this->fieldDefinitions;
}
/**
* Get a field definition.
*/
protected function getFieldDefinition($component_name) {
$defs = $this
->getFieldDefinitions();
return !empty($defs[$component_name]) ? $defs[$component_name] : NULL;
}
/**
* {@inheritdoc}
*/
public function getComponent($name, array $options = []) {
$component = parent::getComponent($name, $options);
if ($field_definition = $this
->getFieldDefinition($name)) {
$component
->setFieldDefinition($this
->getFieldDefinition($name));
}
return $component;
}
/**
* {@inheritdoc}
*/
public function componentRows(EntityDisplayFormBase $form_object, array $form, FormStateInterface $form_state) {
$rows = [];
foreach ($this
->getFieldDefinitions() as $component_name => $field_definition) {
if ($field_definition
->isDisplayConfigurable('form')) {
$rows[$component_name] = $this
->buildComponentRow($form_object, $component_name, $form, $form_state);
}
}
return $rows;
}
/**
* {@inheritdoc}
*/
protected function getApplicableRendererPluginOptions($component_name) {
$field_definition = $this
->getFieldDefinition($component_name);
if (!$field_definition) {
print "NAME: " . $component_name;
}
$options = $this->pluginManager
->getOptions($field_definition
->getType());
$applicable_options = [];
foreach ($options as $option => $label) {
$plugin_class = DefaultFactory::getPluginClass($option, $this->pluginManager
->getDefinition($option));
if ($plugin_class::isApplicable($field_definition)) {
$applicable_options[$option] = $label;
}
}
return $applicable_options;
}
/**
* {@inheritdoc}
*/
protected function getDefaultRendererPlugin($component_name) {
$type = $this
->getFieldDefinition($component_name)
->getType();
return isset($this->fieldTypes[$type]['default_widget']) ? $this->fieldTypes[$type]['default_widget'] : NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FieldWidgetComponentType:: |
protected | property | The entity field manager. | |
FieldWidgetComponentType:: |
protected | property | Field defintiions. | |
FieldWidgetComponentType:: |
protected | property | Field type definitions. | |
FieldWidgetComponentType:: |
protected | property | The widget plugin manager. | |
FieldWidgetComponentType:: |
public | function |
Overrides FormComponentTypeBase:: |
|
FieldWidgetComponentType:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
FieldWidgetComponentType:: |
protected | function |
Get applicable renderer plugin options. Overrides FormComponentTypeBase:: |
|
FieldWidgetComponentType:: |
public | function |
Get a component object. Overrides FormComponentTypeBase:: |
|
FieldWidgetComponentType:: |
protected | function |
Get the default renderer plugin. Overrides FormComponentTypeBase:: |
|
FieldWidgetComponentType:: |
protected | function | Get a field definition. | |
FieldWidgetComponentType:: |
protected | function | Get the field definitions. | |
FieldWidgetComponentType:: |
public | function |
Construct a new FieldWidgetComponentType object. Overrides PluginBase:: |
|
FormComponentTypeBase:: |
protected | property | A list of components that have been constructed. | |
FormComponentTypeBase:: |
protected | property | The form display. | |
FormComponentTypeBase:: |
protected | property | The form entity manager. | |
FormComponentTypeBase:: |
protected | function | Build a component row for a component of this type. | 1 |
FormComponentTypeBase:: |
public | function |
Get the form display. Overrides FormComponentTypeInterface:: |
|
FormComponentTypeBase:: |
public | function |
Get the form entity manager. Overrides FormComponentTypeInterface:: |
|
FormComponentTypeBase:: |
public | function |
Set the form display. Overrides FormComponentTypeInterface:: |
|
FormComponentTypeBase:: |
public | function | ||
FormComponentTypeBase:: |
public | function | 1 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |