trait MicrositePluginTrait in Entity Reference Hierarchy 3.x
Same name and namespace in other branches
- 8.2 modules/entity_hierarchy_microsite/src/Plugin/MicrositePluginTrait.php \Drupal\entity_hierarchy_microsite\Plugin\MicrositePluginTrait
Defines a trait for microsite plugin functionality.
Hierarchy
- trait \Drupal\entity_hierarchy_microsite\Plugin\MicrositePluginTrait
3 files declare their use of MicrositePluginTrait
- ChildOfMicrosite.php in modules/
entity_hierarchy_microsite/ src/ Plugin/ Condition/ ChildOfMicrosite.php - MicrositeLogoBranding.php in modules/
entity_hierarchy_microsite/ src/ Plugin/ Block/ MicrositeLogoBranding.php - MicrositeMenu.php in modules/
entity_hierarchy_microsite/ src/ Plugin/ Block/ MicrositeMenu.php
File
- modules/
entity_hierarchy_microsite/ src/ Plugin/ MicrositePluginTrait.php, line 13
Namespace
Drupal\entity_hierarchy_microsite\PluginView source
trait MicrositePluginTrait {
/**
* Child of microsite lookup.
*
* @var \Drupal\entity_hierarchy_microsite\ChildOfMicrositeLookupInterface
*/
protected $childOfMicrositeLookup;
/**
* Entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* Sets value of NestedSetStorageFactory.
*
* @param \Drupal\entity_hierarchy_microsite\ChildOfMicrositeLookupInterface $childOfMicrositeLookup
* Lookup.
*
* @return $this
*/
public function setChildOfMicrositeLookup(ChildOfMicrositeLookupInterface $childOfMicrositeLookup) {
$this->childOfMicrositeLookup = $childOfMicrositeLookup;
return $this;
}
/**
* Entity field manager.
*
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager
* Entity field manager.
*
* @return $this
*/
protected function setEntityFieldManager(EntityFieldManagerInterface $entityFieldManager) {
$this->entityFieldManager = $entityFieldManager;
return $this;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = new static($configuration, $plugin_id, $plugin_definition);
return $instance
->setChildOfMicrositeLookup($container
->get('entity_hierarchy_microsite.microsite_lookup'))
->setEntityFieldManager($container
->get('entity_field.manager'));
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'field' => '',
] + parent::defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['field'] = [
'#type' => 'select',
'#title' => $this
->t('Entity hierarchy field'),
'#options' => $this
->getFieldOptions(),
'#empty_option' => 'None',
'#empty_value' => '',
'#default_value' => $this->configuration['field'],
'#description' => $this
->t('Select the field to use to identify if the current node is the child of a microsite'),
];
return parent::buildConfigurationForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['field'] = $form_state
->getValue('field');
parent::submitConfigurationForm($form, $form_state);
}
/**
* Gets field options.
*
* @return array
* Field names keyed by label.
*/
protected function getFieldOptions() {
$fields = $this->entityFieldManager
->getFieldMapByFieldType('entity_reference_hierarchy');
$options = [];
if (isset($fields['node'])) {
foreach ($fields['node'] as $field_name => $detail) {
foreach ($detail['bundles'] as $bundle) {
/** @var \Drupal\Core\Field\FieldDefinitionInterface $field */
$field = $this->entityFieldManager
->getFieldDefinitions('node', $bundle)[$field_name];
$options[$field_name] = $field
->getLabel();
}
}
}
return $options;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MicrositePluginTrait:: |
protected | property | Child of microsite lookup. | |
MicrositePluginTrait:: |
protected | property | Entity field manager. | |
MicrositePluginTrait:: |
public | function | ||
MicrositePluginTrait:: |
public static | function | ||
MicrositePluginTrait:: |
public | function | ||
MicrositePluginTrait:: |
protected | function | Gets field options. | |
MicrositePluginTrait:: |
public | function | Sets value of NestedSetStorageFactory. | |
MicrositePluginTrait:: |
protected | function | Entity field manager. | |
MicrositePluginTrait:: |
public | function |