You are here

class TextFormatConfigurationHandler in Configuration Management 7.3

Hierarchy

Expanded class hierarchy of TextFormatConfigurationHandler

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

File

src/Handlers/TextFormatConfigurationHandler.php, line 9

Namespace

Configuration\Handlers
View source
class TextFormatConfigurationHandler extends ConfigurationHandler {
  public static function getSupportedTypes() {
    return array(
      'text_format',
    );
  }
  public function getIdentifiers() {
    $identifiers = array();
    foreach ($this->configuration_manager
      ->drupal()
      ->filter_formats() as $format) {
      $identifiers[$format->format] = $format->name;
    }
    return $identifiers;
  }
  public function loadFromDatabase($identifier) {
    $name = $this
      ->getInternalId($identifier);
    $configuration = new Configuration();
    $configuration
      ->setIdentifier($identifier);
    $format = $this->configuration_manager
      ->drupal()
      ->text_format_getFilterFormat($name);
    if (!empty($format)) {
      $filters_info = $this->configuration_manager
        ->drupal()
        ->filter_get_filters();
      $format->filters = array();
      foreach ($this->configuration_manager
        ->drupal()
        ->filter_list_format($format->format) as $filter) {
        if (!empty($filter->status)) {
          $format->filters[$filter->name]['weight'] = $filter->weight;
          $format->filters[$filter->name]['status'] = $filter->status;
          $format->filters[$filter->name]['settings'] = $filter->settings;
          $configuration
            ->addModule($filters_info[$filter->name]['module']);
        }
      }
      $configuration
        ->setData($format);
    }
    $event = $this
      ->triggerEvent('load_from_database', $configuration);
    return $event->configuration;
  }
  public function writeToDatabase(Configuration $configuration) {
    $event = $this
      ->triggerEvent('write_to_database', $configuration);
    $format_array = $event->configuration
      ->getData();
    $format = new \StdClass();
    $format->format = $format_array["format"];
    $format->name = $format_array["name"];
    $format->cache = $format_array["cache"];
    $format->status = $format_array["status"];
    $format->weight = $format_array["weight"];
    $format->filters = $format_array["filters"];
    $this->configuration_manager
      ->drupal()
      ->filter_format_save($format);
  }
  public function removeFromDatabase(Configuration $configuration) {
    $name = $this
      ->getInternalId($configuration
      ->getIndentifier());
    $this->configuration_manager
      ->drupal()
      ->filter_format_load($name);
    $this->configuration_manager
      ->drupal()
      ->filter_format_disable($format);
    $event = $this
      ->triggerEvent('remove_from_database', $configuration);
  }
  public static function getSubscribedEvents() {
    return array(
      'load_from_database.permission' => array(
        'onPermissionLoad',
        0,
      ),
    );
  }
  public function onPermissionLoad($event) {

    // Search for permissions that match: 'use text format ' . $format->format
    $permission = $event->configuration
      ->getData();
    if (strpos($permission['permission'], 'user text format') !== FALSE) {
      foreach ($this->configuration_manager
        ->drupal()
        ->filter_formats() as $format) {
        $permission = $this->configuration_manager
          ->drupal()
          ->filter_permission_name($format);
        if (!empty($permission)) {
          $data = $event->configuration
            ->getData();
          if ($permission == $data['permission']) {
            $this->configuration_manager
              ->newDependency($event->configuration, 'text_format.' . $format->format);

            // Match found, no other text format will match.
            break;
          }
        }
      }
    }
  }
  protected function jsonAsArray() {
    return TRUE;
  }

}

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::registerProcessors protected function 2
ConfigurationHandler::triggerEvent protected function
ConfigurationHandler::__construct public function 1
TextFormatConfigurationHandler::getIdentifiers public function Returns the configuration identifiers handled by this instance. Overrides ConfigurationHandler::getIdentifiers
TextFormatConfigurationHandler::getSubscribedEvents public static function Overrides ConfigurationHandler::getSubscribedEvents
TextFormatConfigurationHandler::getSupportedTypes public static function Returns the types of configurations that this class can handle. Overrides ConfigurationHandler::getSupportedTypes
TextFormatConfigurationHandler::jsonAsArray protected function Overrides ConfigurationHandler::jsonAsArray
TextFormatConfigurationHandler::loadFromDatabase public function Loads the configuration from the database. Overrides ConfigurationHandler::loadFromDatabase
TextFormatConfigurationHandler::onPermissionLoad public function
TextFormatConfigurationHandler::removeFromDatabase public function Deletes a configuration from the database. Overrides ConfigurationHandler::removeFromDatabase
TextFormatConfigurationHandler::writeToDatabase public function Saves the given configuration into the database. Overrides ConfigurationHandler::writeToDatabase