You are here

public static function PermissionConfiguration::alterDependencies in Configuration Management 7.2

Overrides Drupal\configuration\Config\Configuration::alterDependencies().

Overrides Configuration::alterDependencies

File

lib/Drupal/configuration/Config/PermissionConfiguration.php, line 69
Definition of Drupal\configuration\Config\PermissionConfiguration.

Class

PermissionConfiguration

Namespace

Drupal\configuration\Config

Code

public static function alterDependencies(Configuration $config) {
  if ($config
    ->getComponent() == 'content_type') {
    $permissions = node_list_permissions($config
      ->getIdentifier());
    foreach (array_keys($permissions) as $permission) {
      $identifier = str_replace(' ', '_', $permission);
      $perm = new PermissionConfiguration($identifier);
      $perm
        ->build();

      // Add the content type as a dependency of the permission.
      $perm
        ->addToDependencies($config);

      // Add the permission as a child configuration of the content type
      // The permission is not required to load the content type but is
      // a nice to have.
      $config
        ->addToOptionalConfigurations($perm);
    }
  }
  elseif ($config
    ->getComponent() == 'text_format') {
    $format = $config
      ->getData();
    $permission = filter_permission_name($format);
    if (!empty($permission)) {
      $identifier = str_replace(' ', '_', $permission);
      $perm = new PermissionConfiguration($identifier);
      $perm
        ->build();

      // Add the text format as a dependency of the permission.
      $perm
        ->addToDependencies($config);

      // Add the permission as a child configuration of the filter
      // The permission is not required to load the filter format but is
      // a nice to have.
      $config
        ->addToOptionalConfigurations($perm);
    }
  }
}