public function DomainMenusSelection::getReferenceableEntities in Domain Menus for Domains 3.x
Gets the list of referenceable entities.
Parameters
string|null $match: (optional) Text to match the label against. Defaults to NULL.
string $match_operator: (optional) Operator to be used for string matching. Defaults to "CONTAINS".
int $limit: (optional) Limit the query to a given number of items. Defaults to 0, which indicates no limiting.
Return value
array A nested array of entities, the first level is keyed by the entity bundle, which contains an array of entity labels (escaped), keyed by the entity ID.
Overrides DefaultSelection::getReferenceableEntities
File
- src/
Plugin/ EntityReferenceSelection/ DomainMenusSelection.php, line 73
Class
- DomainMenusSelection
- Domain Menus plugin implementation of the Entity Reference Selection plugin.
Namespace
Drupal\domain_menus\Plugin\EntityReferenceSelectionCode
public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
$config = $this
->getConfiguration();
$domain_id = $config['domain_id'] ?? null;
if ($domain_id == null) {
return parent::getReferenceableEntities($match, $match_operator, $limit);
}
$target_type = $config['target_type'];
$options = parent::getReferenceableEntities($match, $match_operator);
$filtered = [];
$count = 0;
// Filter target entities by domain.
foreach ($options as $bundle => &$items) {
foreach ($items as $entity_id => $label) {
$entity = $this->entityTypeManager
->getStorage($target_type)
->load($entity_id);
$access_values = $this->domainAccessManager
->getAccessValues($entity);
$access_all_value = $this->domainAccessManager
->getAllValue($entity);
if (!($access_values != null && empty($access_all_value) && $access_all_value != null && empty(array_intersect_key($access_values, $domain_id)))) {
$filtered[$bundle][$entity_id] = $label;
$count++;
if ($limit && $count >= $limit) {
break 2;
}
}
}
}
return $filtered;
}