You are here

class Permissions in Search API Saved Searches 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_saved_searches
View source
class Permissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * The saved search type storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $storage;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    $object = new static();
    $storage = $container
      ->get('entity_type.manager')
      ->getStorage('search_api_saved_search_type');
    $object
      ->setStorage($storage);
    $object
      ->setStringTranslation($container
      ->get('string_translation'));
    return $object;
  }

  /**
   * Retrieves the saved search type storage.
   *
   * @return \Drupal\Core\Entity\EntityStorageInterface
   *   The saved search type storage.
   */
  public function getStorage() {
    return $this->storage ?: \Drupal::entityTypeManager()
      ->getStorage('search_api_saved_search_type');
  }

  /**
   * Sets the saved search type storage.
   *
   * @param \Drupal\Core\Entity\EntityStorageInterface $storage
   *   The new saved search type storage.
   *
   * @return $this
   */
  public function setStorage(EntityStorageInterface $storage) {
    $this->storage = $storage;
    return $this;
  }

  /**
   * Returns a list of permissions, one per configured saved search type.
   *
   * @return array[]
   *   A list of permission definitions, keyed by permission machine name.
   */
  public function bySavedSearchType() {
    $perms = [];
    foreach ($this
      ->getStorage()
      ->loadMultiple() as $id => $type) {
      $args = [
        '%type' => $type
          ->label(),
      ];
      $perms['use ' . $id . ' search_api_saved_searches'] = [
        'title' => $this
          ->t('Use saved searches of type %type', $args),
      ];
    }
    return $perms;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Permissions::$storage protected property The saved search type storage.
Permissions::bySavedSearchType public function Returns a list of permissions, one per configured saved search type.
Permissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
Permissions::getStorage public function Retrieves the saved search type storage.
Permissions::setStorage public function Sets the saved search type storage.
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.