SocialGroupSelection.php in Open Social 10.0.x
File
modules/social_features/social_group/src/Plugin/EntityReferenceSelection/SocialGroupSelection.php
View source
<?php
namespace Drupal\social_group\Plugin\EntityReferenceSelection;
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
class SocialGroupSelection extends DefaultSelection {
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) {
$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;
}
}