/** * Overrides Drupal\configuration\Config\PermissionConfiguration::alterDependencies(). */ public static function alterDependencies(Configuration $config) { parent::alterDependencies($config); $id = $config->getIdentifier(); // Rules components that involve permissions should have the permission // bundled along with it, but it's not necessary, so we add as optional. if ($config->getComponent() == 'rules_config') { $rule_name = $id; $rules_permissions = rules_permission(); $permission = "use Rules component {$rule_name}"; if (isset($rules_permissions[$permission])) { $identifier = str_replace(' ', '_', $permission); $perm = new YafflePermissionConfiguration($identifier); $perm->build(); // Add the Rules component as a dependency of the permission. // NOTE: This isn't working, so we're adding the dependency below. // $perm->addToDependencies($config); // Add the permission as a child configuration of the Rules component. $config->addToOptionalConfigurations($perm); } } // Permissions for Rules components require the component in place first // otherwise we will start seeing errors. if ($config->getComponent() == 'permission' && strpos($id, 'use_Rules_component') !== FALSE) { $rule_name = substr($id, 20); $rules_config = ConfigurationManagement::createConfigurationInstance('rules_config.' . $rule_name); $config->addToDependencies($rules_config); } }
/** * Overrides Drupal\configuration\Config\Configuration::findDependencies(). */ public function findDependencies() { $format = $this->getIdentifier(); $formats = filter_formats(); if (isset($formats[$format])) { $filter_format = ConfigurationManagement::createConfigurationInstance('text_format.' . $format); $this->addToDependencies($filter_format); } parent::findDependencies(); }
/** * Overrides Drupal\configuration\Config\Configuration::alterDependencies(). */ public static function alterDependencies(Configuration $config) { // Dependencies for Page Manager Pages. Each page has a handler. if ($config->getComponent() == 'page_manager_pages' && !$config->broken) { $config_data = $config->getData(); $id = 'page_manager_handlers.page_' . $config_data->name . '_panel_context'; $page_handler = ConfigurationManagement::createConfigurationInstance($id); $page_handler->build(); $config->addToDependencies($page_handler); } }
/** * Overrides Drupal\configuration\Config\Configuration::alterDependencies(). */ public static function alterDependencies(Configuration $config) { if ($config->getComponent() == 'permission') { foreach (node_permissions_get_configured_types() as $type) { foreach (array_keys(node_list_permissions($type)) as $permission) { $data = $config->getData(); if ($permission == $data['permission']) { $content_type = ConfigurationManagement::createConfigurationInstance('content_type.' . $type); $config->addToDependencies($content_type); break; } } } } }
/** * Overrides Drupal\configuration\Config\Configuration::saveToActiveStore(). */ public static function alterDependencies(Configuration $config) { if ($config->getComponent() == 'permission') { $data = $config->getData(); if (!empty($data['roles'])) { $role_objects = db_select('role', 'r')->fields('r', array('machine_name', 'rid'))->condition('name', $data['roles'], 'IN')->execute(); foreach ($role_objects as $role_object) { if ($role_object->rid > 2 && !empty($role_object->machine_name)) { $role_config = ConfigurationManagement::createConfigurationInstance('role.' . $role_object->machine_name); $config->addToDependencies($role_config); } } } } }
/** * Returns TRUE if the current user has write permissions for a configuration * file in the config:// directory. */ public static function checkFilePermissions($filename) { $dir_path = ConfigurationManagement::getStream(); $full_path = $dir_path . '/' . $filename; if (static::checkDirectory($dir_path)) { if (file_exists($full_path)) { if (is_writable($full_path) || drupal_chmod($full_path)) { return TRUE; } else { drupal_set_message(t('The current user does not have permissions to edit the file %file.', array('%file' => $full_path)), 'error'); } } else { return TRUE; } } return FALSE; }
/** * Overrides Drupal\configuration\Config\Configuration::alterDependencies(). */ public static function alterDependencies(Configuration $config) { if ($config->getComponent() == 'permission') { // Generate permissions for each text format. Warn the administrator that any // of them are potentially unsafe. foreach (filter_formats() as $format) { $permission = filter_permission_name($format); if (!empty($permission)) { $data = $config->getData(); if ($permission == $data['permission']) { $text_format = ConfigurationManagement::createConfigurationInstance('text_format.' . $format->format); $config->addToDependencies($text_format); break; } } } } }
/** * Overrides Drupal\configuration\Config\Configuration::alterDependencies(). */ public static function alterDependencies(Configuration $config) { if ($config->getComponent() == 'permission') { $panelizers = static::getAllIdentifiers('panelizer_defaults'); $permission = $config->getData(); if (strpos($permission['permission'], 'administer panelizer ') === 0) { list(, , $entity_type, $bundle) = explode(' ', $permission['permission']); $id = $entity_type . ':' . $bundle; foreach ($panelizers as $panelizer_id) { if (strpos($panelizer_id, $id) === 0) { $panelizer = ConfigurationManagement::createConfigurationInstance('panelizer_defaults.' . $panelizer_id); $panelizer->build(); $config->addToDependencies($panelizer); } } } } }
/** * Overrides Drupal\configuration\Config\Configuration::alterDependencies(). */ public static function alterDependencies(Configuration $config) { static $cache; if (!isset($cache)) { $cache = array(); } // Dependencies for Page Manager Handlers. if ($config->getComponent() == 'page_manager_handlers' && !$config->broken) { // This line seems to be inconsistent when executed from drush or browser. $config_data = $config->getData(); // This alternative works more consistent althoug it's no so pretty. if (!isset($config_data->conf['display'])) { if (!isset($cache[$config->getUniqueId()])) { @eval(ctools_export_crud_export($config->getComponent(), $config_data)); $cache[$config->getUniqueId()] = $handler; } else { $handler = $cache[$config->getUniqueId()]; } $config_data = $handler; } foreach ($config_data->conf['display']->content as $object) { $type = $object->type; switch ($type) { case 'block': list($subtype, $id, ) = explode('-', $object->subtype); switch ($subtype) { // Display block from a view. case 'views': $config_id = 'views_view.' . $id; $view = ConfigurationManagement::createConfigurationInstance($config_id); $view->build(); $config->addToDependencies($view); $config->addToDependencies($view); break; } break; // A view added directly. // A view added directly. case 'views': $config_id = 'views_view.' . $object->subtype; $view = ConfigurationManagement::createConfigurationInstance($config_id); $view->build(); $config->addToDependencies($view); break; // A view added using the Views content panes module. // A view added using the Views content panes module. case 'views_panes': list($subtype, ) = explode('-', $object->subtype); $config_id = 'views_view.' . $subtype; $view = ConfigurationManagement::createConfigurationInstance($config_id); $view->build(); $config->addToDependencies($view); break; } } } }
/** * Loads the configuration object from the DataStore. * * @param $file_content * Optional. The content to load directly. * @param $source * Optional. An optional path to load the configuration. */ public function load($file_content = NULL, $source = NULL) { if (empty($this->loaded)) { $this->loaded = TRUE; if (empty($file_content)) { $dir = $source ? $source : ConfigurationManagement::getStream(); if (!file_exists($dir . '/' . $this->filename)) { $this->data = NULL; } else { $file_content = drupal_substr(file_get_contents($dir . '/' . $this->filename), 6); } } if (!empty($file_content)) { $this->import($file_content); } } return $this; }
/** * This function will exectute a callback function over all the configurations * objects that it process. * * @param ConfigIteratorSettings $settings * A ConfigIteratorSettings instance that specifies, which is the callback * to execute. If dependencies and optional configurations should be * processed too, and storage the cache of already processed configurations. * * @see importToActiveStore() * @see exportToDataStore() * @see revertActiveStore() * @see discoverRequiredModules() */ public function iterate(ConfigIteratorSettings &$settings) { $callback = $settings->getCallback(); $build_callback = $settings->getBuildCallback(); if ($settings->alreadyProcessed($this) || $settings->excluded($this)) { return; } // First proccess requires the dependencies that have to be processed before // load the current configuration. if ($settings->processDependencies()) { foreach ($this->getDependencies() as $dependency => $config_dependency) { // In some callbacks, the dependencies storages the full config object // other simply use a plain string. If the object is available, use // that version. if (is_object($config_dependency)) { $config = $config_dependency; } else { $config = $settings->getFromCache($dependency); if (!$config) { $config = ConfigurationManagement::createConfigurationInstance($dependency); } } $config->setContext($settings); $config->{$build_callback}(); $config->iterate($settings); } } if ($settings->alreadyProcessed($this)) { return; } // Now, after proccess the dependencies, proccess the current configuration. $this->setContext($settings); $this->{$callback}($settings); $settings->addToCache($this); // After proccess the dependencies and the current configuration, proccess // the optionals. if ($settings->processOptionals()) { foreach ($this->getOptionalConfigurations() as $optional => $optional_config) { $config = $settings->getFromCache($optional); // In some callbacks, the optionals storages the full config object // other simply use a plain string. If the object is available, use // that version. if (is_object($optional_config)) { $config = $optional_config; } else { if (!$config) { $config = ConfigurationManagement::createConfigurationInstance($optional); } } $config->setContext($settings); $config->{$build_callback}(); $config->iterate($settings); } } }
/** * Overrides Drupal\configuration\Config\Configuration::findDependencies(). */ public function findDependencies() { list($entity_type, $field_name, $bundle_name) = explode('.', $this->getIdentifier()); $supported_handler = FALSE; if ($entity_type == 'node') { $parent_config = ConfigurationManagement::createConfigurationInstance('content_type.' . $bundle_name); $this->addToDependencies($parent_config); } elseif ($entity_type == 'vocabulary') { $parent_config = ConfigurationManagement::createConfigurationInstance('vocabulary.' . $bundle_name); $this->addToDependencies($parent_config); } parent::findDependencies(); }
/** * Import configurations from a Tar file. * * @param StdClass $file * A file object. * @param boolean $start_tracking * If TRUE, all the configurations provided in the Tar file will be imported * and automatically tracked. * * @return ConfigIteratorSettings * An ConfigIteratorSettings object that contains the imported * configurations. */ public static function importToActiveStoreFromTar($uri, $start_tracking = FALSE) { $path = 'temporary://'; $archive = archiver_get_archiver($uri); $files = $archive->listContents(); foreach ($files as $filename) { if (is_file($path . $filename)) { file_unmanaged_delete($path . $filename); } } $config_temp_path = 'temporary://' . 'config-tmp-' . time(); $archive->extract(drupal_realpath($config_temp_path)); $file_content = drupal_substr(file_get_contents($config_temp_path . '/configuration/configurations.inc'), 6); @eval($file_content); $source = $config_temp_path . '/configuration/'; $modules_results = ConfigurationManagement::discoverRequiredModules($modules); $missing_modules = $modules_results->getInfo('modules_missing'); $error = FALSE; if (!empty($missing_modules)) { drupal_set_message(t('Configurations cannot be synchronized because the following modules are not available to install: %modules', array('%modules' => implode(', ', $missing_modules))), 'error'); return $modules_results; } else { $modules_to_install = $modules_results->getInfo('modules_to_install'); if (!empty($modules_to_install)) { module_enable($modules_to_install, TRUE); drupal_set_message(t('The following modules have been enabled: %modules', array('%modules' => implode(', ', $modules_to_install)))); drupal_flush_all_caches(); } } $settings = static::importToActiveStore($configurations, FALSE, FALSE, $start_tracking, $source); static::deteleTempConfigDir($config_temp_path); return $settings; }