class FormElementComponent in Flexiform 8
Component class for field widgets.
Hierarchy
- class \Drupal\flexiform\FormComponent\FormComponentBase implements FormComponentInterface
- class \Drupal\flexiform\Plugin\FormComponentType\FormElementComponent implements ContainerFactoryFormComponentInterface, FormComponentWithSubmitInterface, FormComponentWithValidateInterface uses ContextAwarePluginAssignmentTrait, StringTranslationTrait
Expanded class hierarchy of FormElementComponent
File
- src/
Plugin/ FormComponentType/ FormElementComponent.php, line 22
Namespace
Drupal\flexiform\Plugin\FormComponentTypeView source
class FormElementComponent extends FormComponentBase implements ContainerFactoryFormComponentInterface, FormComponentWithSubmitInterface, FormComponentWithValidateInterface {
use ContextAwarePluginAssignmentTrait;
use StringTranslationTrait;
/**
* Element plugin manager service.
*
* @var \Drupal\flexiform\FormElementPluginManager
*/
protected $pluginManager;
/**
* The context handler.
*
* @var \Drupal\Core\Plugin\Context\ContextHandlerInterface
*/
protected $contextHandler;
/**
* The element plugin associated with this componenet.
*
* @var \Drupal\flexiform\FormElement\FormElementInterface
*/
protected $plugin;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $name, array $options, FlexiformEntityFormDisplay $form_display) {
return new static($name, $options, $form_display, $container
->get('plugin.manager.flexiform.form_element'), $container
->get('context.handler'));
}
/**
* {@inheritdoc}
*/
public function __construct($name, $options, FlexiformEntityFormDisplay $form_display, FormElementPluginManager $plugin_manager, ContextHandlerInterface $context_handler) {
parent::__construct($name, $options, $form_display);
$this->pluginManager = $plugin_manager;
$this->contextHandler = $context_handler;
}
/**
* Get the form element plugin.
*/
protected function getPlugin() {
if (empty($this->plugin)) {
$this->plugin = $this->pluginManager
->createInstance($this->options['form_element'], $this->options['settings']);
if ($this->plugin instanceof ContextAwarePluginInterface) {
$this->contextHandler
->applyContextMapping($this->plugin, $this
->getFormEntityManager()
->getContexts());
}
}
return $this->plugin;
}
/**
* Render the component in the form.
*/
public function render(array &$form, FormStateInterface $form_state, RendererInterface $renderer) {
$element = [
'#parents' => $form['#parents'],
'#array_parents' => !empty($form['#array_parents']) ? $form['#array_parents'] : [],
];
$element['#parents'][] = $this->name;
$element['#array_parents'][] = $this->name;
$element += $this
->getPlugin()
->form($element, $form_state);
$form[$this->name] = $element;
}
/**
* {@inheritdoc}
*/
public function extractFormValues(array $form, FormStateInterface $form_state) {
$this
->getPlugin()
->buildEntities($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function formValidate(array $form, FormStateInterface $form_state) {
$this
->getPlugin()
->formValidate($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function formSubmit(array $form, FormStateInterface $form_state) {
$this
->getPlugin()
->formSubmit($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function getAdminLabel() {
return $this->options['admin_label'];
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$sform = [];
$plugin = $this
->getPlugin();
if ($plugin instanceof ContextAwarePluginInterface) {
$contexts = $this
->getFormEntityManager()
->getContexts();
$sform['context_mapping'] = [
'#parents' => array_merge($form['#parents'], [
'settings',
'context_mapping',
]),
] + $this
->addContextAssignmentElement($plugin, $contexts);
}
$sform += $this
->getPlugin()
->settingsForm($sform, $form_state);
return $sform;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = [];
$summary += $this
->getPlugin()
->settingsSummary();
return $summary;
}
/**
* {@inheritdoc}
*/
public function settingsFormSubmit($values, array $form, FormStateInterface $form_state) {
$options = [];
$options += $this
->getPlugin()
->settingsFormSubmit($values, $form, $form_state);
return $options;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContextAwarePluginAssignmentTrait:: |
protected | function | Builds a form element for assigning a context to a given slot. | |
ContextAwarePluginAssignmentTrait:: |
protected | function | Wraps the context handler. | |
ContextAwarePluginAssignmentTrait:: |
abstract protected | function | Ensures the t() method is available. | |
FormComponentBase:: |
protected | property | The form display. | |
FormComponentBase:: |
protected | property | The form entity manager. | |
FormComponentBase:: |
protected | property | The name of this component. | |
FormComponentBase:: |
protected | property | The options supplied for this component. | |
FormComponentBase:: |
protected | function | Get the entity namespace from the component name. | |
FormComponentBase:: |
public | function | ||
FormComponentBase:: |
public | function | ||
FormComponentBase:: |
public | function | ||
FormComponentBase:: |
public | function | ||
FormElementComponent:: |
protected | property | The context handler. | |
FormElementComponent:: |
protected | property | The element plugin associated with this componenet. | |
FormElementComponent:: |
protected | property | Element plugin manager service. | |
FormElementComponent:: |
public static | function |
Creates an instance of the form componenent. Overrides ContainerFactoryFormComponentInterface:: |
|
FormElementComponent:: |
public | function |
Extract the form values. Overrides FormComponentInterface:: |
|
FormElementComponent:: |
public | function |
Perform submission logic. Overrides FormComponentWithSubmitInterface:: |
|
FormElementComponent:: |
public | function |
Perform validation logic. Overrides FormComponentWithValidateInterface:: |
|
FormElementComponent:: |
public | function |
Get the admin label for the component. Overrides FormComponentBase:: |
|
FormElementComponent:: |
protected | function | Get the form element plugin. | |
FormElementComponent:: |
public | function |
Render the component in the form. Overrides FormComponentInterface:: |
|
FormElementComponent:: |
public | function |
Get the settings form. Overrides FormComponentBase:: |
|
FormElementComponent:: |
public | function |
Overrides FormComponentBase:: |
|
FormElementComponent:: |
public | function |
Get the settings summary. Overrides FormComponentBase:: |
|
FormElementComponent:: |
public | function |
Overrides FormComponentBase:: |
|
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 |