generatePermissions example

$container->get('entity_type.manager'),
    );
  }

  /** * Build permissions for each block type. * * @return array * The block type permissions. */
  public function blockTypePermissions() {
    return $this->generatePermissions($this->entityTypeManager->getStorage('block_content_type')->loadMultiple()[$this, 'buildPermissions']);
  }

  /** * Return all the permissions available for a block type. * * @param \Drupal\block_content\Entity\BlockContentType $type * The block type. * * @return array * Permissions available for the given block type. */
  
public static function create(ContainerInterface $container) {
    return new static($container->get('entity_type.manager'));
  }

  /** * Get taxonomy permissions. * * @return array * Permissions array. */
  public function permissions() {
    return $this->generatePermissions(Vocabulary::loadMultiple()[$this, 'buildPermissions']);
  }

  /** * Builds a standard list of taxonomy term permissions for a given vocabulary. * * @param \Drupal\taxonomy\VocabularyInterface $vocabulary * The vocabulary. * * @return array * An array of permission names and descriptions. */
  
use BundlePermissionHandlerTrait;
  use StringTranslationTrait;

  /** * Returns an array of node type permissions. * * @return array * The node type permissions. * @see \Drupal\user\PermissionHandlerInterface::getPermissions() */
  public function nodeTypePermissions() {
    return $this->generatePermissions(NodeType::loadMultiple()[$this, 'buildPermissions']);
  }

  /** * Returns a list of node permissions for a given node type. * * @param \Drupal\node\Entity\NodeType $type * The node type. * * @return array * An associative array of permission names and descriptions. */
  
/** * Returns an array of media type permissions. * * @return array * The media type permissions. * * @see \Drupal\user\PermissionHandlerInterface::getPermissions() */
  public function mediaTypePermissions() {
    // Generate media permissions for all media types.     $media_types = $this->entityTypeManager->getStorage('media_type')->loadMultiple();
    return $this->generatePermissions($media_types[$this, 'buildPermissions']);
  }

  /** * Returns a list of media permissions for a given media type. * * @param \Drupal\media\MediaTypeInterface $type * The media type. * * @return array * An associative array of permission names and descriptions. */
  
/** * @covers ::generatePermissions */
  public function testGeneratePermissions() {
    EntityTestBundle::create([
      'id' => 'test1',
    ])->save();
    EntityTestBundle::create([
      'id' => 'test2',
    ])->save();
    $permissions = $this->generatePermissions(EntityTestBundle::loadMultiple()[$this, 'buildPermissions']);
    $this->assertSame([
      'title' => 'Create',
      'dependencies' => ['config' => ['entity_test.entity_test_bundle.test1']],
    ]$permissions['create test1']);
    $this->assertSame([
      'title' => 'Edit',
      'dependencies' => [
        'config' => [
          'test_module.entity.test1',
          'entity_test.entity_test_bundle.test1',
        ],
        
Home | Imprint | This part of the site doesn't use cookies.