You are here

public function SearchApiConverter::__construct in Search API 8

Same name in this branch
  1. 8 src/ParamConverter/SearchApiConverter.php \Drupal\search_api\ParamConverter\SearchApiConverter::__construct()
  2. 8 src/ProxyClass/ParamConverter/SearchApiConverter.php \Drupal\search_api\ProxyClass\ParamConverter\SearchApiConverter::__construct()

Constructs a new SearchApiConverter.

Parameters

\Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager: The entity type manager.

\Drupal\Core\Entity\EntityRepositoryInterface $entity_repository: The entity repository.

\Drupal\Core\TempStore\SharedTempStoreFactory $temp_store_factory: The factory for the temp store object.

\Drupal\Core\Session\AccountInterface $user: The current user.

Overrides EntityConverter::__construct

File

src/ParamConverter/SearchApiConverter.php, line 55

Class

SearchApiConverter
Converts search indexes from path parameters to a temporary copy.

Namespace

Drupal\search_api\ParamConverter

Code

public function __construct(EntityTypeManagerInterface $entity_type_manager, $entity_repository, $temp_store_factory, $user = NULL) {

  // For backwards-compatibility, we still support passing just
  // ($entity_manager, $temp_store_factory, $user).
  if (!$user) {
    @trigger_error('Constructing \\Drupal\\search_api\\ParamConverter\\SearchApiConverter with ($entity_manager, $temp_store_factory, $user) is deprecated in search_api 8.x-1.18 and will stop working in 2.0.0. Pass ($entity_type_manager, $entity_repository, $temp_store_factory, $user) instead. See https://www.drupal.org/node/3164248', E_USER_DEPRECATED);
    $user = $temp_store_factory;
    $temp_store_factory = $entity_repository;
    $entity_repository = \Drupal::getContainer()
      ->get('entity.repository');
  }
  $type_checks = [
    2 => [
      $entity_repository,
      EntityRepositoryInterface::class,
    ],
    3 => [
      $temp_store_factory,
      SharedTempStoreFactory::class,
    ],
    4 => [
      $user,
      AccountInterface::class,
    ],
  ];
  foreach ($type_checks as $i => list($object, $expected)) {
    if (!$object instanceof $expected) {
      $actual = get_class($object);
      throw new \TypeError("Argument {$i} passed to Drupal\\search_api\\ParamConverter\\SearchApiConverter::__construct() must implement interface {$expected}, instance of {$actual} given");
    }
  }
  parent::__construct($entity_type_manager, $entity_repository);
  $this->tempStoreFactory = $temp_store_factory;
  $this->currentUser = $user;
}