UserFilteredSelection.php in Workbench Access 8
File
src/Plugin/EntityReferenceSelection/UserFilteredSelection.php
View source
<?php
namespace Drupal\workbench_access\Plugin\EntityReferenceSelection;
use Drupal\user\Plugin\EntityReferenceSelection\UserSelection;
use Drupal\workbench_access\Entity\AccessSchemeInterface;
use Drupal\workbench_access\UserSectionStorageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class UserFilteredSelection extends UserSelection {
protected $scheme;
protected $userSectionStorage;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
return $instance
->setScheme($container
->get('entity_type.manager')
->getStorage('access_scheme')
->load($plugin_definition['scheme']))
->setUserSectionStorage($container
->get('workbench_access.user_section_storage'));
}
public function setUserSectionStorage(UserSectionStorageInterface $userSectionStorage) {
$this->userSectionStorage = $userSectionStorage;
return $this;
}
public function setScheme(AccessSchemeInterface $scheme) {
$this->scheme = $scheme;
return $this;
}
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
if (isset($this->configuration['handler_settings'])) {
$handler_settings = $this->configuration['handler_settings'];
}
if (isset($handler_settings['filter']['section_id'])) {
$id = $handler_settings['filter']['section_id'];
$editors = $this->userSectionStorage
->getEditors($this->scheme, $id);
if (count($editors)) {
$query
->condition('uid', array_keys($editors), 'NOT IN');
}
}
return $query;
}
}