abstract class AbstractPatternsDeriver in UI Patterns 8
Class AbstractPatternsDeriver.
@package Drupal\ui_patterns\Deriver
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\ui_patterns\Plugin\Deriver\AbstractPatternsDeriver implements ContainerDeriverInterface, PatternsDeriverInterface uses StringTranslationTrait
Expanded class hierarchy of AbstractPatternsDeriver
File
- src/
Plugin/ Deriver/ AbstractPatternsDeriver.php, line 19
Namespace
Drupal\ui_patterns\Plugin\DeriverView source
abstract class AbstractPatternsDeriver extends DeriverBase implements PatternsDeriverInterface, ContainerDeriverInterface {
use StringTranslationTrait;
/**
* Typed data manager service.
*
* @var \Drupal\Core\TypedData\TypedDataManager
*/
protected $typedDataManager;
/**
* The messenger.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* AbstractPatternsDeriver constructor.
*/
public function __construct($base_plugin_id, TypedDataManager $typed_data_manager, MessengerInterface $messenger) {
$this->basePluginId = $base_plugin_id;
$this->typedDataManager = $typed_data_manager;
$this->messenger = $messenger;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($base_plugin_id, $container
->get('typed_data_manager'), $container
->get('messenger'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this
->getPatterns() as $pattern) {
$pattern
->setDeriver($base_plugin_definition['deriver']);
$pattern
->setClass($base_plugin_definition['class']);
if ($this
->isValidPatternDefinition($pattern)) {
$this->derivatives[$pattern
->id()] = $pattern;
}
}
return $this->derivatives;
}
/**
* Get pattern data object.
*
* @param array $definition
* Pattern definition array.
*
* @return \Drupal\ui_patterns\Definition\PatternDefinition
* Pattern definition object.
*/
protected function getPatternDefinition(array $definition = []) {
return new PatternDefinition($definition);
}
/**
* Validate pattern definition.
*
* @param \Drupal\ui_patterns\Definition\PatternDefinition $definition
* Pattern definition.
*
* @return bool
* Whereas current pattern definition is valid or not.
*/
protected function isValidPatternDefinition(PatternDefinition $definition) {
$data_definition = PatternDataDefinition::create();
$violations = $this->typedDataManager
->create($data_definition, $definition
->toArray())
->validate();
if ($violations
->count()) {
/** @var \Symfony\Component\Validator\ConstraintViolation $violation */
$this->messenger
->addError($this
->t("Pattern ':id' is skipped because of the following validation error(s):", [
':id' => $definition
->id(),
]));
foreach ($violations as $violation) {
$message = $this
->t('Validation error on ":id.:property": :message', [
':id' => $definition
->id(),
':property' => $violation
->getPropertyPath(),
':message' => $violation
->getMessage(),
]);
$this->messenger
->addError($message);
}
return FALSE;
}
return TRUE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AbstractPatternsDeriver:: |
protected | property | The messenger. | |
AbstractPatternsDeriver:: |
protected | property | Typed data manager service. | |
AbstractPatternsDeriver:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
1 |
AbstractPatternsDeriver:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
AbstractPatternsDeriver:: |
protected | function | Get pattern data object. | |
AbstractPatternsDeriver:: |
protected | function | Validate pattern definition. | |
AbstractPatternsDeriver:: |
public | function | AbstractPatternsDeriver constructor. | 1 |
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
PatternsDeriverInterface:: |
public | function | Get pattern definition objects. | 1 |
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. |