SelectionTrait.php

Namespace

Drupal\Core\Entity\EntityReferenceSelection

File

core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionTrait.php

View source
<?php

namespace Drupal\Core\Entity\EntityReferenceSelection;

use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@trigger_error(__NAMESPACE__ . '\\SelectionTrait is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. A custom constructor must be implemented instead. See https://www.drupal.org/node/3030634', E_USER_DEPRECATED);

/**
 * Provides common methods and injects services for core selection handlers.
 */
trait SelectionTrait {
    
    /**
     * The entity manager service.
     *
     * @var \Drupal\Core\Entity\EntityManagerInterface
     */
    protected $entityManager;
    
    /**
     * The module handler service.
     *
     * @var \Drupal\Core\Extension\ModuleHandlerInterface
     */
    protected $moduleHandler;
    
    /**
     * The current user.
     *
     * @var \Drupal\Core\Session\AccountInterface
     */
    protected $currentUser;
    
    /**
     * Constructs a new selection object.
     *
     * @param array $configuration
     *   A configuration array containing information about the plugin instance.
     * @param string $plugin_id
     *   The plugin_id for the plugin instance.
     * @param mixed $plugin_definition
     *   The plugin implementation definition.
     * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
     *   The entity manager service.
     * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
     *   The module handler service.
     * @param \Drupal\Core\Session\AccountInterface $current_user
     *   The current user.
     */
    public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, AccountInterface $current_user) {
        parent::__construct($configuration, $plugin_id, $plugin_definition);
        $this->entityManager = $entity_manager;
        $this->moduleHandler = $module_handler;
        $this->currentUser = $current_user;
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
        return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity.manager'), $container->get('module_handler'), $container->get('current_user'));
    }

}

Traits

Title Deprecated Summary
SelectionTrait Provides common methods and injects services for core selection handlers.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.