class MultipleEntityForm in Flexiform 8
Form enhancer for multiple entity forms.
Plugin annotation
@FormEnhancer(
id = "multiple_entities",
label = @Translation("Multiple Entities"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\flexiform\FormEnhancer\FormEnhancerBase implements FormEnhancerInterface
- class \Drupal\flexiform\FormEnhancer\ConfigurableFormEnhancerBase implements ConfigurableFormEnhancerInterface
- class \Drupal\flexiform\Plugin\FormEnhancer\MultipleEntityForm uses StringTranslationTrait, AjaxFormTrait
- class \Drupal\flexiform\FormEnhancer\ConfigurableFormEnhancerBase implements ConfigurableFormEnhancerInterface
- class \Drupal\flexiform\FormEnhancer\FormEnhancerBase implements FormEnhancerInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of MultipleEntityForm
File
- src/
Plugin/ FormEnhancer/ MultipleEntityForm.php, line 19
Namespace
Drupal\flexiform\Plugin\FormEnhancerView source
class MultipleEntityForm extends ConfigurableFormEnhancerBase {
use StringTranslationTrait;
use AjaxFormTrait;
/**
* {@inheritdoc}
*/
protected $supportedEvents = [
'init_form_entity_config',
];
/**
* {@inheritdoc}
*/
public function configurationForm(array $form, FormStateInterface $form_state) {
// Prepare a link to add an entity to this form.
$target_entity_type = $this->formDisplay
->get('targetEntityType');
/** @var \Drupal\Core\Entity\EntityTypeInterface $target_entity_def */
$target_entity_def = \Drupal::service('entity_type.manager')
->getDefinition($target_entity_type);
$url_params = [
'form_mode_name' => $this->formDisplay
->get('mode'),
];
if ($target_entity_def
->get('bundle_entity_type')) {
$url_params[$target_entity_def
->get('bundle_entity_type')] = $this->formDisplay
->get('bundle');
}
else {
if ($target_entity_def
->hasKey('bundle')) {
$url_params['bundle'] = $this->formDisplay
->get('bundle');
}
}
$form['add'] = [
'#type' => 'link',
'#title' => $this
->t('Add Entity'),
'#url' => Url::fromRoute("entity.entity_form_display.{$target_entity_type}.form_mode.form_entity_add", $url_params),
'#attributes' => $this
->getAjaxButtonAttributes(),
'#attached' => [
'library' => [
'core/drupal.ajax',
],
],
];
$form['entities'] = [
'#type' => 'table',
'#header' => [
$this
->t('Entity'),
$this
->t('Plugin'),
$this
->t('Operations'),
],
'#title' => t('Entities'),
'#empty' => t('This form display has no entities yet.'),
];
foreach ($this->formDisplay
->getFormEntityManager($form_state)
->getContexts() as $namespace => $context) {
$operations = [];
if (!empty($namespace)) {
$operation_params = $url_params;
$operation_params['entity_namespace'] = $namespace;
$operations['edit'] = [
'title' => $this
->t('Edit'),
'weight' => 10,
'url' => Url::fromRoute("entity.entity_form_display.{$target_entity_type}.form_mode.form_entity_edit", $operation_params),
'attributes' => $this
->getAjaxButtonAttributes(),
];
}
$form['entities'][$namespace] = [
'human_name' => [
'#plain_text' => $context
->getContextDefinition()
->getLabel(),
],
'plugin' => [
'#plain_text' => $context
->getFormEntity()
->getLabel(),
],
'operations' => [
'#type' => 'operations',
'#links' => $operations,
'#attached' => [
'library' => [
'core/drupal.ajax',
],
],
],
];
}
return $form;
}
/**
* Initialise the enhancer config.
*
* @return array
* The initial config for the enhancer.
*/
public function initFormEntityConfig() {
return !empty($this->configuration['entities']) ? $this->configuration['entities'] : [];
}
/**
* Get the config for an entity namespace.
*
* @return array|false
* The entity config or FALSE if it doesn't exist.
*/
public function getFormEntityConfig($namespace) {
return $this->configuration['entities'][$namespace] ?? FALSE;
}
/**
* Set the config for an entity namespace.
*
* @return $this
* The form enhancer.
*
* @todo: Rename to setFormEntityConfig()?
*/
public function addFormEntityConfig($namespace, $configuration) {
$this->configuration['entities'][$namespace] = $configuration;
return $this;
}
/**
* Remove an entity namespace.
*
* @return $this
* The form enhancer.
*/
public function removeFormEntityConfig($namespace) {
unset($this->configuration['entities'][$namespace]);
return $this;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AjaxFormTrait:: |
public static | function | Gets attributes for use with an AJAX modal. | |
AjaxFormTrait:: |
public static | function | Gets attributes for use with an add button AJAX modal. | |
ConfigurableFormEnhancerBase:: |
public | function |
Whether this enhancer applies to a particular event. Overrides FormEnhancerBase:: |
1 |
ConfigurableFormEnhancerBase:: |
public | function |
The configuration form submit callback. Overrides ConfigurableFormEnhancerInterface:: |
5 |
ConfigurableFormEnhancerBase:: |
public | function |
The configuration form validation callback. Overrides ConfigurableFormEnhancerInterface:: |
|
ConfigurableFormEnhancerBase:: |
public | function |
Get the configuration. Overrides ConfigurableFormEnhancerInterface:: |
|
ConfigurableFormEnhancerBase:: |
public | function |
Set the configuration for the enhancer. Overrides ConfigurableFormEnhancerInterface:: |
|
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 | |
FormEnhancerBase:: |
protected | property | The form display entity. | |
FormEnhancerBase:: |
protected | function | Get the form display. | |
FormEnhancerBase:: |
public | function |
Set the form display object. Overrides FormEnhancerInterface:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
MultipleEntityForm:: |
protected | property |
An array of supported events. Overrides FormEnhancerBase:: |
|
MultipleEntityForm:: |
public | function | Set the config for an entity namespace. | |
MultipleEntityForm:: |
public | function |
The configuration form. Overrides ConfigurableFormEnhancerInterface:: |
|
MultipleEntityForm:: |
public | function | Get the config for an entity namespace. | |
MultipleEntityForm:: |
public | function | Initialise the enhancer config. | |
MultipleEntityForm:: |
public | function | Remove an entity namespace. | |
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. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
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. |