protected function SocialGroupSelection::buildEntityQuery in Open Social 10.2.x
Same name and namespace in other branches
- 10.3.x modules/social_features/social_group/src/Plugin/EntityReferenceSelection/SocialGroupSelection.php \Drupal\social_group\Plugin\EntityReferenceSelection\SocialGroupSelection::buildEntityQuery()
- 10.0.x modules/social_features/social_group/src/Plugin/EntityReferenceSelection/SocialGroupSelection.php \Drupal\social_group\Plugin\EntityReferenceSelection\SocialGroupSelection::buildEntityQuery()
- 10.1.x modules/social_features/social_group/src/Plugin/EntityReferenceSelection/SocialGroupSelection.php \Drupal\social_group\Plugin\EntityReferenceSelection\SocialGroupSelection::buildEntityQuery()
Builds an EntityQuery to get referenceable entities.
Parameters
string|null $match: (Optional) Text to match the label against. Defaults to NULL.
string $match_operator: (Optional) The operation the matching should be done with. Defaults to "CONTAINS".
Return value
\Drupal\Core\Entity\Query\QueryInterface The EntityQuery object with the basic conditions and sorting applied to it.
Overrides DefaultSelection::buildEntityQuery
File
- modules/
social_features/ social_group/ src/ Plugin/ EntityReferenceSelection/ SocialGroupSelection.php, line 23
Class
- SocialGroupSelection
- Provides specific access control for the group entity type.
Namespace
Drupal\social_group\Plugin\EntityReferenceSelectionCode
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
$configuration = $this
->getConfiguration();
$all_group_types = [];
if (is_array($configuration['target_bundles'])) {
if ($configuration['target_bundles'] === []) {
return $query;
}
else {
$all_group_types = $configuration['target_bundles'];
}
}
$plugin_id = 'group_node:' . $configuration['entity']
->bundle();
$storage = $this->entityTypeManager
->getStorage('group_type');
if (!$all_group_types) {
$all_group_types = $storage
->getQuery()
->execute();
}
$excluded_group_types = [];
foreach ($all_group_types as $group_type_id) {
/** @var \Drupal\group\Entity\GroupTypeInterface $group_type */
$group_type = $storage
->load($group_type_id);
if (!$group_type
->hasContentPlugin($plugin_id)) {
$excluded_group_types[] = $group_type_id;
}
}
if ($excluded_group_types) {
$diff = array_diff($all_group_types, $excluded_group_types);
if (!empty($diff)) {
$query
->condition($this->entityTypeManager
->getDefinition($configuration['target_type'])
->getKey('bundle'), $diff, 'IN');
}
}
return $query;
}