You are here

configuration.module in Configuration Management 7.2

Same filename and directory in other branches
  1. 6 configuration.module
  2. 7.3 configuration.module
  3. 7 configuration.module

API for Configuration Management module.

File

configuration.module
View source
<?php

/**
 * @file
 * API for Configuration Management module.
 */
use Drupal\configuration\Config\ConfigurationManagement;

/**
 * Implements hook_stream_wrappers().
 */
function configuration_stream_wrappers() {
  return array(
    'config' => array(
      'name' => t('Configuration files'),
      'class' => 'ConfigurationStreamWrapper',
      'description' => t('Configuration files export directory.'),
      'type' => STREAM_WRAPPERS_LOCAL_HIDDEN,
    ),
  );
}

/**
 * Define basic handlers().
 *
 * Other modules can modify and alter new this array by implementing
 * hook_configuration_handlers_alter().
 */
function configuration_configuration_handlers() {
  $handlers = array(
    'content_type' => '\\Drupal\\configuration\\Config\\ContentTypeConfiguration',
    'field' => '\\Drupal\\configuration\\Config\\FieldConfiguration',
    'image_style' => '\\Drupal\\configuration\\Config\\ImageStyleConfiguration',
    'text_format' => '\\Drupal\\configuration\\Config\\TextFormatConfiguration',
    'variable' => '\\Drupal\\configuration\\Config\\VariableConfiguration',
    'permission' => '\\Drupal\\configuration\\Config\\PermissionConfiguration',
    'vocabulary' => '\\Drupal\\configuration\\Config\\VocabularyConfiguration',
    'menu' => '\\Drupal\\configuration\\Config\\MenuConfiguration',
    'menu_link' => '\\Drupal\\configuration\\Config\\MenuLinkConfiguration',
    'ctools' => '\\Drupal\\configuration\\Config\\CtoolsConfiguration',
    'entity' => '\\Drupal\\configuration\\Config\\EntityApiConfiguration',
    'views' => '\\Drupal\\configuration\\Config\\ViewConfiguration',
    'strongarm' => '\\Drupal\\configuration\\Config\\StrongarmConfiguration',
    'page_manager' => '\\Drupal\\configuration\\Config\\PageManagerHandlerConfiguration',
    'panelizer' => '\\Drupal\\configuration\\Config\\PanelizerConfiguration',
    'wysiwyg' => '\\Drupal\\configuration\\Config\\WysiwygConfiguration',
    'role_export' => '\\Drupal\\configuration\\Config\\RoleConfiguration',
    'field_group' => '\\Drupal\\configuration\\Config\\FieldGroupConfiguration',
  );
  drupal_alter('configuration_handlers', $handlers);
  return $handlers;
}

/**
 * Import all configuration files within a directory.
 *
 * The configurations files in the directory have to match the migration
 * estructure of configurations. See http://drupal.org/node/1872288 for
 * clarification of migration vs sync process.
 *
 * @param $path
 *   The path to the directory to import.
 * @param $enable_modules
 *   Enable all the required modules before the import process.
 * @param $include_dependencies
 *   Process a component and all its dependencies.
 * @param $include_optionals
 *   Process a component and all its optionals.
 * @param $start_tracking
 *   Start tracking all imported configurations.
 *
 */
function configuration_import_directory($path, $enable_modules = TRUE, $include_dependencies = TRUE, $include_optionals = TRUE, $start_tracking = TRUE) {
  $path = rtrim($path, '/');
  $file_content = drupal_substr(file_get_contents($path . '/configurations.inc'), 6);

  // this line creates a $configurations array with a list of components and a
  // $modules array with a list of required modules to be enabled.
  @eval($file_content);
  if ($enable_modules) {
    $settings = ConfigurationManagement::discoverRequiredModules($modules);
    $missing = $settings
      ->getInfo('modules_missing');
    if (count($missing)) {
      $missing = implode(', ', $missing);
      drupal_set_message(t('The following modules are required to import the specified configurations but are not available to install: %modules', array(
        '%modules' => $missing,
      )), 'error');
      return FALSE;
    }
    else {
      $to_install = $settings
        ->getInfo('modules_to_install');
      module_enable($to_install);
    }
  }
  $result = ConfigurationManagement::importToActiveStore($configurations, $include_dependencies, $include_optionals, FALSE, $path);
  $imported = $result
    ->getInfo('imported');
  if ($start_tracking) {
    $tracked = ConfigurationManagement::startTracking($configurations, $include_dependencies, $include_optionals);
  }
  if (is_array($imported) && count($imported) > 0) {
    return $imported;
  }
  else {
    return FALSE;
  }
}

Functions

Namesort descending Description
configuration_configuration_handlers Define basic handlers().
configuration_import_directory Import all configuration files within a directory.
configuration_stream_wrappers Implements hook_stream_wrappers().