class NestedLayoutBuilderEntitiesDetector in Lingotek Translation 3.7.x
Same name and namespace in other branches
- 4.0.x src/Plugin/RelatedEntitiesDetector/NestedLayoutBuilderEntitiesDetector.php \Drupal\lingotek\Plugin\RelatedEntitiesDetector\NestedLayoutBuilderEntitiesDetector
- 3.6.x src/Plugin/RelatedEntitiesDetector/NestedLayoutBuilderEntitiesDetector.php \Drupal\lingotek\Plugin\RelatedEntitiesDetector\NestedLayoutBuilderEntitiesDetector
- 3.8.x src/Plugin/RelatedEntitiesDetector/NestedLayoutBuilderEntitiesDetector.php \Drupal\lingotek\Plugin\RelatedEntitiesDetector\NestedLayoutBuilderEntitiesDetector
@RelatedEntitiesDetector ( id = "nested_layout_builder_entities_detector", title =
Plugin annotation
@Translation("Get related nested layout builder content"),
description = @translation("The default retrieval of nested layout builder content"),
weight = 5,
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\lingotek\Plugin\RelatedEntitiesDetector\NestedLayoutBuilderEntitiesDetector implements ContainerFactoryPluginInterface, RelatedEntitiesDetectorInterface
Expanded class hierarchy of NestedLayoutBuilderEntitiesDetector
1 file declares its use of NestedLayoutBuilderEntitiesDetector
- NestedLayoutBuilderEntitiesDetectorTest.php in tests/
src/ Unit/ Plugin/ RelatedEntitiesDetector/ NestedLayoutBuilderEntitiesDetectorTest.php
File
- src/
Plugin/ RelatedEntitiesDetector/ NestedLayoutBuilderEntitiesDetector.php, line 25
Namespace
Drupal\lingotek\Plugin\RelatedEntitiesDetectorView source
class NestedLayoutBuilderEntitiesDetector extends PluginBase implements RelatedEntitiesDetectorInterface, ContainerFactoryPluginInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* The Lingotek configuration service.
*
* @var \Drupal\lingotek\LingotekConfigurationServiceInterface
*/
protected $lingotekConfiguration;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Nested layoutBuilderDetector 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 array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity manager
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager
* The entity field manager.
* @param \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotekConfiguration
* The Lingotek configuration service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* The module handler.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager, EntityFieldManagerInterface $entityFieldManager, LingotekConfigurationServiceInterface $lingotekConfiguration, ModuleHandlerInterface $moduleHandler) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entityTypeManager;
$this->entityFieldManager = $entityFieldManager;
$this->lingotekConfiguration = $lingotekConfiguration;
$this->moduleHandler = $moduleHandler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('entity_field.manager'), $container
->get('lingotek.configuration'), $container
->get('module_handler'));
}
/**
* {@inheritdoc}
*/
public function extract(ContentEntityInterface &$entity, array &$entities, array &$related, $depth, array $visited) {
$visited[$entity
->bundle()][] = $entity
->id();
$entities[$entity
->getEntityTypeId()][$entity
->id()] = $entity
->getUntranslated();
if ($depth > 0) {
--$depth;
$field_definitions = $this->entityFieldManager
->getFieldDefinitions($entity
->getEntityTypeId(), $entity
->bundle());
$layoutBuilderAT = $this->moduleHandler
->moduleExists('layout_builder_at');
$layoutBuilderST = $this->moduleHandler
->moduleExists('layout_builder_st');
foreach ($field_definitions as $k => $definition) {
$field_type = $field_definitions[$k]
->getType();
if ($field_type === 'layout_translation' && $layoutBuilderST || $field_type === 'layout_section' && $layoutBuilderAT) {
$blockContentRevisionIds = [];
$block_manager = \Drupal::service('plugin.manager.block');
$layoutField = $entity
->get(OverridesSectionStorage::FIELD_NAME);
$layout = $layoutField
->getValue();
/** @var \Drupal\layout_builder\Section $sectionObject */
foreach ($layout as $section) {
$sectionObject = $section['section'];
$components = $sectionObject
->getComponents();
/** @var \Drupal\layout_builder\SectionComponent $component */
foreach ($components as $component) {
$blockDefinition = $block_manager
->getDefinition($component
->getPluginId());
$configuration = $component
->toArray()['configuration'];
if ($blockDefinition['id'] === 'inline_block') {
$blockContentRevisionIds[] = $configuration['block_revision_id'];
}
}
}
$target_entity_ids = empty($blockContentRevisionIds) ? $blockContentRevisionIds : $this
->prepareBlockContentIds($blockContentRevisionIds);
$target_entity_type_id = 'block_content';
foreach ($target_entity_ids as $target_content_entity_id) {
$target_entity_type = $this->entityTypeManager
->getDefinition($target_entity_type_id);
if ($target_entity_type instanceof ContentEntityType) {
$relatedEntity = $this->entityTypeManager
->getStorage($target_entity_type_id)
->load($target_content_entity_id);
if ($relatedEntity !== NULL) {
// Avoid entities that were are already visited
if (!isset($visited[$relatedEntity
->bundle()]) || !in_array($relatedEntity
->id(), $visited[$relatedEntity
->bundle()])) {
if ($relatedEntity instanceof ContentEntityInterface && $relatedEntity
->isTranslatable() && $this->lingotekConfiguration
->isEnabled($relatedEntity
->getEntityTypeId(), $relatedEntity
->bundle())) {
if (!$this->lingotekConfiguration
->isFieldLingotekEnabled($entity
->getEntityTypeId(), $entity
->bundle(), $k)) {
$entities = $this
->extract($relatedEntity, $entities, $related, $depth, $visited);
}
else {
$related[$relatedEntity
->getEntityTypeId()][$relatedEntity
->id()] = $relatedEntity
->getUntranslated();
}
}
}
}
}
}
}
}
}
return $entities;
}
/**
* Get block content ids from the revision ids stored in the field definition of parent entity
*
* @param array $blockContentRevisionIds
* An array of block revision IDs.
*
* @return array
* An array of block IDs.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
private function prepareBlockContentIds(array $blockContentRevisionIds) {
/** @var \Drupal\Core\Entity\ContentEntityStorageInterface $blockContentStorage */
$blockContentStorage = $this->entityTypeManager
->getStorage('block_content');
$ids = $blockContentStorage
->getQuery()
->condition($blockContentStorage
->getEntityType()
->getKey('revision'), $blockContentRevisionIds, 'IN')
->execute();
return $ids;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
NestedLayoutBuilderEntitiesDetector:: |
protected | property | The entity field manager. | |
NestedLayoutBuilderEntitiesDetector:: |
protected | property | The entity type manager. | |
NestedLayoutBuilderEntitiesDetector:: |
protected | property | The Lingotek configuration service. | |
NestedLayoutBuilderEntitiesDetector:: |
protected | property | The module handler. | |
NestedLayoutBuilderEntitiesDetector:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
NestedLayoutBuilderEntitiesDetector:: |
public | function |
Extract nested and related content. Overrides RelatedEntitiesDetectorInterface:: |
|
NestedLayoutBuilderEntitiesDetector:: |
private | function | Get block content ids from the revision ids stored in the field definition of parent entity | |
NestedLayoutBuilderEntitiesDetector:: |
public | function |
Nested layoutBuilderDetector constructor. Overrides PluginBase:: |
|
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:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. |