MenuSelection.php in Menu Admin per Menu 8
File
src/Plugin/EntityReferenceSelection/MenuSelection.php
View source
<?php
namespace Drupal\menu_admin_per_menu\Plugin\EntityReferenceSelection;
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
use Drupal\Core\Form\FormStateInterface;
use Drupal\menu_admin_per_menu\Access\MenuAdminPerMenuAccess;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MenuSelection extends DefaultSelection {
protected $allowedMenuService;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance
->setAllowedMenusService($container
->get('menu_admin_per_menu.allowed_menus'));
return $instance;
}
public function setAllowedMenusService(MenuAdminPerMenuAccess $allowed_menu_service) : self {
$this->allowedMenuService = $allowed_menu_service;
return $this;
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['auto_create']['#access'] = FALSE;
return $form;
}
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
if (!$this->currentUser
->hasPermission('administer menu')) {
$menu_permissions = $this->allowedMenuService
->getPerMenuPermissions($this->currentUser);
$query
->condition('id', $menu_permissions, 'IN');
}
return $query;
}
}
Classes
Name |
Description |
MenuSelection |
Provides specific entity reference selection for the menu entity type. |