class ChildOfMicrositeLookup in Entity Reference Hierarchy 8.2
Same name and namespace in other branches
- 3.x modules/entity_hierarchy_microsite/src/ChildOfMicrositeLookup.php \Drupal\entity_hierarchy_microsite\ChildOfMicrositeLookup
Defines a class for looking up a microsite given a node.
Hierarchy
- class \Drupal\entity_hierarchy_microsite\ChildOfMicrositeLookup implements ChildOfMicrositeLookupInterface
Expanded class hierarchy of ChildOfMicrositeLookup
1 string reference to 'ChildOfMicrositeLookup'
- entity_hierarchy_microsite.services.yml in modules/
entity_hierarchy_microsite/ entity_hierarchy_microsite.services.yml - modules/entity_hierarchy_microsite/entity_hierarchy_microsite.services.yml
1 service uses ChildOfMicrositeLookup
- entity_hierarchy_microsite.microsite_lookup in modules/
entity_hierarchy_microsite/ entity_hierarchy_microsite.services.yml - Drupal\entity_hierarchy_microsite\ChildOfMicrositeLookup
File
- modules/
entity_hierarchy_microsite/ src/ ChildOfMicrositeLookup.php, line 15
Namespace
Drupal\entity_hierarchy_micrositeView source
class ChildOfMicrositeLookup implements ChildOfMicrositeLookupInterface {
/**
* Entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* Entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Nested set storage.
*
* @var \Drupal\entity_hierarchy\Storage\NestedSetStorageFactory
*/
protected $nestedSetStorageFactory;
/**
* Nested set node key factory.
*
* @var \Drupal\entity_hierarchy\Storage\NestedSetNodeKeyFactory
*/
protected $nodeKeyFactory;
/**
* Constructs a new ChildOfMicrositeLookup.
*
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager
* Field manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* Entity type manager.
* @param \Drupal\entity_hierarchy\Storage\NestedSetStorageFactory $nestedSetStorageFactory
* Storage factory.
* @param \Drupal\entity_hierarchy\Storage\NestedSetNodeKeyFactory $nodeKeyFactory
* Key factory.
*/
public function __construct(EntityFieldManagerInterface $entityFieldManager, EntityTypeManagerInterface $entityTypeManager, NestedSetStorageFactory $nestedSetStorageFactory, NestedSetNodeKeyFactory $nodeKeyFactory) {
$this->entityFieldManager = $entityFieldManager;
$this->entityTypeManager = $entityTypeManager;
$this->nestedSetStorageFactory = $nestedSetStorageFactory;
$this->nodeKeyFactory = $nodeKeyFactory;
}
/**
* {@inheritdoc}
*/
public function findMicrositesForNodeAndField(NodeInterface $node, $field_name) {
$ids = [];
if ($node
->hasField($field_name) && !$node
->get($field_name)
->isEmpty()) {
$key = $this->nodeKeyFactory
->fromEntity($node);
/** @var \PNX\NestedSet\NestedSetInterface $nestedSetStorage */
$nestedSetStorage = $this->nestedSetStorageFactory
->get($field_name, 'node');
$ids = array_map(function (Node $treeNode) {
return $treeNode
->getId();
}, $nestedSetStorage
->findAncestors($key));
}
$ids[] = $node
->id();
$entityStorage = $this->entityTypeManager
->getStorage('entity_hierarchy_microsite');
return $entityStorage
->loadMultiple($entityStorage
->getQuery()
->sort('id')
->condition('home', $ids, 'IN')
->execute());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ChildOfMicrositeLookup:: |
protected | property | Entity field manager. | |
ChildOfMicrositeLookup:: |
protected | property | Entity type manager. | |
ChildOfMicrositeLookup:: |
protected | property | Nested set storage. | |
ChildOfMicrositeLookup:: |
protected | property | Nested set node key factory. | |
ChildOfMicrositeLookup:: |
public | function |
Gets microsites the node belongs to. Overrides ChildOfMicrositeLookupInterface:: |
|
ChildOfMicrositeLookup:: |
public | function | Constructs a new ChildOfMicrositeLookup. |