You are here

class Permissions in Search API Autocomplete 8

Provides permissions of the search_api_autocomplete module.

Hierarchy

Expanded class hierarchy of Permissions

File

src/Permissions.php, line 13

Namespace

Drupal\search_api_autocomplete
View source
class Permissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * The entity storage service.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $storage;

  /**
   * Constructs a Permissions object.
   *
   * @param \Drupal\Core\Entity\EntityStorageInterface $storage
   *   The entity storage service.
   */
  public function __construct(EntityStorageInterface $storage) {
    $this->storage = $storage;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('entity_type.manager')
      ->getStorage('search_api_autocomplete_search'));
  }

  /**
   * Returns a list of permissions, one per configured search.
   *
   * @return array[]
   *   A list of permission definitions, keyed by permission machine name.
   */
  public function bySearch() {
    $perms = [];

    /** @var \Drupal\search_api_autocomplete\SearchInterface $search */
    foreach ($this->storage
      ->loadMultiple() as $id => $search) {
      $perms['use search_api_autocomplete for ' . $id] = [
        'title' => $this
          ->t('Use autocomplete for the %search search', [
          '%search' => $search
            ->label(),
        ]),
      ];
    }
    return $perms;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Permissions::$storage protected property The entity storage service.
Permissions::bySearch public function Returns a list of permissions, one per configured search.
Permissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
Permissions::__construct public function Constructs a Permissions object.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.