class RoleProcessor in Configuration Management 7.3
Hierarchy
- class \Configuration\Processors\AbstractProcessor implements ProcessorInterface
- class \Configuration\Processors\RoleProcessor
Expanded class hierarchy of RoleProcessor
File
- src/
Processors/ RoleProcessor.php, line 7
Namespace
Configuration\ProcessorsView source
class RoleProcessor extends AbstractProcessor {
public static function availableProcessors() {
return array(
// Converts the keys of an array from Role Ids to Role machine names.
'RoleKeyId2Name',
// Converts the values of an array from Role Ids to Role machine names.
'RoleValueId2Name',
// Converts the keys and the values of an array from Role Ids to Role machine names.
'RoleAllId2Name',
);
}
public function apply(Configuration $configuration, $properties = array()) {
$roles_names = array(
DRUPAL_ANONYMOUS_RID => 'anonymous_user',
DRUPAL_AUTHENTICATED_RID => 'authenticated_user',
);
foreach (role_export_roles() as $role) {
if ($role->rid > 2) {
$roles_names[$role->rid] = $role->machine_name;
}
}
$converted = array();
foreach ($properties as $property) {
$array = $configuration
->getValue($property);
foreach ($array as $key => $value) {
switch ($this
->getName()) {
case 'RoleKeyId2Name':
$converted[$roles_names[$key]] = $value;
break;
case 'RoleValueId2Name':
$converted[$key] = $roles_names[$value];
break;
case 'RoleAllId2Name':
$converted[$roles_names[$key]] = $roles_names[$value];
break;
}
}
$configuration
->setValue($property, $converted);
}
}
public function revert(Configuration $configuration, $properties = array()) {
$roles_ids = array(
'anonymous_user' => DRUPAL_ANONYMOUS_RID,
'authenticated_user' => DRUPAL_AUTHENTICATED_RID,
);
foreach (role_export_roles() as $role) {
if ($role->rid > 2) {
$roles_ids[$role->machine_name] = $role->rid;
}
}
$converted = array();
foreach ($properties as $property) {
$array = $configuration
->getValue($property);
foreach ($array as $key => $value) {
switch ($this
->getName()) {
case 'RoleKeyId2Name':
$converted[$roles_ids[$key]] = $value;
break;
case 'RoleValueId2Name':
$converted[$key] = $roles_ids[$value];
break;
case 'RoleAllId2Name':
$converted[$roles_ids[$key]] = $roles_ids[$value];
break;
}
}
$configuration
->setValue($property, $converted);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AbstractProcessor:: |
protected | property | ||
AbstractProcessor:: |
protected | property | ||
AbstractProcessor:: |
public | function | ||
AbstractProcessor:: |
public static | function | ||
AbstractProcessor:: |
public | function | ||
RoleProcessor:: |
public | function |
Overrides AbstractProcessor:: |
|
RoleProcessor:: |
public static | function |
Overrides AbstractProcessor:: |
|
RoleProcessor:: |
public | function |
Overrides AbstractProcessor:: |