You are here

class CustomPermissions in Custom Permissions 8

Same name and namespace in other branches
  1. 8.2 src/CustomPermissions.php \Drupal\config_perms\CustomPermissions

Provides dynamic permissions of the filter module.

Hierarchy

Expanded class hierarchy of CustomPermissions

File

src/CustomPermissions.php, line 13

Namespace

Drupal\config_perms
View source
class CustomPermissions implements ContainerInjectionInterface {
  use StringTranslationTrait;

  /**
   * The entity manager.
   *
   * @var \Drupal\Core\Entity\EntityManagerInterface
   */
  protected $entityManager;

  /**
   * Constructs a new FilterPermissions instance.
   *
   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
   *   The entity manager.
   */
  public function __construct(EntityManagerInterface $entity_manager) {
    $this->entityManager = $entity_manager;
  }

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

  /**
   * Returns an array of filter permissions.
   *
   * @return array
   *   Return a table of permissions
   */
  public function permissions() {
    $permissions = [];

    // Generate permissions for each text format. Warn the administrator that
    // any of them are potentially unsafe.

    /** @var \Drupal\filter\FilterFormatInterface[] $formats */
    $custom_perms = $this->entityManager
      ->getStorage('custom_perms_entity')
      ->loadByProperties([
      'status' => TRUE,
    ]);
    uasort($custom_perms, 'Drupal\\Core\\Config\\Entity\\ConfigEntityBase::sort');
    foreach ($custom_perms as $custom_perm) {
      if ($permission = $custom_perm
        ->label()) {
        $permissions[$permission] = [
          'title' => $permission,
          'description' => [
            '#prefix' => '<em>',
            '#markup' => $this
              ->t('Warning: This permission may have security implications.'),
            '#suffix' => '</em>',
          ],
        ];
      }
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CustomPermissions::$entityManager protected property The entity manager.
CustomPermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
CustomPermissions::permissions public function Returns an array of filter permissions.
CustomPermissions::__construct public function Constructs a new FilterPermissions instance.
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.