You are here

class ParagraphsTypePermissions in Paragraphs 8

Defines a class containing permission callbacks.

Hierarchy

Expanded class hierarchy of ParagraphsTypePermissions

File

modules/paragraphs_type_permissions/src/ParagraphsTypePermissions.php, line 11

Namespace

Drupal\paragraphs_type_permissions
View source
class ParagraphsTypePermissions {
  use StringTranslationTrait;

  /**
   * Returns an array of content permissions.
   *
   * @return array
   */
  public function globalPermissions() {
    return array(
      'bypass paragraphs type content access' => array(
        'title' => $this
          ->t('Bypass Paragraphs type content access control'),
        'description' => $this
          ->t('Is able to administer content for all Paragraph types'),
      ),
    );
  }

  /**
   * Returns an array of Paragraphs type permissions.
   *
   * @return array
   */
  public function paragraphTypePermissions() {
    $perms = array();

    // Generate paragraph permissions for all Paragraphs types.
    foreach (ParagraphsType::loadMultiple() as $type) {
      $perms += $this
        ->buildPermissions($type);
    }
    return $perms;
  }

  /**
   * Builds a standard list of node permissions for a given type.
   *
   * @param \Drupal\paragraphs\Entity\ParagraphsType $type
   *   The machine name of the node type.
   *
   * @return array
   *   An array of permission names and descriptions.
   */
  protected function buildPermissions(ParagraphsType $type) {
    $type_id = $type
      ->id();
    $type_params = array(
      '%type_name' => $type
        ->label(),
    );
    return array(
      'view paragraph content ' . $type_id => array(
        'title' => $this
          ->t('%type_name: View content', $type_params),
        'description' => $this
          ->t('Is able to view Paragraphs content of type %type_name', $type_params),
      ),
      'create paragraph content ' . $type_id => array(
        'title' => $this
          ->t('%type_name: Create content', $type_params),
        'description' => $this
          ->t('Is able to create Paragraphs content of type %type_name', $type_params),
      ),
      'update paragraph content ' . $type_id => array(
        'title' => $this
          ->t('%type_name: Edit content', $type_params),
        'description' => $this
          ->t('Is able to update Paragraphs content of type %type_name', $type_params),
      ),
      'delete paragraph content ' . $type_id => array(
        'title' => $this
          ->t('%type_name: Delete content', $type_params),
        'description' => $this
          ->t('Is able to delete Paragraphs content of type %type_name', $type_params),
      ),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParagraphsTypePermissions::buildPermissions protected function Builds a standard list of node permissions for a given type.
ParagraphsTypePermissions::globalPermissions public function Returns an array of content permissions.
ParagraphsTypePermissions::paragraphTypePermissions public function Returns an array of Paragraphs type permissions.
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.