class Pattern in UI Patterns 8
Same name in this branch
- 8 src/Element/Pattern.php \Drupal\ui_patterns\Element\Pattern
- 8 modules/ui_patterns_ds/src/Plugin/DsFieldTemplate/Pattern.php \Drupal\ui_patterns_ds\Plugin\DsFieldTemplate\Pattern
- 8 modules/ui_patterns_views/src/Plugin/views/row/Pattern.php \Drupal\ui_patterns_views\Plugin\views\row\Pattern
Plugin for the expert field template.
Plugin annotation
@DsFieldTemplate(
id = "pattern",
title = @Translation("Pattern"),
theme = "pattern_ds_field_template",
)
Hierarchy
- class \Drupal\ui_patterns_ds\Plugin\DsFieldTemplate\Pattern extends \Drupal\ds\Plugin\DsFieldTemplate\DsFieldTemplateBase implements ContainerFactoryPluginInterface uses PatternDisplayFormTrait
Expanded class hierarchy of Pattern
3 string references to 'Pattern'
- PatternDisplayFormTrait::buildPatternDisplayForm in src/
Form/ PatternDisplayFormTrait.php - Build pattern display form.
- UiPatternsFieldGroupSettingsTest::testWarningMessage in modules/
ui_patterns_field_group/ tests/ src/ FunctionalJavascript/ UiPatternsFieldGroupSettingsTest.php - Make sure a warning message is displayed when using pattern formatter.
- UiPatternsFieldSettingsTest::testUiPatternsFieldSettings in modules/
ui_patterns_ds/ tests/ src/ FunctionalJavascript/ UiPatternsFieldSettingsTest.php - Tests field template settings.
File
- modules/
ui_patterns_ds/ src/ Plugin/ DsFieldTemplate/ Pattern.php, line 24
Namespace
Drupal\ui_patterns_ds\Plugin\DsFieldTemplateView source
class Pattern extends DsFieldTemplateBase implements ContainerFactoryPluginInterface {
use PatternDisplayFormTrait;
/**
* Module Handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler = NULL;
/**
* UI Patterns manager.
*
* @var \Drupal\ui_patterns\UiPatternsManager
*/
protected $patternsManager;
/**
* UI Patterns manager.
*
* @var \Drupal\ui_patterns\UiPatternsSourceManager
*/
protected $sourceManager;
/**
* Current $_POST parameters.
*
* @var \Symfony\Component\HttpFoundation\ParameterBag
*/
protected $parameters;
/**
* Entity field manager service.
*
* @var \Drupal\Core\Entity\EntityFieldManager
*/
protected $fieldManager;
/**
* Pattern constructor.
*
* @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\ui_patterns\UiPatternsManager $patterns_manager
* UI Patterns manager.
* @param \Drupal\ui_patterns\UiPatternsSourceManager $source_manager
* UI Patterns source manager.
* @param \Symfony\Component\HttpFoundation\RequestStack $parameters
* Current $_POST parameters.
* @param \Drupal\Core\Entity\EntityFieldManager $field_manager
* Field manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* Module handler.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, UiPatternsManager $patterns_manager, UiPatternsSourceManager $source_manager, RequestStack $parameters, EntityFieldManager $field_manager, ModuleHandlerInterface $module_handler) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->patternsManager = $patterns_manager;
$this->sourceManager = $source_manager;
$this->parameters = $parameters
->getCurrentRequest()->request;
$this->fieldManager = $field_manager;
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('plugin.manager.ui_patterns'), $container
->get('plugin.manager.ui_patterns_source'), $container
->get('request_stack'), $container
->get('entity_field.manager'), $container
->get('module_handler'));
}
/**
* {@inheritdoc}
*/
public function alterForm(&$form) {
$context = $this
->getContext();
if ($this
->isSupportedField($context)) {
$this
->buildPatternDisplayForm($form, 'ds_field_template', $context, $this
->getConfiguration());
}
else {
$form['#markup'] = $this
->t("The current field is not supported.");
}
}
/**
* Get source field plugin context.
*
* @return array
* Context array.
*/
protected function getContext() {
$fields = $this->parameters
->get('fields');
$field_name = $this
->getCurrentField();
return [
'field_name' => $field_name,
'field_settings' => $fields[$field_name],
'entity_type' => $this->parameters
->get('ds_entity_type'),
'bundle' => $this->parameters
->get('ds_bundle'),
'view_mode' => $this->parameters
->get('ds_view_mode'),
];
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'pattern' => '',
'pattern_variant' => '',
'pattern_mapping' => [],
];
}
/**
* Get name of field currently being edited.
*
* @return string
* Name of field currently being edited.
*/
protected function getCurrentField() {
$fields = array_filter($this->parameters
->get('fields', []), function ($field) {
return isset($field['settings_edit_form']['third_party_settings']['ds']['ft']['id']) && $field['settings_edit_form']['third_party_settings']['ds']['ft']['id'] == 'pattern';
});
$fields = array_keys($fields);
$field = reset($fields);
if (empty($field)) {
$trigger_element = $this->parameters
->get('_triggering_element_name');
$field = str_replace('_plugin_settings_edit', '', $trigger_element);
}
return $field;
}
/**
* Pattern Display Suite field template plugin only supports actual fields.
*
* @param array $context
* Current context.
*
* @return bool
* TRUE if supported, FALSE otherwise.
*/
protected function isSupportedField(array $context) {
/** @var \Drupal\field\Entity\FieldConfig $field */
if ($context['entity_type'] && $context['bundle']) {
$field = $this->fieldManager
->getFieldDefinitions($context['entity_type'], $context['bundle']);
return isset($field[$context['field_name']]);
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Pattern:: |
protected | property | Entity field manager service. | |
Pattern:: |
protected | property | Module Handler. | |
Pattern:: |
protected | property | Current $_POST parameters. | |
Pattern:: |
protected | property | UI Patterns manager. | |
Pattern:: |
protected | property | UI Patterns manager. | |
Pattern:: |
public | function | ||
Pattern:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
Pattern:: |
public | function | ||
Pattern:: |
protected | function | Get source field plugin context. | |
Pattern:: |
protected | function | Get name of field currently being edited. | |
Pattern:: |
protected | function | Pattern Display Suite field template plugin only supports actual fields. | |
Pattern:: |
public | function | Pattern constructor. | |
PatternDisplayFormTrait:: |
public | function | Build pattern display form. | |
PatternDisplayFormTrait:: |
protected | function | Helper function: get default value. | |
PatternDisplayFormTrait:: |
public | function | Helper function: return mapping destination given plugin id and field name. | |
PatternDisplayFormTrait:: |
public | function | Get mapping form. | |
PatternDisplayFormTrait:: |
public | function | Helper function: check if given source field has mapping destination. | |
PatternDisplayFormTrait:: |
public static | function | Normalize settings coming from a form submission. |