function PermissionsPerBundle::parseValue

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Config/Action/Plugin/ConfigAction/PermissionsPerBundle.php \Drupal\Core\Config\Action\Plugin\ConfigAction\PermissionsPerBundle::parseValue()

Parses the value supplied to ::apply().

Parameters

string|array<string|string[]> $value: One of:

  • A single string (a permission template).
  • An array of strings (several permission templates).
  • An array with a `permissions` element, and an optional `except` element, either of which can be an array or a string. `except` accepts a single bundle, or a list of bundles, to exclude from the permissions being granted.

Return value

array<int, array<int<0, max>, array<string>|string>> An indexed array with two elements: the array of permissions to grant, and the list of bundles to ignore.

1 call to PermissionsPerBundle::parseValue()
PermissionsPerBundle::apply in core/lib/Drupal/Core/Config/Action/Plugin/ConfigAction/PermissionsPerBundle.php
Applies the config action.

File

core/lib/Drupal/Core/Config/Action/Plugin/ConfigAction/PermissionsPerBundle.php, line 93

Class

PermissionsPerBundle
@internal This API is experimental.

Namespace

Drupal\Core\Config\Action\Plugin\ConfigAction

Code

private static function parseValue(string|array $value) : array {
    if (is_string($value)) {
        return [
            [
                $value,
            ],
            [],
        ];
    }
    if (array_is_list($value)) {
        return [
            $value,
            [],
        ];
    }
    $permissions = $value['permissions'] ?? [];
    $except_bundles = $value['except'] ?? [];
    return [
        (array) $permissions,
        (array) $except_bundles,
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.