class EntityReferenceLayoutRevisioned in Entity Reference with Layout 8
Entity Reference Layout Revisioned field type.
Plugin annotation
@FieldType(
id = "entity_reference_layout_revisioned",
label = @Translation("Entity Reference with Layout"),
description = @Translation("An entity field with layouts containing revisioned entity references."),
category = @Translation("Reference revisions"),
default_widget = "entity_reference_layout_widget",
default_formatter = "entity_reference_layout",
list_class = "\Drupal\entity_reference_layout\EntityReferenceLayoutRevisionsFieldItemList",
)
Hierarchy
- class \Drupal\Core\TypedData\TypedData implements PluginInspectionInterface, TypedDataInterface uses DependencySerializationTrait, StringTranslationTrait, TypedDataTrait
- class \Drupal\Core\TypedData\Plugin\DataType\Map implements \Drupal\Core\TypedData\Plugin\DataType\IteratorAggregate, ComplexDataInterface
- class \Drupal\Core\Field\FieldItemBase implements FieldItemInterface
- class \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem implements PreconfiguredFieldUiOptionsInterface, OptionsProviderInterface
- class \Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem implements PreconfiguredFieldUiOptionsInterface, OptionsProviderInterface
- class \Drupal\entity_reference_layout\Plugin\Field\FieldType\EntityReferenceLayoutRevisioned uses StringTranslationTrait
- class \Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem implements PreconfiguredFieldUiOptionsInterface, OptionsProviderInterface
- class \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem implements PreconfiguredFieldUiOptionsInterface, OptionsProviderInterface
- class \Drupal\Core\Field\FieldItemBase implements FieldItemInterface
- class \Drupal\Core\TypedData\Plugin\DataType\Map implements \Drupal\Core\TypedData\Plugin\DataType\IteratorAggregate, ComplexDataInterface
Expanded class hierarchy of EntityReferenceLayoutRevisioned
2 files declare their use of EntityReferenceLayoutRevisioned
File
- src/
Plugin/ Field/ FieldType/ EntityReferenceLayoutRevisioned.php, line 25
Namespace
Drupal\entity_reference_layout\Plugin\Field\FieldTypeView source
class EntityReferenceLayoutRevisioned extends EntityReferenceRevisionsItem {
use StringTranslationTrait;
/**
* Define field properties.
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties = parent::propertyDefinitions($field_definition);
$properties['region'] = DataDefinition::create('string')
->setLabel(t('Region'));
$properties['layout'] = DataDefinition::create('string')
->setLabel(t('Layout'));
$properties['section_id'] = DataDefinition::create('integer')
->setLabel(t('Section ID'));
$properties['options'] = DataDefinition::create('any')
->setLabel(t('Options'));
$properties['config'] = DataDefinition::create('any')
->setLabel(t('Config'));
return $properties;
}
/**
* Define field schema.
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
$schema = parent::schema($field_definition);
$schema['columns']['region'] = [
'type' => 'varchar',
'length' => '60',
'not null' => FALSE,
];
$schema['columns']['layout'] = [
'type' => 'varchar',
'length' => '60',
'not null' => FALSE,
];
$schema['columns']['section_id'] = [
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
];
$schema['columns']['options'] = [
'type' => 'blob',
'size' => 'normal',
'serialize' => TRUE,
'not null' => FALSE,
];
$schema['columns']['config'] = [
'type' => 'blob',
'size' => 'normal',
'serialize' => TRUE,
'not null' => FALSE,
];
return $schema;
}
/**
* Manipulate field data to be saved as configuration.
*/
public static function fieldSettingsToConfigData(array $settings) {
$settings = parent::fieldSettingsToConfigData($settings);
$allowed_layouts = [];
$selected_layouts = isset($settings['handler_settings']['allowed_layouts']) ? $settings['handler_settings']['allowed_layouts'] : [];
$layout_groups = \Drupal::service('plugin.manager.core.layout')
->getLayoutOptions();
foreach ($layout_groups as $group => $layouts) {
foreach ($layouts as $name => $value) {
if (!empty($selected_layouts[$group][$name])) {
$allowed_layouts[$group][$name] = $value;
}
}
}
$settings['handler_settings']['allowed_layouts'] = $allowed_layouts;
return $settings;
}
/**
* Manipulate saved data into configuration.
*
* Set 'layout_bundles' configuration item as an array even though it
* may be stored as a string in case we support attaching layouts to
* multiple bundles in the future.
*/
public static function fieldSettingsFromConfigData(array $settings) {
if (isset($settings['handler_settings']['layout_bundles']) && !is_array($settings['handler_settings']['layout_bundles'])) {
$settings['handler_settings']['layout_bundles'] = [
$settings['handler_settings']['layout_bundles'],
];
}
return $settings;
}
/**
* Manipulate configuration data for settings form.
*/
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$form = parent::fieldSettingsForm($form, $form_state);
$handler_settings = $this
->getSetting('handler_settings');
$target_type = $this
->getSetting('target_type');
$negate = isset($handler_settings['negate']) ? $handler_settings['negate'] : 0;
$input_negate = $form_state
->getValue([
'settings',
'handler_settings',
'negate',
]);
if (isset($input_negate)) {
$negate = $input_negate;
}
$form['handler']['handler_settings']['negate']['#ajax'] = TRUE;
$target_bundles = isset($handler_settings['target_bundles']) ? $handler_settings['target_bundles'] : [];
// For AJAX, also look at form_state values:
$input_target_bundles = $form_state
->getValue([
'settings',
'handler_settings',
'target_bundles',
]);
if (!empty($input_target_bundles)) {
$target_bundles = $input_target_bundles;
}
$target_bundle_options = $form['handler']['handler_settings']['target_bundles']['#options'];
if ($negate) {
$layout_bundle_options = array_diff_key($target_bundle_options, $target_bundles);
}
else {
$layout_bundle_options = array_intersect_key($target_bundle_options, $target_bundles);
}
if (!empty($form['handler']['handler_settings']['target_bundles_drag_drop'])) {
foreach (Element::children($form['handler']['handler_settings']['target_bundles_drag_drop']) as $item) {
$form['handler']['handler_settings']['target_bundles_drag_drop'][$item]['enabled']['#ajax'] = TRUE;
}
}
$default_layout_bundle = '';
if (isset($handler_settings['layout_bundles'])) {
$default_layout_bundle = reset($handler_settings['layout_bundles']);
}
if (empty($layout_bundle_options[$default_layout_bundle])) {
$default_layout_bundle = [];
}
$form['handler']['handler_settings']['layout_bundles'] = [
'#type' => 'radios',
'#options' => $layout_bundle_options,
'#title' => $this
->t('Layout @target_type type', [
'@target_type' => $target_type,
]),
'#default_value' => $default_layout_bundle,
'#multiple' => TRUE,
'#description' => $this
->t('Which @target_type type should be used for layout.', [
'@target_type' => $target_type,
]),
'#required' => TRUE,
'#id' => 'erl-layout-bundles-select',
];
$layout_groups = \Drupal::service('plugin.manager.core.layout')
->getLayoutOptions();
$layout_groups_defaults = isset($handler_settings['allowed_layouts']) ? $handler_settings['allowed_layouts'] : [];
foreach ($layout_groups as $group => $layouts) {
if (!empty($group)) {
$defaults = isset($layout_groups_defaults[$group]) ? array_keys($layout_groups_defaults[$group]) : [];
$form['handler']['handler_settings']['allowed_layouts'][$group] = [
'#type' => 'checkboxes',
'#options' => $layouts,
'#title' => $group,
'#multiple' => TRUE,
'#default_value' => $defaults,
];
}
}
$form['handler']['handler_settings']['allowed_layouts']['#prefix'] = '<b>' . $this
->t('Allowed Layouts:') . '</b>';
return $form;
}
/**
* Get defaults settings.
*/
public static function defaultFieldSettings() {
$settings = parent::defaultFieldSettings();
$settings['handler_settings']['layout_bundles'] = [];
$settings['handler_settings']['allowed_layouts'] = [];
return $settings;
}
/**
* {@inheritdoc}
*
* Only support references to paragraphs.
*
* @todo Expand support to other entity types.
*/
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
$element = parent::storageSettingsForm($form, $form_state, $has_data);
foreach ($element['target_type']['#options'] as $key => $value) {
if ($key !== 'paragraph') {
unset($element['target_type']['#options'][$key]);
}
}
return $element;
}
}
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 | |
EntityReferenceItem:: |
public static | function |
Calculates dependencies for field items. Overrides FieldItemBase:: |
|
EntityReferenceItem:: |
public static | function |
Calculates dependencies for field items on the storage level. Overrides FieldItemBase:: |
|
EntityReferenceItem:: |
public static | function |
Defines the storage-level settings for this plugin. Overrides FieldItemBase:: |
1 |
EntityReferenceItem:: |
public static | function | Render API callback: Processes the field settings form and allows access to the form state. | |
EntityReferenceItem:: |
public static | function | Adds entity_reference specific properties to AJAX form elements from the field settings form. | |
EntityReferenceItem:: |
public static | function | Form element validation handler; Invokes selection plugin's validation. | |
EntityReferenceItem:: |
public static | function | Render API callback: Moves entity_reference specific Form API elements (i.e. 'handler_settings') up a level for easier processing by the validation and submission handlers. | |
EntityReferenceItem:: |
public | function |
Gets a list of validation constraints. Overrides TypedData:: |
|
EntityReferenceItem:: |
public | function |
Returns an array of possible values with labels for display. Overrides OptionsProviderInterface:: |
|
EntityReferenceItem:: |
public | function |
Returns an array of possible values. Overrides OptionsProviderInterface:: |
|
EntityReferenceItem:: |
protected static | function | Gets a bundle for a given entity type and selection options. | |
EntityReferenceItem:: |
public | function |
Returns an array of settable values with labels for display. Overrides OptionsProviderInterface:: |
|
EntityReferenceItem:: |
public | function |
Returns an array of settable values. Overrides OptionsProviderInterface:: |
|
EntityReferenceItem:: |
public | function | Determines whether the item holds an unsaved entity. | |
EntityReferenceItem:: |
public static | function |
Returns the name of the main property, if any. Overrides FieldItemBase:: |
|
EntityReferenceItem:: |
public static | function | Ajax callback for the handler settings form. | |
EntityReferenceItem:: |
public static | function | Submit handler for the non-JS case. | |
EntityReferenceLayoutRevisioned:: |
public static | function |
Get defaults settings. Overrides EntityReferenceItem:: |
|
EntityReferenceLayoutRevisioned:: |
public | function |
Manipulate configuration data for settings form. Overrides EntityReferenceItem:: |
|
EntityReferenceLayoutRevisioned:: |
public static | function |
Manipulate saved data into configuration. Overrides FieldItemBase:: |
|
EntityReferenceLayoutRevisioned:: |
public static | function |
Manipulate field data to be saved as configuration. Overrides FieldItemBase:: |
|
EntityReferenceLayoutRevisioned:: |
public static | function |
Define field properties. Overrides EntityReferenceRevisionsItem:: |
|
EntityReferenceLayoutRevisioned:: |
public static | function |
Define field schema. Overrides EntityReferenceRevisionsItem:: |
|
EntityReferenceLayoutRevisioned:: |
public | function |
Only support references to paragraphs. Overrides EntityReferenceRevisionsItem:: |
|
EntityReferenceRevisionsItem:: |
public | function |
Defines custom delete behavior for field values. Overrides FieldItemBase:: |
|
EntityReferenceRevisionsItem:: |
public | function |
Defines custom revision delete behavior for field values. Overrides FieldItemBase:: |
|
EntityReferenceRevisionsItem:: |
public static | function |
Generates placeholder field values. Overrides EntityReferenceItem:: |
|
EntityReferenceRevisionsItem:: |
public static | function |
Returns preconfigured field options for a field type. Overrides EntityReferenceItem:: |
|
EntityReferenceRevisionsItem:: |
public | function |
Gets the data value. Overrides EntityReferenceItem:: |
|
EntityReferenceRevisionsItem:: |
public | function |
Determines whether the data structure is empty. Overrides EntityReferenceItem:: |
|
EntityReferenceRevisionsItem:: |
public | function |
React to changes to a child property or item. Overrides EntityReferenceItem:: |
|
EntityReferenceRevisionsItem:: |
public static | function |
Informs the plugin that a dependency of the field will be deleted. Overrides EntityReferenceItem:: |
|
EntityReferenceRevisionsItem:: |
public | function |
Defines custom post-save behavior for field values. Overrides FieldItemBase:: |
|
EntityReferenceRevisionsItem:: |
public | function |
Defines custom presave behavior for field values. Overrides EntityReferenceItem:: |
|
EntityReferenceRevisionsItem:: |
public | function |
Sets the data value. Overrides EntityReferenceItem:: |
|
FieldItemBase:: |
public | function |
Gets the entity that field belongs to. Overrides FieldItemInterface:: |
|
FieldItemBase:: |
public | function |
Gets the field definition. Overrides FieldItemInterface:: |
|
FieldItemBase:: |
public | function |
Gets the langcode of the field values held in the object. Overrides FieldItemInterface:: |
|
FieldItemBase:: |
protected | function | Returns the value of a field setting. | |
FieldItemBase:: |
protected | function | Returns the array of field settings. | |
FieldItemBase:: |
public static | function |
Returns a settings array in the field type's canonical representation. Overrides FieldItemInterface:: |
2 |
FieldItemBase:: |
public static | function |
Returns a settings array that can be stored as a configuration value. Overrides FieldItemInterface:: |
2 |
FieldItemBase:: |
public | function |
Returns a renderable array for a single field item. Overrides FieldItemInterface:: |
|
FieldItemBase:: |
protected | function |
Different to the parent Map class, we avoid creating property objects as
far as possible in order to optimize performance. Thus we just update
$this->values if no property object has been created yet. Overrides Map:: |
|
FieldItemBase:: |
public | function |
Constructs a TypedData object given its definition and context. Overrides TypedData:: |
1 |
FieldItemBase:: |
public | function |
Magic method: Gets a property value. Overrides FieldItemInterface:: |
2 |
FieldItemBase:: |
public | function |
Magic method: Determines whether a property is set. Overrides FieldItemInterface:: |
|
FieldItemBase:: |
public | function |
Magic method: Sets a property value. Overrides FieldItemInterface:: |
1 |
FieldItemBase:: |
public | function |
Magic method: Unsets a property. Overrides FieldItemInterface:: |
|
Map:: |
protected | property |
The data definition. Overrides TypedData:: |
|
Map:: |
protected | property | The array of properties. | |
Map:: |
protected | property | An array of values for the contained properties. | |
Map:: |
public | function |
Applies the default value. Overrides TypedData:: |
4 |
Map:: |
public | function |
Gets a property object. Overrides ComplexDataInterface:: |
|
Map:: |
public | function | ||
Map:: |
public | function |
Gets an array of property objects. Overrides ComplexDataInterface:: |
|
Map:: |
public | function |
Returns a string representation of the data. Overrides TypedData:: |
|
Map:: |
public | function |
Sets a property value. Overrides ComplexDataInterface:: |
|
Map:: |
public | function |
Returns an array of all property values. Overrides ComplexDataInterface:: |
1 |
Map:: |
public | function | Magic method: Implements a deep clone. | |
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. | |
TypedData:: |
protected | property | The property name. | |
TypedData:: |
protected | property | The parent typed data object. | |
TypedData:: |
public static | function |
Constructs a TypedData object given its definition and context. Overrides TypedDataInterface:: |
|
TypedData:: |
public | function |
Gets the data definition. Overrides TypedDataInterface:: |
|
TypedData:: |
public | function |
Returns the name of a property or item. Overrides TypedDataInterface:: |
|
TypedData:: |
public | function |
Returns the parent data structure; i.e. either complex data or a list. Overrides TypedDataInterface:: |
|
TypedData:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
|
TypedData:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
TypedData:: |
public | function |
Returns the property path of the data. Overrides TypedDataInterface:: |
|
TypedData:: |
public | function |
Returns the root of the typed data tree. Overrides TypedDataInterface:: |
|
TypedData:: |
public | function |
Sets the context of a property or item via a context aware parent. Overrides TypedDataInterface:: |
|
TypedData:: |
public | function |
Validates the currently set data value. Overrides TypedDataInterface:: |
|
TypedDataTrait:: |
protected | property | The typed data manager used for creating the data types. | |
TypedDataTrait:: |
public | function | Gets the typed data manager. | 2 |
TypedDataTrait:: |
public | function | Sets the typed data manager. | 2 |