abstract class ParagraphsBehaviorBase in Paragraphs 8
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\paragraphs\ParagraphsBehaviorBase implements ContainerFactoryPluginInterface, ParagraphsBehaviorInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of ParagraphsBehaviorBase
4 files declare their use of ParagraphsBehaviorBase
- TestBoldTextBehavior.php in tests/
modules/ paragraphs_test/ src/ Plugin/ paragraphs/ Behavior/ TestBoldTextBehavior.php - TestDummyBehavior.php in tests/
modules/ paragraphs_test/ src/ Plugin/ paragraphs/ Behavior/ TestDummyBehavior.php - TestFieldsSelectionBehavior.php in tests/
modules/ paragraphs_test/ src/ Plugin/ paragraphs/ Behavior/ TestFieldsSelectionBehavior.php - TestTextColorBehavior.php in tests/
modules/ paragraphs_test/ src/ Plugin/ paragraphs/ Behavior/ TestTextColorBehavior.php
File
- src/
ParagraphsBehaviorBase.php, line 15
Namespace
Drupal\paragraphsView source
abstract class ParagraphsBehaviorBase extends PluginBase implements ParagraphsBehaviorInterface, ContainerFactoryPluginInterface {
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* Constructs a ParagraphsBehaviorBase 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->configuration += $this
->defaultConfiguration();
$this->entityFieldManager = $entity_field_manager;
}
/**
* {@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'));
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [];
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = $configuration + $this
->defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
return [];
}
/**
* {@inheritdoc}
*/
public function preprocess(&$variables) {
}
/**
* {@inheritdoc}
*/
public static function isApplicable(ParagraphsType $paragraphs_type) {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function settingsSummary(Paragraph $paragraph) {
return [];
}
/**
* {@inheritdoc}
*/
public function settingsIcon(Paragraph $paragraph) {
return [];
}
/**
* {@inheritdoc}
*/
public function buildBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {
return $form;
}
/**
* {@inheritdoc}
*/
public function validateBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {
$filtered_values = $this
->filterBehaviorFormSubmitValues($paragraph, $form, $form_state);
$paragraph
->setBehaviorSettings($this
->getPluginId(), $filtered_values);
}
/**
* Removes default behavior form values before storing the user-set ones.
*
* Default implementation considers a value to be default if and only if it is
* an empty value. Behavior plugins that do not consider all empty values to
* be default should override this method or
* \Drupal\paragraphs\ParagraphsBehaviorBase::submitBehaviorForm.
*
* @param \Drupal\paragraphs\ParagraphInterface $paragraph
* The paragraph.
* @param array $form
* An associative array containing the initial structure of the plugin form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return array
* An associative array of values submitted to the form with all empty
* leaves removed. Subarrays that only contain empty leaves are also
* removed.
*/
protected function filterBehaviorFormSubmitValues(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {
// Keeps removing empty leaves, until there are none left. So if a subarray
// only contains empty leaves, that subarray itself will be removed.
$new_array = $form_state
->getValues();
do {
$old_array = $new_array;
$new_array = NestedArray::filter($old_array);
} while ($new_array !== $old_array);
return $new_array;
}
/**
* {@inheritdoc}
*/
public function getFieldNameOptions(ParagraphsType $paragraphs_type, $field_type = NULL) {
$fields = [];
$field_definitions = $this->entityFieldManager
->getFieldDefinitions('paragraph', $paragraphs_type
->id());
foreach ($field_definitions as $name => $definition) {
if ($field_definitions[$name] instanceof FieldConfigInterface) {
if (empty($field_type) || $definition
->getType() == $field_type) {
$fields[$name] = $definition
->getLabel();
}
}
}
return $fields;
}
}
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 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
ParagraphsBehaviorBase:: |
protected | property | The entity field manager. | |
ParagraphsBehaviorBase:: |
public | function |
Builds a behavior perspective for each paragraph based on its type. Overrides ParagraphsBehaviorInterface:: |
3 |
ParagraphsBehaviorBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
2 |
ParagraphsBehaviorBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
ParagraphsBehaviorBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
ParagraphsBehaviorBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
2 |
ParagraphsBehaviorBase:: |
protected | function | Removes default behavior form values before storing the user-set ones. | |
ParagraphsBehaviorBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ParagraphsBehaviorBase:: |
public | function |
Returns list of field names for the given paragraph type and field type. Overrides ParagraphsBehaviorInterface:: |
|
ParagraphsBehaviorBase:: |
public static | function |
Returns if the plugin can be used for the provided Paragraphs type. Overrides ParagraphsBehaviorInterface:: |
1 |
ParagraphsBehaviorBase:: |
public | function |
Adds a default set of helper variables for preprocessors and templates. Overrides ParagraphsBehaviorInterface:: |
|
ParagraphsBehaviorBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
ParagraphsBehaviorBase:: |
public | function |
Returns a short info icon for the current behavior settings. Overrides ParagraphsBehaviorInterface:: |
1 |
ParagraphsBehaviorBase:: |
public | function |
Returns a short summary for the current behavior settings. Overrides ParagraphsBehaviorInterface:: |
2 |
ParagraphsBehaviorBase:: |
public | function |
Submit the values taken from the form to store the values. Overrides ParagraphsBehaviorInterface:: |
|
ParagraphsBehaviorBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
1 |
ParagraphsBehaviorBase:: |
public | function |
Validates the behavior fields form. Overrides ParagraphsBehaviorInterface:: |
1 |
ParagraphsBehaviorBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
1 |
ParagraphsBehaviorBase:: |
public | function |
Constructs a ParagraphsBehaviorBase object. Overrides PluginBase:: |
|
ParagraphsBehaviorInterface:: |
public | function | Extends the paragraph render array with behavior. | 4 |
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. |