class PermissionConfiguration in Configuration Management 7.2
Hierarchy
- class \Drupal\configuration\Config\Configuration
- class \Drupal\configuration\Config\PermissionConfiguration
Expanded class hierarchy of PermissionConfiguration
File
- lib/
Drupal/ configuration/ Config/ PermissionConfiguration.php, line 13 - Definition of Drupal\configuration\Config\PermissionConfiguration.
Namespace
Drupal\configuration\ConfigView source
class PermissionConfiguration extends Configuration {
/**
* Overrides Drupal\configuration\Config\Configuration::getComponentHumanName().
*/
public static function getComponentHumanName($component, $plural = FALSE) {
return $plural ? t('Permissions') : t('Permission');
}
/**
* Overrides Drupal\configuration\Config\Configuration::getComponent().
*/
public function getComponent() {
return 'permission';
}
/**
* Overrides Drupal\configuration\Config\Configuration::supportedComponents().
*/
public static function supportedComponents() {
return array(
'permission',
);
}
/**
* Returns the original permission based of the identifier of the
* configuration.
*
* @param string $identifier
* The configuration identifier.
*
*
* @return string
* The original permissions with spaces.
*/
public static function getPermissionById($identifier) {
$perms = static::getAllIdentifiers('permission');
if (!empty($perms[$identifier])) {
return $perms[$identifier];
}
}
/**
* Returns all the identifiers available for this component.
*/
public static function getAllIdentifiers($component) {
$return = array();
$permissions = array_keys(module_invoke_all('permission'));
foreach ($permissions as $permission) {
$id = str_replace(' ', '_', $permission);
$id = str_replace('/', '_', $id);
$return[$id] = $permission;
}
return $return;
}
/**
* Overrides Drupal\configuration\Config\Configuration::alterDependencies().
*/
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);
}
}
}
/**
* Overrides Drupal\configuration\Config\Configuration::findRequiredModules().
*/
public function findRequiredModules() {
$perm_modules = user_permission_get_modules();
$this
->addToModules($perm_modules[$this->data['permission']]);
}
/**
* Generate $rid => $role with role names untranslated.
*/
protected static function get_roles($builtin = TRUE) {
$roles = array();
foreach (user_roles() as $rid => $name) {
switch ($rid) {
case DRUPAL_ANONYMOUS_RID:
if ($builtin) {
$roles[$rid] = 'anonymous user';
}
break;
case DRUPAL_AUTHENTICATED_RID:
if ($builtin) {
$roles[$rid] = 'authenticated user';
}
break;
default:
$roles[$rid] = $name;
break;
}
}
return $roles;
}
/**
* Represent the current state of permissions as a perm to role name array map.
*/
protected static function get_permissions($by_role = TRUE) {
$map = user_permission_get_modules();
$roles = static::get_roles();
$permissions = array();
foreach (user_role_permissions($roles) as $rid => $role_permissions) {
if ($by_role) {
foreach (array_keys(array_filter($role_permissions)) as $permission) {
if (isset($map[$permission])) {
$permissions[$permission][] = $roles[$rid];
}
}
}
else {
$permissions[$roles[$rid]] = array();
foreach ($role_permissions as $permission => $status) {
if (isset($map[$permission])) {
$permissions[$roles[$rid]][$permission] = $status;
}
}
}
}
return $permissions;
}
/**
* Implements Drupal\configuration\Config\Configuration::prepareBuild().
*/
protected function prepareBuild() {
$permissions_roles = $this
->get_permissions();
$permission = static::getPermissionById($this->identifier);
$this->data = array(
'permission' => $permission,
'roles' => !empty($permissions_roles[$permission]) ? $permissions_roles[$permission] : array(),
);
if (!empty($this->data['roles'])) {
sort($this->data['roles']);
}
return $this;
}
/**
* Implements Drupal\configuration\Config\Configuration::saveToActiveStore().
*/
public function saveToActiveStore(ConfigIteratorSettings &$settings) {
node_types_rebuild();
$exist = FALSE;
$roles = static::get_roles();
$permissions_by_role = static::get_permissions(FALSE);
$map = user_permission_get_modules();
$permission = $this
->getData();
$perm = $permission['permission'];
foreach ($roles as $role) {
if (isset($map[$perm])) {
$exist = TRUE;
if (in_array($role, $permission['roles'])) {
$permissions_by_role[$role][$perm] = TRUE;
}
else {
$permissions_by_role[$role][$perm] = FALSE;
}
}
}
if (!$exist) {
drupal_set_message(t('Configuration Management: Permission %permission does not exist and can not be set.', array(
'%permission' => $perm,
)), 'error');
}
// Write the updated permissions.
foreach ($roles as $rid => $role) {
if (isset($permissions_by_role[$role])) {
user_role_change_permissions($rid, $permissions_by_role[$role]);
}
}
$settings
->addInfo('imported', $this
->getUniqueId());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Configuration:: |
protected | property | A boolean flag to indicate if the configuration object couldn't be loaded from it source. | |
Configuration:: |
protected | property | A boolean flag to indicate if the configuration object was already populated from the ActiveStore, or from the DataStore. | |
Configuration:: |
protected | property | The ConfigIteratorSettings instance used by iterate. | |
Configuration:: |
protected | property | The data of this configuration. | |
Configuration:: |
protected | property | An array of configuration objects required to use this configuration. | |
Configuration:: |
protected | property | A hash that represent that sumarizes the configuration and can be used to copare configurations. | |
Configuration:: |
protected | property | The identifier that identifies to the component, usually the machine name. | |
Configuration:: |
protected | property | An array of keys names to export. If the array is empty, all the keys of the configuration will be exported. | |
Configuration:: |
protected | property | An array of configuration objects that are parts of this configurations but are not required to use this configuration. | |
Configuration:: |
protected | property | The required modules to load this configuration. | |
Configuration:: |
protected | property | An object to save and load the data from a persistent medium. | |
Configuration:: |
public | function | Add a new dependency for this configuration. | |
Configuration:: |
public | function | Add a new dependency for this configuration. | |
Configuration:: |
public | function | Add a new child configuration for this configuration. | |
Configuration:: |
public | function | Build the configuration object based on the component name and in the identifier. | |
Configuration:: |
public | function | Create a unique hash for this configuration based on the data, dependencies, optional configurations and modules required to use this configuration. Use getHash() after call this function. | |
Configuration:: |
public | function | Returns TRUE if all the dependencies of this configurations are met. Returns FALSE if a module or a dependency is required by this configuration is not enabled. | |
Configuration:: |
public | function | Returns TRUE if the file that represents this configuration exists in the datastore. | |
Configuration:: |
public | function | Return TRUE if this is the configuration for an entity. | 3 |
Configuration:: |
protected | function | Internal function to discover what modules are required for the current being proccessed configurations. | |
Configuration:: |
public | function | ||
Configuration:: |
public | function | Ask to each configuration handler to add its dependencies to the current configuration that is being exported. | 2 |
Configuration:: |
public static | function | Cache wrapper for getAllIdentifiers(). | |
Configuration:: |
protected static | function | Helper for retrieving info from system table. | |
Configuration:: |
public | function | Return the data for this configuration. | |
Configuration:: |
public | function | Returns the list of dependencies of this configuration | |
Configuration:: |
public static | function | Determine the status of the given module and of its dependencies. | |
Configuration:: |
public | function | Returns the filename that contains the content of the current configuration. | |
Configuration:: |
public | function | Returns the hash of the configuration object. | |
Configuration:: |
public | function | Returns the identifier of the configuration object. | |
Configuration:: |
public | function | Returns an array of keys names to export. If the array is empty, all the keys of the configuration will be exported. | |
Configuration:: |
public | function | Returns the name of the required_modules that provide this configuration. | |
Configuration:: |
public | function | Returns the list of optional_configurations of this configuration | |
Configuration:: |
public | function | Returns a list of modules that are required to run this configuration. | |
Configuration:: |
public | function | Return the current status of the configuration. | |
Configuration:: |
protected static | function | Returns a Storage Object ready to load or write configurations from the disk. | 2 |
Configuration:: |
protected static | function | Returns a class with its namespace to save data to the disk. | 2 |
Configuration:: |
public | function | Returns an unique identifier for this configuration. Usually something like 'content_type.article' where content_type is the component of the configuration and 'article' is the identifier of the configuration for the given component. | |
Configuration:: |
public | function | Load a configuration from the DataStore and save it into the ActiveStore. This function is called from iterator(). | |
Configuration:: |
constant | A bit flag used to let us know if a configuration is the same in both the activestore and the datastore. | ||
Configuration:: |
public static | function | Determine if the handler can be used. Usually this function should check that modules required to handle the configuration are installed. | 8 |
Configuration:: |
public | function | Return TRUE if something went wrong with the load of the configuration. | |
Configuration:: |
public | function | This function will exectute a callback function over all the configurations objects that it process. | |
Configuration:: |
public | function | Load a configurations from the database. | |
Configuration:: |
public | function | Load the Configuration data from the disk. | |
Configuration:: |
constant | A bit flag used to let us know if a module for the configuration is already installed. | ||
Configuration:: |
constant | A bit flag used to let us know if a module for the configuration is not available to install in the site. | ||
Configuration:: |
constant | A bit flag used to let us know if a module for the configuration is disabled but can be enabled. | ||
Configuration:: |
constant | A bit flag used to let us know if a configuration is not currently being tracked. | ||
Configuration:: |
constant | A bit flag used to let us know if a configuration was overridden as a result of changing the activestore directly. (config changes via the UI) | ||
Configuration:: |
protected | function | Print the configuration as plain text formatted to use in a tar file. | |
Configuration:: |
public | function | Print the configuration as plain text formatted to use in a tar file. | |
Configuration:: |
public | function | Removes the configuration record from the configuration_tracked table for the current configuration. | |
Configuration:: |
public | function | Removes the configuration file from the dataStore folder. | |
Configuration:: |
public static | function | Returns the list of components available in the DataStore. | |
Configuration:: |
public | function | Set the context where a function is executed. | |
Configuration:: |
public | function | Set the data for this configuration. | |
Configuration:: |
public | function | Returns the list of dependencies of this configuration | |
Configuration:: |
public | function | Set the hash for this configuration. | |
Configuration:: |
public | function | Set the component identifier of this configuration | |
Configuration:: |
public | function | Set an array of keys names to export. If the array is empty, all the keys of the configuration will be exported. | |
Configuration:: |
public | function | Set the name of the required_modules that provide this configuration. | |
Configuration:: |
public | function | Returns the list of optional_configurations of this configuration | |
Configuration:: |
public | function | Save a configuration object into the configuration_tracked table. | |
Configuration:: |
public | function | Removes the configuration record from the configuration_tracked table for the current configuration. | |
Configuration:: |
public | function | Constructor. | 5 |
PermissionConfiguration:: |
public static | function |
Overrides Drupal\configuration\Config\Configuration::alterDependencies(). Overrides Configuration:: |
|
PermissionConfiguration:: |
public | function |
Overrides Drupal\configuration\Config\Configuration::findRequiredModules(). Overrides Configuration:: |
|
PermissionConfiguration:: |
public static | function |
Returns all the identifiers available for this component. Overrides Configuration:: |
|
PermissionConfiguration:: |
public | function |
Overrides Drupal\configuration\Config\Configuration::getComponent(). Overrides Configuration:: |
|
PermissionConfiguration:: |
public static | function |
Overrides Drupal\configuration\Config\Configuration::getComponentHumanName(). Overrides Configuration:: |
|
PermissionConfiguration:: |
public static | function | Returns the original permission based of the identifier of the configuration. | |
PermissionConfiguration:: |
protected static | function | Represent the current state of permissions as a perm to role name array map. | |
PermissionConfiguration:: |
protected static | function | Generate $rid => $role with role names untranslated. | |
PermissionConfiguration:: |
protected | function |
Implements Drupal\configuration\Config\Configuration::prepareBuild(). Overrides Configuration:: |
|
PermissionConfiguration:: |
public | function |
Implements Drupal\configuration\Config\Configuration::saveToActiveStore(). Overrides Configuration:: |
|
PermissionConfiguration:: |
public static | function |
Overrides Drupal\configuration\Config\Configuration::supportedComponents(). Overrides Configuration:: |