class ExtraFieldComponentType in Flexiform 8
Plugin for extra field components.
Plugin annotation
@FormComponentType(
id = "extra_field",
label = @Translation("Extra Field"),
component_class = "Drupal\flexiform\Plugin\FormComponentType\ExtraFieldComponent",
)
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\ExtraFieldComponentType implements ContainerFactoryPluginInterface
- class \Drupal\flexiform\FormComponent\FormComponentTypeBase implements FormComponentTypeInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of ExtraFieldComponentType
File
- src/
Plugin/ FormComponentType/ ExtraFieldComponentType.php, line 21
Namespace
Drupal\flexiform\Plugin\FormComponentTypeView source
class ExtraFieldComponentType extends FormComponentTypeBase implements ContainerFactoryPluginInterface {
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $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\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityFieldManagerInterface $entity_field_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityFieldManager = $entity_field_manager;
}
/**
* {@inheritdoc}
*/
public function getComponent($name, array $options = []) {
$component = parent::getComponent($name, $options);
$component
->setExtraField($this
->getExtraField($name));
return $component;
}
/**
* {@inheritdoc}
*/
public function componentRows(EntityDisplayFormBase $form_object, array $form, FormStateInterface $form_state) {
$rows = [];
foreach ($this
->getExtraFields() as $component_name => $extra_field) {
$rows[$component_name] = $this
->buildComponentRow($form_object, $component_name, $form, $form_state);
}
return $rows;
}
/**
* {@inheritdoc}
*/
public function submitComponentRow($component_name, $values, array $form, FormStateInterface $form_state) {
$options = $this
->getFormDisplay()
->getComponent($component_name);
$options['weight'] = $values['weight'];
$options['region'] = $values['region'];
return $options;
}
/**
* {@inheritdoc}
*/
public function buildComponentRow(EntityDisplayFormBase $form_object, $component_name, array $form, FormStateInterface $form_state) {
$display_options = $this
->getFormDisplay()
->getComponent($component_name);
$extra_field = $this
->getExtraField($component_name);
$regions = array_keys($form_object
->getRegions());
$extra_field_row = [
'#attributes' => [
'class' => [
'draggable',
'tabledrag-leaf',
],
],
'#row_type' => 'extra_field',
'#region_callback' => [
$form_object,
'getRowRegion',
],
'#js_settings' => [
'rowHandler' => 'field',
],
'human_name' => [
'#markup' => $extra_field['label'],
],
'weight' => [
'#type' => 'textfield',
'#title' => t('Weight for @title', [
'@title' => $extra_field['label'],
]),
'#title_display' => 'invisible',
'#default_value' => $display_options ? $display_options['weight'] : 0,
'#size' => 3,
'#attributes' => [
'class' => [
'field-weight',
],
],
],
'parent_wrapper' => [
'parent' => [
'#type' => 'select',
'#title' => t('Parents for @title', [
'@title' => $extra_field['label'],
]),
'#title_display' => 'invisible',
'#options' => array_combine($regions, $regions),
'#empty_value' => '',
'#attributes' => [
'class' => [
'js-field-parent',
'field-parent',
],
],
'#parents' => [
'fields',
$component_name,
'parent',
],
],
'hidden_name' => [
'#type' => 'hidden',
'#default_value' => $component_name,
'#attributes' => [
'class' => [
'field-name',
],
],
],
],
'region' => [
'#type' => 'select',
'#title' => t('Region for @title', [
'@title' => $extra_field['label'],
]),
'#title_display' => 'invisible',
'#options' => $form_object
->getRegionOptions(),
'#default_value' => $display_options ? $display_options['region'] : 'hidden',
'#attributes' => [
'class' => [
'field-region',
],
],
],
'plugin' => [
'type' => [
'#type' => 'hidden',
'#value' => $display_options ? 'visible' : 'hidden',
'#parents' => [
'fields',
$component_name,
'type',
],
'#attributes' => [
'class' => [
'field-plugin-type',
],
],
],
],
'settings_summary' => [],
'settings_edit' => [],
];
return $extra_field_row;
}
/**
* Get extra fields.
*/
protected function getExtraFields() {
if ($form_entity = $this
->getFormEntityManager()
->getFormEntity('')) {
$extra_fields = $this->entityFieldManager
->getExtraFields($form_entity
->getEntityType(), $form_entity
->getBundle());
return isset($extra_fields['form']) ? $extra_fields['form'] : [];
}
return [];
}
/**
* Get extra field.
*/
protected function getExtraField($component_name) {
$extra_fields = $this
->getExtraFields();
return isset($extra_fields[$component_name]) ? $extra_fields[$component_name] : [];
}
}
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 | |
ExtraFieldComponentType:: |
public | function |
Build a component row for a component of this type. Overrides FormComponentTypeBase:: |
|
ExtraFieldComponentType:: |
public | function |
Overrides FormComponentTypeBase:: |
|
ExtraFieldComponentType:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
ExtraFieldComponentType:: |
public | function |
Get a component object. Overrides FormComponentTypeBase:: |
|
ExtraFieldComponentType:: |
protected | function | Get extra field. | |
ExtraFieldComponentType:: |
protected | function | Get extra fields. | |
ExtraFieldComponentType:: |
public | function |
Overrides FormComponentTypeBase:: |
|
ExtraFieldComponentType:: |
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 | Get applicable renderer plugin options. | 1 |
FormComponentTypeBase:: |
protected | function | Get the default renderer plugin. | 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 | ||
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. |