You are here

class ContentTypeConfigurationHandler in Configuration Management 7.3

Hierarchy

Expanded class hierarchy of ContentTypeConfigurationHandler

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

File

src/Handlers/ContentTypeConfigurationHandler.php, line 8

Namespace

Configuration\Handlers
View source
class ContentTypeConfigurationHandler extends ConfigurationHandler {
  public static function getSupportedTypes() {
    return array(
      'content_type',
    );
  }
  public function getIdentifiers() {
    return $this->configuration_manager
      ->drupal()
      ->node_type_get_names();
  }
  public function loadFromDatabase($identifier) {
    $content_type_name = $this
      ->getInternalId($identifier);
    $configuration = new Configuration();
    $configuration
      ->setIdentifier($identifier);
    $content_type = (object) $this->configuration_manager
      ->drupal()
      ->node_type_get_type($content_type_name);
    $data = new \StdClass();
    $keys = array(
      'type',
      'name',
      'description',
      'has_title',
      'title_label',
      'base',
      'module',
      'help',
    );
    foreach ($keys as $key) {
      $data->{$key} = $content_type->{$key};
    }

    // Force module name to be 'configuration' if set to 'node. If we leave as
    // 'node' the content type will be assumed to be database-stored by
    // the node module.
    if ($content_type->base === 'node') {
      $data->base = 'configuration';
    }
    $configuration
      ->setData($data);
    $event = $this
      ->triggerEvent('load_from_database', $configuration);
    $event_settings = array(
      'entity_type' => 'node',
      'bundle_name' => $data->type,
    );
    $event = $this
      ->triggerEvent('load_from_database.entity', $event->configuration, $event_settings, FALSE);
    return $event->configuration;
  }
  public function writeToDatabase(Configuration $configuration) {
    $content_type_name = $this
      ->getInternalId($configuration
      ->getIdentifier());
    $event = $this
      ->triggerEvent('write_to_database', $configuration);
    $content_type = $event->configuration
      ->getData();
    $content_type->base = isset($content_type->base) ? $content_type->base : 'node_content';
    $content_type->module = isset($content_type->module) ? $content_type->module : 'node';
    $content_type->custom = 1;
    $content_type->modified = 1;
    $content_type->locked = 0;
    $this->configuration_manager
      ->drupal()
      ->node_type_save($content_type);
  }
  public function removeFromDatabase(Configuration $configuration) {
    $content_type_name = $this
      ->getInternalId($configuration
      ->getIdentifier());
    $event = $this
      ->triggerEvent('remove_from_database', $configuration);
    $this->configuration_manager
      ->drupal()
      ->node_type_delete($content_type_name);
  }

}

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