You are here

class RoleConfigurationHandler in Configuration Management 7.3

Hierarchy

Expanded class hierarchy of RoleConfigurationHandler

1 file declares its use of RoleConfigurationHandler
ConfigurationManager.php in src/ConfigurationManager.php

File

src/Handlers/RoleConfigurationHandler.php, line 9

Namespace

Configuration\Handlers
View source
class RoleConfigurationHandler extends ConfigurationHandler {
  public static function getSupportedTypes() {
    return array(
      'role',
    );
  }
  protected function registerProcessors() {
    foreach (\Configuration\Processors\RoleProcessor::availableProcessors() as $name) {
      $processor = new \Configuration\Processors\RoleProcessor($name, $this->configuration_manager);
      $this->configuration_manager
        ->registerProcessor($name, $processor);
    }
  }
  public function getIdentifiers() {
    $identifiers = array(
      'anonymous_user' => t('Anonymous user'),
      'authenticated_user' => t('Authenticated user'),
    );
    foreach ($this->configuration_manager
      ->drupal()
      ->role_export_roles() as $role) {
      if ($role->rid > 2) {
        $identifiers[$role->machine_name] = $role->name;
      }
    }
    return $identifiers;
  }
  public function loadFromDatabase($identifier) {
    $name = $this
      ->getInternalId($identifier);
    $configuration = new Configuration();
    $configuration
      ->setIdentifier($identifier);
    foreach ($this->configuration_manager
      ->drupal()
      ->role_export_roles() as $role) {
      if ($role->machine_name == $name) {
        unset($role->rid);
        $configuration
          ->setData($role);
        $configuration
          ->addModule('role_export');
        break;
      }
    }
    $event = $this
      ->triggerEvent('load_from_database', $configuration);
    return $event->configuration;
  }
  public function writeToDatabase(Configuration $configuration) {
    $name = $this
      ->getInternalId($configuration
      ->getIdentifier());
    if ($name == 'anonymous_user' || $name == 'authenticated_user') {
      return;
    }
    $event = $this
      ->triggerEvent('write_to_database', $configuration);
    $role = $event->configuration
      ->getData();
    $existent_role = $this->configuration_manager
      ->drupal()
      ->role_roleExists($name);
    if ($existent_role) {

      // Updating an existent role.
      $role->rid = $existent_role;
    }
    $this->configuration_manager
      ->drupal()
      ->user_role_save($role);
  }
  public function removeFromDatabase(Configuration $configuration) {
    $name = $this
      ->getInternalId($configuration
      ->getIdentifier());
    if ($name == 'anonymous_user' || $name == 'authenticated_user') {
      return;
    }
    $event = $this
      ->triggerEvent('remove_from_database', $configuration);
    $role = $event->configuration
      ->getData();
    $this->configuration_manager
      ->drupal()
      ->user_role_delete($role);
  }
  public static function getSubscribedEvents() {
    return array(
      'load_from_database.permission' => array(
        'onPermissionLoad',
        0,
      ),
    );
  }
  public function onPermissionLoad($event) {
    $permission = $event->configuration
      ->getData();
    foreach ($permission['roles'] as $role) {
      $this->configuration_manager
        ->newDependency($event->configuration, 'role.' . $role);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigurationHandler::$configuration_manager protected property
ConfigurationHandler::$type protected property
ConfigurationHandler::export public function Generates the JSON representation of this configuration.
ConfigurationHandler::exportToJson protected function
ConfigurationHandler::getExportPath public function
ConfigurationHandler::getInternalId protected function
ConfigurationHandler::getType public function
ConfigurationHandler::getTypeFromId protected function
ConfigurationHandler::import public function
ConfigurationHandler::importFromJson public function
ConfigurationHandler::importFromJsonAsArray protected function 1
ConfigurationHandler::jsonAsArray protected function 9
ConfigurationHandler::triggerEvent protected function
ConfigurationHandler::__construct public function 1
RoleConfigurationHandler::getIdentifiers public function Returns the configuration identifiers handled by this instance. Overrides ConfigurationHandler::getIdentifiers
RoleConfigurationHandler::getSubscribedEvents public static function Overrides ConfigurationHandler::getSubscribedEvents
RoleConfigurationHandler::getSupportedTypes public static function Returns the types of configurations that this class can handle. Overrides ConfigurationHandler::getSupportedTypes
RoleConfigurationHandler::loadFromDatabase public function Loads the configuration from the database. Overrides ConfigurationHandler::loadFromDatabase
RoleConfigurationHandler::onPermissionLoad public function
RoleConfigurationHandler::registerProcessors protected function Overrides ConfigurationHandler::registerProcessors
RoleConfigurationHandler::removeFromDatabase public function Deletes a configuration from the database. Overrides ConfigurationHandler::removeFromDatabase
RoleConfigurationHandler::writeToDatabase public function Saves the given configuration into the database. Overrides ConfigurationHandler::writeToDatabase