+
+For sandboxed DB you remove this permanent storage, import your database into Writeable Container's memory and create a new Docker Image from your container with `docker commit` command. New image will include Base Image plus all in-memory changes made i.e. your DataBase snapshot. It is then used as a Base Image for your DB container.
+
+:page_facing_up: docker-compose.yml
+```yml
+# DB node
+db:
+ image: mysql_with_my_database:snapshot1
+ volumes:
+ ...
+ # Permanent DB data storage (turned off)
+ # - /var/lib/mysql
+ ```
+
+
+
+Now you can do any changes to database you want but each time after the container is restarted all changes will be lost (as it doesn't have external persistant storage) and you will be back to your Base Image `mysql_with_my_database:snapshot1`.
+
+## Steps
+
+1. Create a DB dump
+2. Stop and remove running containers
+
+ `docker-compose stop && docker-compose rm --force`
+
+3. Comment out the `/var/lib/mysql` volume definition for the **db** service in `docker-compose.yml`
+4. Restart containers
+
+ `docker-compose up -d`
+
+5. Import the DB dump you created in step 1.
+6. Stop and [commit](https://docs.docker.com/reference/commandline/cli/#commit) the **db** service container (this will turn the container into a reusable docker image)
+
+ `docker stop $(docker-compose ps -q db) && docker commit $(docker-compose ps -q db) ' . check_plain($output) . ''; + case 'admin/build/features': + return '
' . t('A "Feature" is a certain type of Drupal module which contains a package of configuration that, when enabled, provides a new set of functionality for your Drupal site. Enable features by selecting the checkboxes below and clicking the Save configuration button. If the configuration of the feature has been changed its "State" will be either "overridden" or "needs review", otherwise it will be "default", indicating that the configuration has not been changed. Click on the state to see more details about the feature and its components.') . '
'; + } +} + +/** + * Implements hook_modules_disabled(). + */ +function features_modules_disabled($modules) { + // Go through all modules and gather features that can be disabled. + $items = array(); + foreach ($modules as $module) { + if ($feature = features_load_feature($module)) { + $items[$module] = array_keys($feature->info['features']); + } + } + + if (!empty($items)) { + _features_restore('disable', $items); + // Rebuild the list of features includes. + features_include(TRUE); + } +} + +/** + * Implements hook_modules_enabled(). + */ +function features_modules_enabled($modules) { + // Allow distributions to disable this behavior and rebuild the features + // manually inside a batch. + if (!variable_get('features_rebuild_on_module_install', TRUE)) { + return; + } + + // mark modules as being changed for test in features_flush_caches + variable_set('features_modules_changed', TRUE); + + // Go through all modules and gather features that can be enabled. + $items = array(); + foreach ($modules as $module) { + if ($feature = features_load_feature($module)) { + $items[$module] = array_keys($feature->info['features']); + } + } + + if (!empty($items)) { + // Need to include any new files. + // @todo Redo function so can take in list of modules to include. + features_include_defaults(NULL, TRUE); + _features_restore('enable', $items); + // Rebuild the list of features includes. + features_include(TRUE); + // Reorders components to match hook order and removes non-existant. + $all_components = array_keys(features_get_components()); + foreach ($items as $module => $components) { + $items[$module] = array_intersect($all_components, $components); + } + _features_restore('rebuild', $items); + } +} + +/** + * Load includes for any modules that implement the features API and + * load includes for those provided by features. + */ +function features_include($reset = FALSE) { + static $once; + if (!isset($once) || $reset) { + $once = TRUE; + + // Features provides integration on behalf of these modules. + // The features include provides handling for the feature dependencies. + // Note that ctools is placed last because it implements hooks "dynamically" for other modules. + $modules = array('features', 'block', 'contact', 'context', 'field', 'filter', 'image', 'locale', 'menu', 'node', 'taxonomy', 'user', 'views', 'ctools'); + + foreach (array_filter($modules, 'module_exists') as $module) { + module_load_include('inc', 'features', "includes/features.$module"); + } + + if (module_exists('ctools')) { + // Finally, add ctools eval'd implementations. + ctools_features_declare_functions($reset); + } + + // Clear static cache, since we've now included new implementers. + foreach (features_get_components(NULL, 'file', $reset) as $file) { + if (is_file(DRUPAL_ROOT . '/' . $file)) { + require_once DRUPAL_ROOT . '/' . $file; + } + } + } +} + +/** + * Load features includes for all components that require includes before + * collecting defaults. + */ +function features_include_defaults($components = NULL, $reset = FALSE) { + static $include_components; + + // Build an array of components that require inclusion: + // Views, CTools components and those using FEATURES_DEFAULTS_INCLUDED. + if (!isset($include_components) || $reset) { + $include_components = features_get_components(); + foreach ($include_components as $component => $info) { + if (!isset($info['api']) && (!isset($info['default_file']) || $info['default_file'] !== FEATURES_DEFAULTS_INCLUDED)) { + unset($include_components[$component]); + } + } + } + + // If components are specified, only include for the specified components. + if (isset($components)) { + $components = is_array($components) ? $components : array($components); + } + // Use all include components if none are explicitly specified. + else { + $components = array_keys($include_components); + } + foreach ($components as $component) { + if (isset($include_components[$component])) { + $info = $include_components[$component]; + // Inclusion of ctools components. + if (isset($info['api'], $info['module'], $info['current_version'])) { + ctools_include('plugins'); + ctools_plugin_api_include($info['module'], $info['api'], $info['current_version'], $info['current_version']); + } + // Inclusion of defaults for components using FEATURES_DEFAULTS_INCLUDED. + else { + $features = isset($features) ? $features : features_get_features(NULL, $reset); + foreach ($features as $feature) { + $filename = isset($info['default_file']) && $info['default_file'] == FEATURES_DEFAULTS_CUSTOM ? $info['default_filename'] : "features.{$component}"; + if (module_exists($feature->name) && isset($feature->info['features'][$component])) { + module_load_include('inc', $feature->name, "{$feature->name}.$filename"); + } + } + } + } + } +} + +/** + * Feature object loader. DEPRECATED but included for backwards compatibility + */ +function feature_load($name, $reset = FALSE) { + return features_load_feature($name, $reset); +} + +/** + * Feature object loader. + */ +function features_load_feature($name, $reset = FALSE) { + // Use an alternative code path during installation, for better performance. + if (variable_get('install_task') != 'done') { + static $features; + + if (!isset($features[$name])) { + // Set defaults for module info. + $defaults = array( + 'dependencies' => array(), + 'description' => '', + 'package' => 'Other', + 'version' => NULL, + 'php' => DRUPAL_MINIMUM_PHP, + 'files' => array(), + 'bootstrap' => 0, + ); + $info = drupal_parse_info_file(drupal_get_path('module', $name) . '/' . $name . '.info'); + + $features[$name] = FALSE; + if (!empty($info['features']) && empty($info['hidden'])) { + // Build a fake file object with the data needed during installation. + $features[$name] = new stdClass; + $features[$name]->name = $name; + $features[$name]->filename = drupal_get_path('module', $name) . '/' . $name . '.module'; + $features[$name]->type = 'module'; + $features[$name]->info = $info + $defaults; + } + } + + return $features[$name]; + } + else { + return features_get_features($name, $reset); + } +} + +/** + * Return a module 'object' including .info information. + * + * @param $name + * The name of the module to retrieve information for. If omitted, + * an array of all available modules will be returned. + * @param $reset + * Whether to reset the cache. + * + * @return + * If a module is request (and exists) a module object is returned. If no + * module is requested info for all modules is returned. + */ +function features_get_modules($name = NULL, $reset = FALSE) { + return features_get_info('module', $name, $reset); +} + +/** + * Returns the array of supported components. + * + * @see hook_features_api + * + * @param $component + * A specific type of component that supports features. + * @param $key + * A key that hook_features_api supports. + * + * @return An array of component labels keyed by the component names. + */ +function features_get_components($component = NULL, $key = NULL, $reset = FALSE) { + features_include(); + $components = &drupal_static(__FUNCTION__); + $component_by_key = &drupal_static(__FUNCTION__ . '_by_key'); + + if ($reset || !isset($components) || !isset($component_by_key)) { + $components = $component_by_key = array(); + if (!$reset && ($cache = cache_get('features_api', 'cache_features'))) { + $components = $cache->data; + } + else { + $components = module_invoke_all('features_api'); + drupal_alter('features_api', $components); + cache_set('features_api', $components, 'cache_features'); + } + + foreach ($components as $component_type => $component_information) { + foreach ($component_information as $component_key => $component_value) { + $component_by_key[$component_key][$component_type] = $component_value; + } + } + } + + if ($key && $component) { + return !empty($components[$component][$key]) ? $components[$component][$key] : NULL; + } + elseif ($key) { + return !empty($component_by_key[$key]) ? $component_by_key[$key] : array(); + } + elseif ($component) { + return $components[$component]; + } + return $components; +} + +/** + * Returns components that are offered as an option on feature creation. + */ +function features_get_feature_components() { + return array_intersect_key(features_get_components(), array_filter(features_get_components(NULL, 'feature_source'))); +} + +/** + * Invoke a component callback. + */ +function features_invoke($component, $callback) { + $args = func_get_args(); + unset($args[0], $args[1]); + // Append the component name to the arguments. + $args[] = $component; + if ($function = features_hook($component, $callback)) { + return call_user_func_array($function, $args); + } +} + +/** + * Checks whether a component implements the given hook. + * + * @return + * The function implementing the hook, or FALSE. + */ +function features_hook($component, $hook, $reset = FALSE) { + // Determine the function callback base. + $base = features_get_components($component, 'base'); + $base = isset($base) ? $base : $component; + return function_exists($base . '_' . $hook) ? $base . '_' . $hook : FALSE; +} + +/** + * Enables and installs an array of modules, ignoring those + * already enabled & installed. Consider this a helper or + * extension to drupal_install_modules(). + * + * @param $modules + * An array of modules to install. + * @param $reset + * Clear the module info cache. + */ +function features_install_modules($modules) { + variable_set('features_modules_changed', TRUE); + + module_load_include('inc', 'features', 'features.export'); + $files = system_rebuild_module_data(); + + // Build maximal list of dependencies. + $install = array(); + foreach ($modules as $name) { + // Parse the dependency string into the module name and version information. + $parsed_name = drupal_parse_dependency($name); + $name = $parsed_name['name']; + if ($file = $files[$name]) { + $install[] = $name; + if (!empty($file->info['dependencies'])) { + $install = array_merge($install, _features_export_maximize_dependencies($file->info['dependencies'])); + } + } + } + + // Filter out enabled modules. + $enabled = array_filter($install, 'module_exists'); + $install = array_diff($install, $enabled); + + if (!empty($install)) { + // Make sure the install API is available. + $install = array_unique($install); + include_once DRUPAL_ROOT . '/' . './includes/install.inc'; + module_enable($install); + } +} + +/** + * Wrapper around features_get_info() that returns an array + * of module info objects that are features. + */ +function features_get_features($name = NULL, $reset = FALSE) { + return features_get_info('feature', $name, $reset); +} + +/** + * Helper for retrieving info from system table. + */ +function features_get_info($type = 'module', $name = NULL, $reset = FALSE) { + static $cache; + if (!isset($cache)) { + $cache = cache_get('features_module_info', 'cache_features'); + } + if (empty($cache) || $reset) { + $data = array( + 'feature' => array(), + 'module' => array(), + ); + $ignored = variable_get('features_ignored_orphans', array()); + $files = system_rebuild_module_data(); + + foreach ($files as $row) { + // Remove modification timestamp, added in Drupal 7.33. + if (isset($row->info['mtime'])) { + unset($row->info['mtime']); + } + // Avoid false-reported feature overrides for php = 5.2.4 line in .info file. + if (isset($row->info['php'])) { + unset($row->info['php']); + } + // If module is no longer enabled, remove it from the ignored orphans list. + if (in_array($row->name, $ignored, TRUE) && !$row->status) { + $key = array_search($row->name, $ignored, TRUE); + unset($ignored[$key]); + } + + if (!empty($row->info['features'])) { + // Fix css/js paths + if (!empty($row->info['stylesheets'])) { + foreach ($row->info['stylesheets'] as $media => $css) { + $row->info['stylesheets'][$media] = array_keys($css); + } + } + if (!empty($row->info['scripts'])) { + $row->info['scripts'] = array_keys($row->info['scripts']); + } + // Rework the features array, to change the vocabulary permission + // features. + foreach ($row->info['features'] as $component => $features) { + if ($component == 'user_permission') { + foreach ($features as $key => $feature) { + // Export vocabulary permissions using the machine name, instead + // of vocabulary id. + _user_features_change_term_permission($feature); + $row->info['features'][$component][$key] = $feature; + } + } + } + $data['feature'][$row->name] = $row; + $data['feature'][$row->name]->components = array_keys($row->info['features']); + if (!empty($row->info['dependencies'])) { + $data['feature'][$row->name]->components[] = 'dependencies'; + } + } + $data['module'][$row->name] = $row; + } + + // Sort features according to dependencies. + // @see install_profile_modules() + $required = array(); + $non_required = array(); + + $modules = array_keys($data['feature']); + foreach ($modules as $module) { + if ($files[$module]->requires) { + $modules = array_merge($modules, array_keys($files[$module]->requires)); + } + } + $modules = array_unique($modules); + foreach ($modules as $module) { + if (!empty($files[$module]->info['features'])) { + if (!empty($files[$module]->info['required'])) { + $required[$module] = $files[$module]->sort; + } + else { + $non_required[$module] = $files[$module]->sort; + } + } + } + arsort($required); + arsort($non_required); + + $sorted = array(); + foreach ($required + $non_required as $module => $weight) { + $sorted[$module] = $data['feature'][$module]; + } + $data['feature'] = $sorted; + + variable_set('features_ignored_orphans', $ignored); + cache_set('features_module_info', $data, 'cache_features'); + $cache = new stdClass(); + $cache->data = $data; + } + if (!empty($name)) { + return !empty($cache->data[$type][$name]) ? clone $cache->data[$type][$name] : FALSE; + } + return !empty($cache->data[$type]) ? $cache->data[$type] : FALSE; +} + +/** + * Generate an array of feature dependencies that have been orphaned. + */ +function features_get_orphans($reset = FALSE) { + static $orphans; + if (!isset($orphans) || $reset) { + module_load_include('inc', 'features', 'features.export'); + $orphans = array(); + + // Build a list of all dependencies for enabled and disabled features. + $dependencies = array('enabled' => array(), 'disabled' => array()); + $features = features_get_features(); + foreach ($features as $feature) { + $key = module_exists($feature->name) ? 'enabled' : 'disabled'; + if (!empty($feature->info['dependencies'])) { + $dependencies[$key] = array_merge($dependencies[$key], _features_export_maximize_dependencies($feature->info['dependencies'])); + } + } + $dependencies['enabled'] = array_unique($dependencies['enabled']); + $dependencies['disabled'] = array_unique($dependencies['disabled']); + + // Find the list of orphaned modules. + $orphaned = array_diff($dependencies['disabled'], $dependencies['enabled']); + $orphaned = array_intersect($orphaned, module_list(FALSE, FALSE)); + $orphaned = array_diff($orphaned, drupal_required_modules()); + $orphaned = array_diff($orphaned, array('features')); + + // Build final list of modules that can be disabled. + $modules = features_get_modules(NULL, TRUE); + $enabled = module_list(); + _module_build_dependencies($modules); + + foreach ($orphaned as $module) { + if (!empty($modules[$module]->required_by)) { + foreach ($modules[$module]->required_by as $module_name => $dependency) { + $modules[$module]->required_by[$module_name] = $dependency['name']; + } + // Determine whether any dependents are actually enabled. + $dependents = array_intersect($modules[$module]->required_by, $enabled); + if (empty($dependents)) { + $info = features_get_modules($module); + $orphans[$module] = $info; + } + } + } + } + return $orphans; +} + +/** + * Detect potential conflicts between any features that provide + * identical components. + */ +function features_get_conflicts($reset = FALSE) { + $conflicts = array(); + $component_info = features_get_components(); + $map = features_get_component_map(NULL, $reset); + + foreach ($map as $type => $components) { + // Only check conflicts for components we know about. + if (isset($component_info[$type])) { + foreach ($components as $component => $modules) { + if (isset($component_info[$type]['duplicates']) && $component_info[$type]['duplicates'] == FEATURES_DUPLICATES_ALLOWED) { + continue; + } + elseif (count($modules) > 1) { + foreach ($modules as $module) { + if (!isset($conflicts[$module])) { + $conflicts[$module] = array(); + } + foreach ($modules as $m) { + if ($m != $module) { + $conflicts[$module][$m][$type][] = $component; + } + } + } + } + } + } + } + + return $conflicts; +} + +/** + * Provide a component to feature map. + */ +function features_get_component_map($key = NULL, $reset = FALSE) { + static $map; + if (!isset($map) || $reset) { + $map = array(); + $features = features_get_features(NULL, $reset); + foreach ($features as $feature) { + foreach ($feature->info['features'] as $type => $components) { + if (!isset($map[$type])) { + $map[$type] = array(); + } + foreach ($components as $component) { + $map[$type][$component][] = $feature->name; + } + } + } + } + if (isset($key)) { + return isset($map[$key]) ? $map[$key] : array(); + } + return $map; +} + +/** + * Simple wrapper returns the status of a module. + */ +function features_get_module_status($module) { + if (module_exists($module)) { + return FEATURES_MODULE_ENABLED; + } + elseif (features_get_modules($module)) { + return FEATURES_MODULE_DISABLED; + } + else { + return FEATURES_MODULE_MISSING; + } +} + +/** + * Menu title callback. + */ +function features_get_feature_title($feature) { + return $feature->info['name']; +} + +/** + * Menu access callback for whether a user should be able to access + * override actions for a given feature. + */ +function features_access_override_actions($feature) { + if (user_access('administer features')) { + static $access = array(); + if (!isset($access[$feature->name])) { + // Set a value first. We may get called again from within features_detect_overrides(). + $access[$feature->name] = FALSE; + + features_include(); + module_load_include('inc', 'features', 'features.export'); + $access[$feature->name] = in_array(features_get_storage($feature->name), array(FEATURES_OVERRIDDEN, FEATURES_NEEDS_REVIEW)) && user_access('administer features'); + } + return $access[$feature->name]; + } + return FALSE; +} + +/** + * Implements hook_form_alter() for system_modules form(). + */ +function features_form_system_modules_alter(&$form) { + features_rebuild(); +} + +/** + * Restore the specified modules to the default state. + */ +function _features_restore($op, $items = array()) { + $lockable = FALSE; + // Set this variable in $conf if having timeout issues during install/rebuild. + if (variable_get('features_restore_time_limit_' . $op, FALSE) !== FALSE) { + drupal_set_time_limit(variable_get('features_restore_time_limit_' . $op, FALSE)); + } + + module_load_include('inc', 'features', 'features.export'); + features_include(); + + switch ($op) { + case 'revert': + $restore_states = array(FEATURES_OVERRIDDEN, FEATURES_REBUILDABLE, FEATURES_NEEDS_REVIEW); + $restore_hook = 'features_revert'; + $log_action = 'Revert'; + $lockable = TRUE; + break; + case 'rebuild': + $restore_states = array(FEATURES_REBUILDABLE); + $restore_hook = 'features_rebuild'; + $log_action = 'Rebuild'; + $lockable = variable_get('features_lock_mode', 'all') == 'all'; + break; + case 'disable': + $restore_hook = 'features_disable_feature'; + $log_action = 'Disable'; + break; + case 'enable': + $restore_hook = 'features_enable_feature'; + $log_action = 'Enable'; + break; + } + + if (empty($items)) { + // Drush may execute a whole chain of commands that may trigger feature + // rebuilding multiple times during a single request. Make sure we do not + // rebuild the same cached list of modules over and over again by setting + // $reset to TRUE. + // Note: this may happen whenever more than one feature will be enabled + // in chain, for example also using features_install_modules(). + $states = features_get_component_states(array(), ($op == 'rebuild'), defined('DRUSH_BASE_PATH')); + foreach ($states as $module_name => $components) { + foreach ($components as $component => $state) { + if (in_array($state, $restore_states)) { + $items[$module_name][] = $component; + } + } + } + } + + // Invoke global pre restore hook. + module_invoke_all('features_pre_restore', $op, $items); + foreach ($items as $module_name => $components) { + // If feature is totally locked, do not execute past this stage. + if ($lockable && features_feature_is_locked($module_name)) { + watchdog('features', 'Tried @actioning a locked @module_name, aborted.', array('@action' => $log_action, '@module_name' => $module_name)); + continue; + } + foreach ($components as $component) { + // If feature is totally locked, do not execute past this stage. + if ($lockable && features_feature_is_locked($module_name, $component)) { + watchdog('features', 'Tried @actioning a locked @module_name / @component, aborted.', array('@action' => $log_action, '@component' => $component, '@module_name' => $module_name)); + continue; + } + // Invoke pre hook + $pre_hook = 'pre_' . $restore_hook; + module_invoke($module_name, $pre_hook, $component); + + if (features_hook($component, $restore_hook)) { + // Set a semaphore to prevent other instances of the same script from running concurrently. + watchdog('features', '@actioning @module_name / @component.', array('@action' => $log_action, '@component' => $component, '@module_name' => $module_name)); + features_semaphore('set', $component); + features_invoke($component, $restore_hook, $module_name); + + // If the script completes, remove the semaphore and set the code signature. + features_semaphore('del', $component); + features_set_signature($module_name, $component); + watchdog('features', '@action completed for @module_name / @component.', array('@action' => $log_action, '@component' => $component, '@module_name' => $module_name)); + } + + // Invoke post hook + $post_hook = 'post_' . $restore_hook; + module_invoke($module_name, $post_hook, $component); + } + } + // Invoke global post restore hook. + module_invoke_all('features_post_restore', $op, $items); +} + +/** + * Wrapper around _features_restore(). + */ +function features_revert($revert = array()) { + return _features_restore('revert', $revert); +} + +/** + * Wrapper around _features_restore(). + */ +function features_rebuild($rebuild = array()) { + return _features_restore('rebuild', $rebuild); +} + +/** + * Revert a single features module. + * + * @param string $module + * A features module machine name. This module must be a + * features module and enabled. + */ +function features_revert_module($module) { + if (($feature = feature_load($module, TRUE)) && module_exists($module)) { + $components = array(); + foreach (array_keys($feature->info['features']) as $component) { + if (features_hook($component, 'features_revert')) { + $components[] = $component; + } + } + features_revert(array($module => $components)); + } +} + +/** + * Utility functions ================================================== + */ + +/** + * Log a message, environment agnostic. + * + * @param $message + * The message to log. + * @param $severity + * The severity of the message: status, warning or error. + */ +function features_log($message, $severity = 'status') { + if (function_exists('drush_verify_cli')) { + $message = strip_tags($message); + if ($severity == 'status') { + $severity = 'ok'; + } + elseif ($severity == 'error') { + drush_set_error($message); + return; + } + drush_log($message, $severity); + return; + } + drupal_set_message($message, $severity, FALSE); +} + +/** + * Implements hook_hook_info(). + */ +function features_hook_info() { + $hooks = array( + 'features_api', + 'features_pipe_alter', + 'features_export_alter', + 'features_export_options_alter', + ); + return array_fill_keys($hooks, array('group' => 'features')); +} + +/** + * Change vocabularies permission, from vocab id to machine name and vice versa. + */ +function _user_features_change_term_permission(&$perm, $type = 'vid') { + if (!module_exists('taxonomy')) { + return; + } + // Export vocabulary permissions using the machine name, instead of vocabulary + // id. + if (strpos($perm, 'edit terms in ') !== FALSE || strpos($perm, 'delete terms in ') !== FALSE) { + preg_match("/(?<=\040)([^\s]+?)$/", trim($perm), $voc_id); + $vid = $voc_id[0]; + if (is_numeric($vid) && $type == 'vid') { + if (function_exists('taxonomy_vocabulary_load')) { + if ($voc = taxonomy_vocabulary_load($vid)) { + $perm = str_replace($vid, $voc->machine_name, $perm); + } + } + } + elseif ($type == 'machine_name') { + if ($voc = taxonomy_vocabulary_machine_name_load($vid)) { + $perm = str_replace($vid, $voc->vid, $perm); + } + } + } +} + +/** + * Recursively computes the difference of arrays with additional index check. + * + * This is a version of array_diff_assoc() that supports multidimensional + * arrays. + * + * @param array $array1 + * The array to compare from. + * @param array $array2 + * The array to compare to. + * + * @return array + * Returns an array containing all the values from array1 that are not present + * in array2. + */ +function features_array_diff_assoc_recursive(array $array1, array $array2) { + $difference = array(); + foreach ($array1 as $key => $value) { + if (is_array($value)) { + if (!isset($array2[$key]) || !is_array($array2[$key])) { + $difference[$key] = $value; + } + else { + $new_diff = features_array_diff_assoc_recursive($value, $array2[$key]); + if (!empty($new_diff)) { + $difference[$key] = $new_diff; + } + } + } + elseif (!isset($array2[$key]) || $array2[$key] != $value) { + $difference[$key] = $value; + } + } + return $difference; +} + +/** + * Returns an array of deprecated components + * Rather than deprecating the component directly, we look for other components + * that supersedes the component + * @param $components + * The array of components (component_info) from features_get_components typically. + */ +function features_get_deprecated($components = array()) { + if (empty($components)) { + $components = features_get_components(); + } + $deprecated = array(); + foreach ($components as $component => $component_info) { + if (!empty($component_info['supersedes'])) { + $deprecated[$component_info['supersedes']] = $component_info['supersedes']; + } + } + return $deprecated; +} + +/** + * Returns whether a feature or it's component is locked. + */ +function features_feature_is_locked($feature, $component = NULL, $check_global_component_setting = TRUE) { + $locked = variable_get('features_feature_locked', array()); + if ($component) { + return ($check_global_component_setting && features_component_is_locked($component)) || !empty($locked[$feature][$component]); + } + else { + return !empty($locked[$feature]['_all']); + } +} + +/** + * Returns whether a component is locked. + */ +function features_component_is_locked($component) { + return variable_get('features_component_locked_' . $component, FALSE); +} + +/** + * Locks a feature or it's component. + */ +function features_feature_lock($feature, $component = NULL) { + $locked = variable_get('features_feature_locked', array()); + $locked[$feature] = !empty($locked[$feature]) ? $locked[$feature] : array(); + if ($component) { + $locked[$feature][$component] = TRUE; + } + else { + $locked[$feature]['_all'] = TRUE; + } + variable_set('features_feature_locked', $locked); +} + +/** + * Unlocks a feature or it's component. + */ +function features_feature_unlock($feature, $component = NULL) { + $locked = variable_get('features_feature_locked', array()); + if ($component) { + unset($locked[$feature][$component]); + } + else { + unset($locked[$feature]['_all']); + } + variable_set('features_feature_locked', $locked); +} + +/** + * Sets the current language to english to ensure a proper export. + */ +function _features_set_export_language() { + // Ensure this is only done if the language isn't already en. + // This can be called multiple times - ensure the handling is done just once. + if ($GLOBALS['language']->language != 'en' && !drupal_static(__FUNCTION__)) { + // Create the language object as language_default() does. + $GLOBALS['language'] = (object) array( + 'language' => 'en', + 'name' => 'English', + 'native' => 'English', + 'direction' => 0, + 'enabled' => 1, + 'plurals' => 0, + 'formula' => '', + 'domain' => '', + 'prefix' => '', + 'weight' => 0, + 'javascript' => '', + ); + // Ensure that static caches are cleared, as they might contain language + // specific information. But keep some important ones. The call below + // accesses a non existing key and requests to reset it. In such cases the + // whole caching data array is returned. + $static = drupal_static(uniqid('', TRUE), NULL, TRUE); + drupal_static_reset(); + // Restore some of the language independent, runtime state information to + // keep everything working and avoid unnecessary double processing. + $static_caches_to_keep = array( + 'conf_path', + 'system_list', + 'ip_address', + 'drupal_page_is_cacheable', + 'list_themes', + 'drupal_page_header', + 'drupal_send_headers', + 'drupal_http_headers', + 'language_list', + 'module_implements', + 'drupal_alter', + 'path_is_admin', + 'path_get_admin_paths', + 'drupal_match_path', + 'menu_get_custom_theme', + 'menu_get_item', + 'arg', + 'drupal_system_listing', + 'drupal_parse_info_file', + 'libraries_get_path', + 'module_hook_info', + 'drupal_add_js', + 'drupal_add_js:jquery_added', + 'drupal_add_library', + 'drupal_get_library', + 'drupal_add_css', + 'menu_set_active_trail', + 'menu_link_get_preferred', + 'menu_set_active_menu_names', + 'theme_get_registry', + 'features_get_components', + 'features_get_components_by_key', + ); + foreach ($static_caches_to_keep as $cid) { + if (isset($static[$cid])) { + $data = &drupal_static($cid); + $data = $static[$cid]; + } + } + $called = &drupal_static(__FUNCTION__); + $called = TRUE; + } +} + +/** + * Implements hook_features_ignore(). + */ +function features_features_ignore($component) { + // Determine which keys need to be ignored for override diff for various components. + // Value is how many levels deep the key is. + $ignores = array(); + switch ($component) { + case 'views_view': + $ignores['current_display'] = 0; + $ignores['display_handler'] = 0; + $ignores['handler'] = 2; + $ignores['query'] = 0; + $ignores['localization_plugin'] = 0; + // Views automatically adds these two on export to set values. + $ignores['api_version'] = 0; + $ignores['disabled'] = 0; + break; + case 'image': + $ignores['module'] = 0; + $ignores['name'] = 0; + $ignores['storage'] = 0; + // Various properties are loaded into the effect in image_styles. + $ignores['summary theme'] = 2; + $ignores['module'] = 2; + $ignores['label'] = 2; + $ignores['help'] = 2; + $ignores['form callback'] = 2; + $ignores['effect callback'] = 2; + $ignores['dimensions callback'] = 2; + break; + case 'field': + $ignores['locked'] = 1; + break; + case 'field_base': + $ignores['indexes'] = 0; + break; + } + return $ignores; +} diff --git a/docroot/sites/all/modules/features/includes/features.block.inc b/docroot/sites/all/modules/features/includes/features.block.inc new file mode 100644 index 0000000..3d0db3b --- /dev/null +++ b/docroot/sites/all/modules/features/includes/features.block.inc @@ -0,0 +1,40 @@ + array( + 'name' => t('Contact categories'), + 'feature_source' => TRUE, + 'default_hook' => 'contact_categories_defaults', + 'default_file' => FEATURES_DEFAULTS_INCLUDED, + ), + ); +} + +/** + * Implements hook_features_export_options(). + */ +function contact_categories_features_export_options() { + $options = array(); + $categories = db_select('contact', 'c')->fields('c')->execute()->fetchAll(); + foreach ($categories as $category) { + $options["$category->category"] = "$category->category"; + } + return $options; +} + +/** + * Implements hook_features_export(). + */ +function contact_categories_features_export($data, &$export, $module_name = '') { + $export['dependencies']['features'] = 'features'; + $export['dependencies']['contact'] = 'contact'; + + foreach ($data as $name) { + $export['features']['contact_categories'][$name] = $name; + } + + return array(); +} + +/** + * Implements hook_features_export_render(). + */ +function contact_categories_features_export_render($module, $data, $export = NULL) { + $render = array(); + foreach ($data as $name) { + $export_category = db_select('contact', 'c') + ->fields('c', array('cid', 'category')) + ->condition('category', $name, 'LIKE') + ->execute() + ->fetchAll(); + if (isset($export_category[0]->cid) && ($category = contact_load($export_category[0]->cid))) { + unset($category['cid']); + $render[$name] = $category; + } + } + return array('contact_categories_defaults' => ' return ' . features_var_export($render, ' ') . ';'); +} + +/** + * Implements hook_features_revert(). + */ +function contact_categories_features_revert($module) { + return contact_categories_features_rebuild($module); +} + +/** + * Implements hook_features_rebuild(). + */ +function contact_categories_features_rebuild($module) { + if ($defaults = features_get_default('contact_categories', $module)) { + foreach ($defaults as $default_category) { + $existing_categories = db_select('contact', 'c') + ->fields('c', array('cid', 'category')) + ->execute() + ->fetchAll(); + if ($existing_categories) { + foreach ($existing_categories as $existing_category) { + if ($default_category['category'] == $existing_category->category) { + db_update('contact') + ->fields( + array( + 'recipients' => $default_category['recipients'], + 'reply' => $default_category['reply'], + 'weight' => $default_category['weight'], + 'selected' => $default_category['selected'], + ) + ) + ->condition('category', $existing_category->category, '=') + ->execute(); + } + else { + db_merge('contact') + ->key(array('category' => $default_category['category'])) + ->fields($default_category) + ->execute(); + } + } + } + else { + db_merge('contact') + ->key(array('category' => $default_category['category'])) + ->fields($default_category) + ->execute(); + } + } + } +} diff --git a/docroot/sites/all/modules/features/includes/features.context.inc b/docroot/sites/all/modules/features/includes/features.context.inc new file mode 100644 index 0000000..2da59a7 --- /dev/null +++ b/docroot/sites/all/modules/features/includes/features.context.inc @@ -0,0 +1,54 @@ +conditions{$key}['values'])) { + foreach ($context->conditions{$key}['values'] as $item) { + // Special pipe for views + if ($key === 'views') { + $split = explode(':', $item); + $view_name = array_shift($split); + $pipe[$key][$view_name] = $view_name; + } + else { + $pipe[$key][$item] = $item; + } + } + } + } + // Reactions. + if (!empty($context->reactions['block']['blocks'])) { + foreach ($context->reactions['block']['blocks'] as $block) { + $block = (array) $block; + $bid = "{$block['module']}-{$block['delta']}"; + $pipe['block'][$bid] = $bid; + } + } + } + } + return $pipe; +} + +/** + * Implements hook_features_revert(). + * + * @param $module + * name of module to revert content for + */ +function context_features_revert($module = NULL) { + $return = ctools_component_features_revert('context', $module); + context_invalidate_cache(); + return $return; +} diff --git a/docroot/sites/all/modules/features/includes/features.ctools.inc b/docroot/sites/all/modules/features/includes/features.ctools.inc new file mode 100644 index 0000000..387cece --- /dev/null +++ b/docroot/sites/all/modules/features/includes/features.ctools.inc @@ -0,0 +1,378 @@ + $info) { + $code = ''; + if (!function_exists("{$info['module']}_features_api")) { + $code .= 'function '. $info['module'] .'_features_api() { return ctools_component_features_api("'. $info['module'] .'"); }'; + } + + // ctools component with owner defined as "ctools" + if (!function_exists("{$component}_features_api") && $info['module'] === 'ctools') { + $code .= 'function '. $component .'_features_api() { return ctools_component_features_api("'. $component .'"); }'; + } + + if (!function_exists("{$component}_features_export")) { + $code .= 'function '. $component .'_features_export($data, &$export, $module_name = "") { return ctools_component_features_export("'. $component .'", $data, $export, $module_name); }'; + } + if (!function_exists("{$component}_features_export_options")) { + $code .= 'function '. $component .'_features_export_options() { return ctools_component_features_export_options("'. $component .'"); }'; + } + if (!function_exists("{$component}_features_export_render")) { + $code .= 'function '. $component .'_features_export_render($module, $data, $export = NULL) { return ctools_component_features_export_render("'. $component .'", $module, $data, $export); }'; + } + if (!function_exists("{$component}_features_revert")) { + $code .= 'function '. $component .'_features_revert($module) { return ctools_component_features_revert("'. $component .'", $module); }'; + } + eval($code); + } + } +} + +/** + * Implements hook_features_api(). + */ +function ctools_features_api() { + return array( + 'ctools' => array( + 'name' => 'CTools export API', + 'feature_source' => TRUE, + 'duplicates' => FEATURES_DUPLICATES_ALLOWED, + // CTools API integration does not include a default hook declaration as + // it is not a proper default hook. + // 'default_hook' => 'ctools_plugin_api', + ), + ); +} + +/** + * Implements hook_features_export(). + * Adds references to the ctools mothership hook, ctools_plugin_api(). + */ +function ctools_features_export($data, &$export, $module_name = '') { + // Add ctools dependency + $export['dependencies']['ctools'] = 'ctools'; + + // Add the actual ctools components which will need to be accounted for in + // hook_ctools_plugin_api(). The components are actually identified by a + // delimited list of values: `module_name:api:current_version` + foreach ($data as $component) { + if ($info = _ctools_features_get_info($component)) { + $identifier = "{$info['module']}:{$info['api']}:{$info['current_version']}"; + $export['features']['ctools'][$identifier] = $identifier; + } + } + + return array(); +} + +/** + * Implements hook_features_export_render(). + * Adds the ctools mothership hook, ctools_plugin_api(). + */ +function ctools_features_export_render($module, $data) { + $component_exports = array(); + foreach ($data as $component) { + $code = array(); + if ($info = _ctools_features_get_info($component)) { + // For background on why we change the output for hook_views_api() + // see http://drupal.org/node/1459120. + if ($info['module'] == 'views') { + $code[] = ' return array("api" => "3.0");'; + } + else { + $code[] = ' if ($module == "'. $info['module'] .'" && $api == "'. $info['api'] .'") {'; + $code[] = ' return array("version" => "'. $info['current_version'] .'");'; + $code[] = ' }'; + } + } + ctools_include('plugins'); + $plugin_api_hook_name = ctools_plugin_api_get_hook($info['module'], $info['api']); + + if (key_exists($plugin_api_hook_name, $component_exports)) { + $component_exports[$plugin_api_hook_name]['code'] .= "\n" . implode("\n", $code); + } + else { + $component_exports[$plugin_api_hook_name] = array( + 'code' => implode("\n", $code), + 'args' => '$module = NULL, $api = NULL', + ); + } + } + + return $component_exports; + +} + +/** + * Master implementation of hook_features_api() for all ctools components. + * + * Note that this master hook does not use $component like the others, but uses the + * component module's namespace instead. + */ +function ctools_component_features_api($module_name) { + $api = array(); + foreach (_ctools_features_get_info() as $component => $info) { + // if module owner is set to "ctools" we need to compare the component + if ($info['module'] == $module_name || ($info['module'] === 'ctools' && $component == $module_name) ) { + $api[$component] = $info; + } + } + return $api; +} + +/** + * Master implementation of hook_features_export_options() for all ctools components. + */ +function ctools_component_features_export_options($component) { + $options = array(); + + ctools_include('export'); + $schema = ctools_export_get_schema($component); + if ($schema && $schema['export']['bulk export']) { + if (!empty($schema['export']['list callback']) && function_exists($schema['export']['list callback'])) { + $options = $schema['export']['list callback'](); + } + else { + $options = _ctools_features_export_default_list($component, $schema); + } + } + asort($options); + return $options; +} + +/** + * Master implementation of hook_features_export() for all ctools components. + */ +function ctools_component_features_export($component, $data, &$export, $module_name = '') { + // Add the actual implementing module as a dependency + $info = _ctools_features_get_info(); + if ($module_name !== $info[$component]['module']) { + $export['dependencies'][$info[$component]['module']] = $info[$component]['module']; + } + + // Add the components + foreach ($data as $object_name) { + if ($object = _ctools_features_export_crud_load($component, $object_name)) { + // If this object is provided as a default by a different module, don't + // export and add that module as a dependency instead. + if (!empty($object->export_module) && $object->export_module !== $module_name) { + $export['dependencies'][$object->export_module] = $object->export_module; + if (isset($export['features'][$component][$object_name])) { + unset($export['features'][$component][$object_name]); + } + } + // Otherwise, add the component. + else { + $export['features'][$component][$object_name] = $object_name; + } + } + } + + // Let CTools handle API integration for this component. + return array('ctools' => array($component)); +} + +/** + * Master implementation of hook_features_export_render() for all ctools components. + */ +function ctools_component_features_export_render($component, $module, $data) { + // Reset the export display static to prevent clashes. + drupal_static_reset('panels_export_display'); + + ctools_include('export'); + $schema = ctools_export_get_schema($component); + + if (function_exists($schema['export']['to hook code callback'])) { + $export = $schema['export']['to hook code callback']($data, $module); + $code = explode("{\n", $export); + array_shift($code); + $code = explode('}', implode($code, "{\n")); + array_pop($code); + $code = implode('}', $code); + } + else { + $code = ' $export = array();'."\n\n"; + foreach ($data as $object_name) { + if ($object = _ctools_features_export_crud_load($component, $object_name)) { + $identifier = $schema['export']['identifier']; + $code .= _ctools_features_export_crud_export($component, $object, ' '); + $code .= " \$export[" . ctools_var_export($object_name) . "] = \${$identifier};\n\n"; + } + } + $code .= ' return $export;'; + } + + return array($schema['export']['default hook'] => $code); +} + +/** + * Master implementation of hook_features_revert() for all ctools components. + */ +function ctools_component_features_revert($component, $module) { + if ($objects = features_get_default($component, $module)) { + foreach ($objects as $name => $object) { + // Some things (like views) do not use the machine name as key + // and need to be loaded explicitly in order to be deleted. + $object = ctools_export_crud_load($component, $name); + if ($object && ($object->export_type & EXPORT_IN_DATABASE)) { + _ctools_features_export_crud_delete($component, $object); + } + } + } +} + +/** + * Helper function to return various ctools information for components. + */ +function _ctools_features_get_info($identifier = NULL, $reset = FALSE) { + static $components; + if (!isset($components) || $reset) { + $components = array(); + $modules = features_get_info(); + ctools_include('export'); + drupal_static('ctools_export_get_schemas', NULL, $reset); + foreach (ctools_export_get_schemas_by_module() as $module => $schemas) { + foreach ($schemas as $table => $schema) { + if ($schema['export']['bulk export']) { + // Let the API owner take precedence as the owning module. + $api_module = isset($schema['export']['api']['owner']) ? $schema['export']['api']['owner'] : $module; + $components[$table] = array( + 'name' => isset($modules[$api_module]->info['name']) ? $modules[$api_module]->info['name'] : $api_module, + 'default_hook' => $schema['export']['default hook'], + 'default_file' => FEATURES_DEFAULTS_CUSTOM, + 'module' => $api_module, + 'feature_source' => TRUE, + ); + if (isset($schema['export']['api'])) { + $components[$table] += array( + 'api' => $schema['export']['api']['api'], + 'default_filename' => $schema['export']['api']['api'], + 'current_version' => $schema['export']['api']['current_version'], + ); + } + } + } + } + } + + // Return information specific to a particular component. + if (isset($identifier)) { + // Identified by the table name. + if (isset($components[$identifier])) { + return $components[$identifier]; + } + // New API identifier. Allows non-exportables related CTools APIs to be + // supported by an explicit `module:api:current_version` key. + else if (substr_count($identifier, ':') === 2) { + list($module, $api, $current_version) = explode(':', $identifier); + // If a schema component matches the provided identifier, provide that + // information. This also ensures that the version number is up to date. + foreach ($components as $table => $info) { + if ($info['module'] == $module && $info['api'] == $api && $info['current_version'] >= $current_version) { + return $info; + } + } + // Fallback to just giving back what was provided to us. + return array('module' => $module, 'api' => $api, 'current_version' => $current_version); + } + return FALSE; + } + + return $components; +} + +/** + * Wrapper around ctools_export_crud_export() for < 1.7 compatibility. + */ +function _ctools_features_export_crud_export($table, $object, $indent = '') { + return ctools_api_version('1.7') ? ctools_export_crud_export($table, $object, $indent) : ctools_export_object($table, $object, $indent); +} + +/** + * Wrapper around ctools_export_crud_load() for < 1.7 compatibility. + */ +function _ctools_features_export_crud_load($table, $name) { + if (ctools_api_version('1.7')) { + return ctools_export_crud_load($table, $name); + } + elseif ($objects = ctools_export_load_object($table, 'names', array($name))) { + return array_shift($objects); + } + return FALSE; +} + +/** + * Wrapper around ctools_export_default_list() for < 1.7 compatibility. + */ +function _ctools_features_export_default_list($table, $schema) { + if (ctools_api_version('1.7')) { + return ctools_export_default_list($table, $schema); + } + elseif ($objects = ctools_export_load_object($table, 'all')) { + return drupal_map_assoc(array_keys($objects)); + } + return array(); +} + +/** + * Wrapper around ctools_export_crud_delete() for < 1.7 compatibility. + */ +function _ctools_features_export_crud_delete($table, $object) { + if (ctools_api_version('1.7')) { + ctools_export_crud_delete($table, $object); + } + else { + $schema = ctools_export_get_schema($table); + $export = $schema['export']; + db_query("DELETE FROM {{$table}} WHERE {$export['key']} = '%s'", $object->{$export['key']}); + } +} + +/** + * Implements hook_features_export_render() for page_manager. + */ +function page_manager_pages_features_export_render($module, $data) { + // Reset the export display static to prevent clashes. + drupal_static_reset('panels_export_display'); + + // Ensure that handlers have their code included before exporting. + page_manager_get_tasks(); + return ctools_component_features_export_render('page_manager_pages', $module, $data); +} + +/** + * Implements hook_features_revert() for page_manager. + */ +function page_manager_pages_features_revert($module) { + if ($pages = features_get_default('page_manager_pages', $module)) { + require_once drupal_get_path('module', 'ctools') . '/page_manager/plugins/tasks/page.inc'; + foreach ($pages as $page) { + page_manager_page_delete($page); + } + } +} + +/** + * Implements hook_features_pipe_COMPONENT_alter() for views_view. + */ +function views_features_pipe_views_view_alter(&$pipe, $data, $export) { + // @todo Remove this check before next stable release. + if (!function_exists('views_plugin_list')) { + return; + } + + $map = array_flip($data); + foreach (views_plugin_list() as $plugin) { + foreach ($plugin['views'] as $view_name) { + if (isset($map[$view_name])) { + $pipe['dependencies'][$plugin['module']] = $plugin['module']; + } + } + } +} diff --git a/docroot/sites/all/modules/features/includes/features.features.inc b/docroot/sites/all/modules/features/includes/features.features.inc new file mode 100644 index 0000000..c657bc8 --- /dev/null +++ b/docroot/sites/all/modules/features/includes/features.features.inc @@ -0,0 +1,73 @@ + array( + 'name' => 'Dependencies', + 'feature_source' => TRUE, + 'duplicates' => FEATURES_DUPLICATES_ALLOWED, + ), + ); +} + +/** + * Implements hook_features_export_options(). + */ +function dependencies_features_export_options() { + // Excluded modules. + $excluded = drupal_required_modules(); + $options = array(); + foreach (features_get_modules() as $module_name => $info) { + if (!in_array($module_name, $excluded) && $info->status && !empty($info->info)) { + $options[$module_name] = $info->info['name']; + } + } + return $options; +} + +/** + * Implements hook_features_export(). + */ +function dependencies_features_export($data, &$export, $module_name = '') { + // Don't allow a module to depend upon itself. + if (!empty($data[$module_name])) { + unset($data[$module_name]); + } + + // Clean up existing dependencies and merge. + $export['dependencies'] = _features_export_minimize_dependencies($export['dependencies'], $module_name); + $export['dependencies'] = array_merge($data, $export['dependencies']); + $export['dependencies'] = array_unique($export['dependencies']); +} + +/** + * Implements hook_features_revert(). + */ +function dependencies_features_revert($module) { + dependencies_features_rebuild($module); +} + +/** + * Implements hook_features_rebuild(). + * Ensure that all of a feature's dependencies are enabled. + */ +function dependencies_features_rebuild($module) { + $feature = features_get_features($module); + if (!empty($feature->info['dependencies'])) { + $install = array(); + foreach ($feature->info['dependencies'] as $dependency) { + // Parse the dependency string into the module name and version information. + $parsed_dependency = drupal_parse_dependency($dependency); + $dependency = $parsed_dependency['name']; + if (!module_exists($dependency)) { + $install[] = $dependency; + } + } + if (!empty($install)) { + features_install_modules($install); + } + } +} diff --git a/docroot/sites/all/modules/features/includes/features.field.inc b/docroot/sites/all/modules/features/includes/features.field.inc new file mode 100644 index 0000000..849081d --- /dev/null +++ b/docroot/sites/all/modules/features/includes/features.field.inc @@ -0,0 +1,577 @@ + array( + // this is deprecated by field_base and field_instance + // but retained for compatibility with older exports + 'name' => t('Fields'), + 'default_hook' => 'field_default_fields', + 'default_file' => FEATURES_DEFAULTS_INCLUDED, + 'feature_source' => FALSE, + ), + 'field_base' => array( + 'name' => t('Field Bases'), + 'default_hook' => 'field_default_field_bases', + 'default_file' => FEATURES_DEFAULTS_INCLUDED, + 'feature_source' => TRUE, + 'supersedes' => 'field', + ), + 'field_instance' => array( + 'name' => t('Field Instances'), + 'default_hook' => 'field_default_field_instances', + 'default_file' => FEATURES_DEFAULTS_INCLUDED, + 'feature_source' => TRUE, + 'supersedes' => 'field', + ) + ); +} + +/** + * Implements hook_features_export_options(). + */ +function field_base_features_export_options() { + $options = array(); + $fields = field_info_fields(); + foreach ($fields as $field_name => $field) { + $options[$field_name] = $field_name; + } + return $options; +} + +/** + * Implements hook_features_export_options(). + */ +function field_instance_features_export_options() { + $options = array(); + foreach (field_info_fields() as $field_name => $field) { + foreach ($field['bundles'] as $entity_type => $bundles) { + foreach ($bundles as $bundle) { + $identifier = "{$entity_type}-{$bundle}-{$field_name}"; + $options[$identifier] = $identifier; + } + } + } + ksort($options); + return $options; +} + +/** + * Implements hook_features_export(). + */ +function field_base_features_export($data, &$export, $module_name = '') { + $pipe = array(); + $map = features_get_default_map('field_base'); + + // The field_default_field_bases() hook integration is provided by the + // features module so we need to add it as a dependency. + $export['dependencies']['features'] = 'features'; + + foreach ($data as $identifier) { + if ($base = features_field_base_load($identifier)) { + // If this field is already provided by another module, remove the field + // and add the other module as a dependency. + if (isset($map[$identifier]) && $map[$identifier] != $module_name) { + if (isset($export['features']['field_base'][$identifier])) { + unset($export['features']['field_base'][$identifier]); + } + $module = $map[$identifier]; + $export['dependencies'][$module] = $module; + } + // If the field has not yet been exported, add it + else { + $export['features']['field_base'][$identifier] = $identifier; + $export['dependencies'][$base['module']] = $base['module']; + if ($base['storage']['type'] != variable_get('field_storage_default', 'field_sql_storage')) { + $export['dependencies'][$base['storage']['module']] = $base['storage']['module']; + } + // If taxonomy field, add in the vocabulary + if ($base['type'] == 'taxonomy_term_reference' && !empty($base['settings']['allowed_values'])) { + foreach ($base['settings']['allowed_values'] as $allowed_values) { + if (!empty($allowed_values['vocabulary'])) { + $pipe['taxonomy'][] = $allowed_values['vocabulary']; + } + } + } + } + } + } + return $pipe; +} + +/** + * Implements hook_features_export(). + */ +function field_instance_features_export($data, &$export, $module_name = '') { + $pipe = array('field_base' => array()); + $map = features_get_default_map('field_instance'); + + // The field_default_field_instances() hook integration is provided by the + // features module so we need to add it as a dependency. + $export['dependencies']['features'] = 'features'; + + foreach ($data as $identifier) { + if ($instance = features_field_instance_load($identifier)) { + // If this field is already provided by another module, remove the field + // and add the other module as a dependency. + if (isset($map[$identifier]) && $map[$identifier] != $module_name) { + if (isset($export['features']['field_instance'][$identifier])) { + unset($export['features']['field_instance'][$identifier]); + } + $module = $map[$identifier]; + $export['dependencies'][$module] = $module; + } + // If the field has not yet been exported, add it + else { + $export['features']['field_instance'][$identifier] = $identifier; + $export['dependencies'][$instance['widget']['module']] = $instance['widget']['module']; + foreach ($instance['display'] as $key => $display) { + if (isset($display['module'])) { + $export['dependencies'][$display['module']] = $display['module']; + // @TODO: handle the pipe to image styles + } + } + $pipe['field_base'][] = $instance['field_name']; + } + } + } + return $pipe; +} + +/** + * Implements hook_features_export_render(). + */ +function field_base_features_export_render($module, $data, $export = NULL) { + $translatables = $code = array(); + $code[] = ' $field_bases = array();'; + $code[] = ''; + foreach ($data as $identifier) { + if ($field = features_field_base_load($identifier)) { + unset($field['columns']); + unset($field['foreign keys']); + // Only remove the 'storage' declaration if the field is using the default + // storage type. + if ($field['storage']['type'] == variable_get('field_storage_default', 'field_sql_storage')) { + unset($field['storage']); + } + // If we still have a storage declaration here it means that a non-default + // storage type was altered into to the field definition. And no one would + // never need to change the 'details' key, so don't render it. + if (isset($field['storage']['details'])) { + unset($field['storage']['details']); + } + + _field_instance_features_export_sort($field); + $field_export = features_var_export($field, ' '); + $field_prefix = ' // Exported field_base: '; + $field_identifier = features_var_export($identifier); + if (features_field_export_needs_wrap($field_prefix, $field_identifier)) { + $code[] = rtrim($field_prefix); + $code[] = " // {$field_identifier}."; + } + else { + $code[] = $field_prefix . $field_identifier . '.'; + } + $code[] = " \$field_bases[{$field_identifier}] = {$field_export};"; + $code[] = ""; + } + } + $code[] = ' return $field_bases;'; + $code = implode("\n", $code); + return array('field_default_field_bases' => $code); +} + +/** + * Implements hook_features_export_render(). + */ +function field_instance_features_export_render($module, $data, $export = NULL) { + $translatables = $code = array(); + + $code[] = ' $field_instances = array();'; + $code[] = ''; + + foreach ($data as $identifier) { + if ($instance = features_field_instance_load($identifier)) { + _field_instance_features_export_sort($instance); + $field_export = features_var_export($instance, ' '); + $instance_prefix = ' // Exported field_instance: '; + $instance_identifier = features_var_export($identifier); + if (features_field_export_needs_wrap($instance_prefix, $instance_identifier)) { + $code[] = rtrim($instance_prefix); + $code[] = " // {$instance_identifier}."; + } + else { + $code[] = $instance_prefix . $instance_identifier . '.'; + } + $code[] = " \$field_instances[{$instance_identifier}] = {$field_export};"; + $code[] = ""; + + if (!empty($instance['label'])) { + $translatables[] = $instance['label']; + } + if (!empty($instance['description'])) { + $translatables[] = $instance['description']; + } + } + } + if (!empty($translatables)) { + $code[] = features_translatables_export($translatables, ' '); + } + $code[] = ' return $field_instances;'; + $code = implode("\n", $code); + return array('field_default_field_instances' => $code); +} + +// Helper to enforce consistency in field export arrays. +function _field_instance_features_export_sort(&$field, $sort = TRUE) { + + // Some arrays are not sorted to preserve order (for example allowed_values). + static $sort_blacklist = array( + 'allowed_values', + 'format_handlers', + ); + + if ($sort) { + uksort($field, 'strnatcmp'); + } + foreach ($field as $k => $v) { + if (is_array($v)) { + _field_instance_features_export_sort($field[$k], !in_array($k, $sort_blacklist)); + } + } +} + +/** + * Implements hook_features_revert(). + */ +function field_base_features_revert($module) { + field_base_features_rebuild($module); +} + +/** + * Implements hook_features_revert(). + */ +function field_instance_features_revert($module) { + field_instance_features_rebuild($module); +} + +/** + * Implements of hook_features_rebuild(). + * Rebuilds fields from code defaults. + */ +function field_base_features_rebuild($module) { + if ($fields = features_get_default('field_base', $module)) { + field_info_cache_clear(); + + // Load all the existing field bases up-front so that we don't + // have to rebuild the cache all the time. + $existing_fields = field_info_fields(); + + foreach ($fields as $field) { + // Create or update field. + if (isset($existing_fields[$field['field_name']])) { + $existing_field = $existing_fields[$field['field_name']]; + $array_diff_result = drupal_array_diff_assoc_recursive($field + $existing_field, $existing_field); + if (!empty($array_diff_result)) { + try { + field_update_field($field); + } + catch (FieldException $e) { + watchdog('features', 'Attempt to update field %label failed: %message', array('%label' => $field['field_name'], '%message' => $e->getMessage()), WATCHDOG_ERROR); + } + } + } + else { + try { + field_create_field($field); + } + catch (FieldException $e) { + watchdog('features', 'Attempt to create field %label failed: %message', array('%label' => $field['field_name'], '%message' => $e->getMessage()), WATCHDOG_ERROR); + } + $existing_fields[$field['field_name']] = $field; + } + variable_set('menu_rebuild_needed', TRUE); + } + } +} + +/** + * Implements of hook_features_rebuild(). + * Rebuilds field instances from code defaults. + */ +function field_instance_features_rebuild($module) { + if ($instances = features_get_default('field_instance', $module)) { + field_info_cache_clear(); + + // Load all the existing instances up-front so that we don't + // have to rebuild the cache all the time. + $existing_instances = field_info_instances(); + + foreach ($instances as $field_instance) { + // If the field base information does not exist yet, cancel out. + if (!field_info_field($field_instance['field_name'])) { + continue; + } + + // Create or update field instance. + if (isset($existing_instances[$field_instance['entity_type']][$field_instance['bundle']][$field_instance['field_name']])) { + $existing_instance = $existing_instances[$field_instance['entity_type']][$field_instance['bundle']][$field_instance['field_name']]; + if ($field_instance + $existing_instance !== $existing_instance) { + try { + field_update_instance($field_instance); + } + catch (FieldException $e) { + watchdog('features', 'Attempt to update field instance %label (in %entity entity type %bundle bundle) failed: %message', array('%label' => $field_instance['field_name'], '%entity' => $field_instance['entity_type'], '%bundle' => $field_instance['bundle'], '%message' => $e->getMessage()), WATCHDOG_ERROR); + } + } + } + else { + try { + field_create_instance($field_instance); + } + catch (FieldException $e) { + watchdog('features', 'Attempt to create field instance %label (in %entity entity type %bundle bundle) failed: %message', array('%label' => $field_instance['field_name'], '%entity' => $field_instance['entity_type'], '%bundle' => $field_instance['bundle'], '%message' => $e->getMessage()), WATCHDOG_ERROR); + } + $existing_instances[$field_instance['entity_type']][$field_instance['bundle']][$field_instance['field_name']] = $field_instance; + } + } + + if ($instances) { + variable_set('menu_rebuild_needed', TRUE); + } + } +} + +/** + * Load a field base configuration by a field_name identifier. + */ +function features_field_base_load($field_name) { + if ($field_info = field_info_field($field_name)) { + unset($field_info['id']); + unset($field_info['bundles']); + return $field_info; + } + return FALSE; +} + +/** + * Load a field's instance configuration by an entity_type-bundle-field_name + * identifier. + */ +function features_field_instance_load($identifier) { + list($entity_type, $bundle, $field_name) = explode('-', $identifier); + if ($instance_info = field_info_instance($entity_type, $field_name, $bundle)) { + unset($instance_info['id']); + unset($instance_info['field_id']); + return $instance_info; + } + return FALSE; +} + +/* ----- DEPRECATED FIELD EXPORT ----- + * keep this code for backward compatibility with older exports + * until v3.x + */ + +/** + * Implements hook_features_export_options(). + */ +function field_features_export_options() { + $options = array(); + $instances = field_info_instances(); + foreach ($instances as $entity_type => $bundles) { + foreach ($bundles as $bundle => $fields) { + foreach ($fields as $field) { + $identifier = "{$entity_type}-{$bundle}-{$field['field_name']}"; + $options[$identifier] = $identifier; + } + } + } + return $options; +} + +/** + * Implements hook_features_export(). + */ +function field_features_export($data, &$export, $module_name = '') { + $pipe = array(); + // Convert 'field' to 'field_instance' on features-update. + $pipe['field_instance'] = $data; + return $pipe; +} + +/** + * Implements hook_features_export_render(). + */ +function field_features_export_render($module, $data, $export = NULL) { + $translatables = $code = array(); + + $code[] = ' $fields = array();'; + $code[] = ''; + foreach ($data as $identifier) { + if ($field = features_field_load($identifier)) { + unset($field['field_config']['columns']); + // Only remove the 'storage' declaration if the field is using the default + // storage type. + if ($field['field_config']['storage']['type'] == variable_get('field_storage_default', 'field_sql_storage')) { + unset($field['field_config']['storage']); + } + // If we still have a storage declaration here it means that a non-default + // storage type was altered into to the field definition. And no one would + // never need to change the 'details' key, so don't render it. + if (isset($field['field_config']['storage']['details'])) { + unset($field['field_config']['storage']['details']); + } + + _field_features_export_sort($field); + $field_export = features_var_export($field, ' '); + $field_identifier = features_var_export($identifier); + $code[] = " // Exported field: {$field_identifier}."; + $code[] = " \$fields[{$field_identifier}] = {$field_export};"; + $code[] = ""; + + // Add label and description to translatables array. + if (!empty($field['field_instance']['label'])) { + $translatables[] = $field['field_instance']['label']; + } + if (!empty($field['field_instance']['description'])) { + $translatables[] = $field['field_instance']['description']; + } + } + } + if (!empty($translatables)) { + $code[] = features_translatables_export($translatables, ' '); + } + $code[] = ' return $fields;'; + $code = implode("\n", $code); + return array('field_default_fields' => $code); +} + +// Helper to enforce consistency in field export arrays. +function _field_features_export_sort(&$field, $sort = TRUE) { + + // Some arrays are not sorted to preserve order (for example allowed_values). + static $sort_blacklist = array( + 'allowed_values', + 'format_handlers', + ); + + if ($sort) { + ksort($field); + } + foreach ($field as $k => $v) { + if (is_array($v)) { + _field_features_export_sort($field[$k], !in_array($k, $sort_blacklist)); + } + } +} + +/** + * Implements hook_features_revert(). + */ +function field_features_revert($module) { + field_features_rebuild($module); +} + +/** + * Implements of hook_features_rebuild(). + * Rebuilds fields from code defaults. + */ +function field_features_rebuild($module) { + if ($fields = features_get_default('field', $module)) { + field_info_cache_clear(); + + // Load all the existing fields and instance up-front so that we don't + // have to rebuild the cache all the time. + $existing_fields = field_info_fields(); + $existing_instances = field_info_instances(); + + foreach ($fields as $field) { + // Create or update field. + $field_config = $field['field_config']; + if (isset($existing_fields[$field_config['field_name']])) { + $existing_field = $existing_fields[$field_config['field_name']]; + $array_diff_result = drupal_array_diff_assoc_recursive($field_config + $existing_field, $existing_field); + if (!empty($array_diff_result)) { + try { + field_update_field($field_config); + } + catch (FieldException $e) { + watchdog('features', 'Attempt to update field %label failed: %message', array('%label' => $field_config['field_name'], '%message' => $e->getMessage()), WATCHDOG_ERROR); + } + } + } + else { + try { + field_create_field($field_config); + } + catch (FieldException $e) { + watchdog('features', 'Attempt to create field %label failed: %message', array('%label' => $field_config['field_name'], '%message' => $e->getMessage()), WATCHDOG_ERROR); + } + $existing_fields[$field_config['field_name']] = $field_config; + } + + // Create or update field instance. + $field_instance = $field['field_instance']; + if (isset($existing_instances[$field_instance['entity_type']][$field_instance['bundle']][$field_instance['field_name']])) { + $existing_instance = $existing_instances[$field_instance['entity_type']][$field_instance['bundle']][$field_instance['field_name']]; + if ($field_instance + $existing_instance !== $existing_instance) { + field_update_instance($field_instance); + } + } + else { + field_create_instance($field_instance); + $existing_instances[$field_instance['entity_type']][$field_instance['bundle']][$field_instance['field_name']] = $field_instance; + } + } + + if ($fields) { + variable_set('menu_rebuild_needed', TRUE); + } + } +} + +/** + * Load a field's configuration and instance configuration by an + * entity_type-bundle-field_name identifier. + */ +function features_field_load($identifier) { + list($entity_type, $bundle, $field_name) = explode('-', $identifier); + $field_info = field_info_field($field_name); + $instance_info = field_info_instance($entity_type, $field_name, $bundle); + if ($field_info && $instance_info) { + unset($field_info['id']); + unset($field_info['bundles']); + unset($instance_info['id']); + unset($instance_info['field_id']); + return array( + 'field_config' => $field_info, + 'field_instance' => $instance_info, + ); + } + return FALSE; +} + +/** + * Determine if a field export line needs to be wrapped. + * + * Drupal code standards specify that comments should wrap at 80 characters or + * less. + * + * @param string $prefix + * The prefix to be exported before the field identifier. + * @param string $identifier + * The field identifier. + * + * @return BOOL + * TRUE if the line should be wrapped after the prefix, else FALSE. + * + * @see https://www.drupal.org/node/1354 + */ +function features_field_export_needs_wrap($prefix, $identifier) { + // Check for 79 characters, since the comment ends with a full stop. + return (strlen($prefix) + strlen($identifier) > 79); +} diff --git a/docroot/sites/all/modules/features/includes/features.filter.inc b/docroot/sites/all/modules/features/includes/features.filter.inc new file mode 100644 index 0000000..a52927d --- /dev/null +++ b/docroot/sites/all/modules/features/includes/features.filter.inc @@ -0,0 +1,120 @@ + array( + 'name' => t('Text formats'), + 'default_hook' => 'filter_default_formats', + 'default_file' => FEATURES_DEFAULTS_INCLUDED, + 'feature_source' => TRUE + ), + ); +} + +/** + * Implements hook_features_export_options(). + */ +function filter_features_export_options() { + $options = array(); + foreach (filter_formats() as $format => $info) { + $options[$format] = $info->name; + } + return $options; +} + +/** + * Implements hook_features_export(). + */ +function filter_features_export($data, &$export, $module_name = '') { + // The filter_default_formats() hook integration is provided by the + // features module so we need to add it as a dependency. + $export['dependencies']['features'] = 'features'; + + $filter_info = filter_get_filters(); + foreach ($data as $name) { + if ($format = features_filter_format_load($name)) { + // Add format to exports + $export['features']['filter'][$format->format] = $format->format; + + // Iterate through filters and ensure each filter's module is included as a dependency + foreach (array_keys($format->filters) as $name) { + if (isset($filter_info[$name], $filter_info[$name]['module'])) { + $module = $filter_info[$name]['module']; + $export['dependencies'][$module] = $module; + } + } + } + } + + $pipe = array(); + return $pipe; +} + +/** + * Implements hook_features_export_render(). + */ +function filter_features_export_render($module, $data, $export = NULL) { + $code = array(); + $code[] = ' $formats = array();'; + $code[] = ''; + + foreach ($data as $name) { + if ($format = features_filter_format_load($name)) { + $format_export = features_var_export($format, ' '); + $format_identifier = features_var_export($format->format); + $code[] = " // Exported format: {$format->name}."; + $code[] = " \$formats[{$format_identifier}] = {$format_export};"; + $code[] = ""; + } + } + + $code[] = ' return $formats;'; + $code = implode("\n", $code); + return array('filter_default_formats' => $code); +} + +/** + * Implements hook_features_revert(). + */ +function filter_features_revert($module) { + return filter_features_rebuild($module); +} + +/** + * Implements hook_features_rebuild(). + */ +function filter_features_rebuild($module) { + if ($defaults = features_get_default('filter', $module)) { + foreach ($defaults as $format) { + $format = (object) $format; + filter_format_save($format); + } + } +} + +/** + * Load a filter format by its name. + */ +function features_filter_format_load($name) { + // Use machine name for retrieving the format if available. + $query = db_select('filter_format'); + $query->fields('filter_format'); + $query->condition('format', $name); + + // Retrieve filters for the format and attach. + if ($format = $query->execute()->fetchObject()) { + $format->filters = array(); + foreach (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; + } + } + return $format; + } + return FALSE; +} diff --git a/docroot/sites/all/modules/features/includes/features.image.inc b/docroot/sites/all/modules/features/includes/features.image.inc new file mode 100644 index 0000000..b2058b7 --- /dev/null +++ b/docroot/sites/all/modules/features/includes/features.image.inc @@ -0,0 +1,110 @@ + array( + 'name' => t('Image styles'), + 'feature_source' => TRUE, + 'default_hook' => 'image_default_styles', + 'alter_hook' => 'image_styles', + ) + ); +} + +/** + * Implements hook_features_export_options(). + */ +function image_features_export_options() { + $options = array(); + foreach (image_styles() as $name => $style) { + $options[$name] = $style['name']; + } + return $options; +} + +/** + * Implements hook_features_export(). + */ +function image_features_export($data, &$export, $module_name = '') { + $pipe = array(); + $map = features_get_default_map('image'); + foreach ($data as $style) { + $export['dependencies']['image'] = 'image'; + // If another module provides this style, add it as a dependency + if (isset($map[$style]) && $map[$style] != $module_name) { + $module = $map[$style]; + $export['dependencies'][$module] = $module; + } + // Otherwise, export the style + elseif (image_style_load($style)) { + $export['features']['image'][$style] = $style; + } + } + return $pipe; +} + +/** + * Implements hook_features_export_render(). + */ +function image_features_export_render($module_name, $data, $export = NULL) { + $code = array(); + $code[] = ' $styles = array();'; + $code[] = ''; + foreach ($data as $name) { + if ($style = image_style_load($name)) { + _image_features_style_sanitize($style); + $style_export = features_var_export($style, ' '); + $style_identifier = features_var_export($name); + $code[] = " // Exported image style: {$name}."; + $code[] = " \$styles[{$style_identifier}] = {$style_export};"; + $code[] = ""; + } + } + $code[] = ' return $styles;'; + $code = implode("\n", $code); + return array('image_default_styles' => $code); +} + +/** + * Implements hook_features_revert(). + */ +function image_features_revert($module) { + if ($default_styles = features_get_default('image', $module)) { + foreach (array_keys($default_styles) as $default_style) { + if ($style = image_style_load($default_style)) { + if ($style['storage'] != IMAGE_STORAGE_DEFAULT) { + image_default_style_revert($style); + } + } + } + } +} + +/** + * Remove unnecessary keys for export. + */ +function _image_features_style_sanitize(array &$style) { + // Sanitize style: Don't export numeric IDs and things which get overwritten + // in image_styles() or are code/storage specific. The name property will be + // the key of the exported $style array. + $style = array_diff_key($style, array_flip(array( + 'isid', + 'name', + 'module', + 'storage', + ))); + + // Sanitize effects: all that needs to be kept is name, weight and data, + // which holds all the style-specific configuration. Other keys are assumed + // to belong to the definition of the effect itself, so not configuration. + foreach ($style['effects'] as $id => $effect) { + $style['effects'][$id] = array_intersect_key($effect, array_flip(array( + 'name', + 'data', + 'weight', + ))); + } +} diff --git a/docroot/sites/all/modules/features/includes/features.locale.inc b/docroot/sites/all/modules/features/includes/features.locale.inc new file mode 100644 index 0000000..126d177 --- /dev/null +++ b/docroot/sites/all/modules/features/includes/features.locale.inc @@ -0,0 +1,163 @@ + array( + 'name' => t('Languages'), + 'default_hook' => 'locale_default_languages', + 'feature_source' => TRUE, + 'default_file' => FEATURES_DEFAULTS_INCLUDED, + ), + ); +} + +/** + * Implements hook_features_export_options(). + */ +function language_features_export_options() { + return locale_language_list('native', TRUE); +} + +/** + * Implements hook_features_export(). + */ +function language_features_export($data, &$export, $module_name = '') { + $export['dependencies']['features'] = 'features'; + $export['dependencies']['locale'] = 'locale'; + + $language_list = locale_language_list('native', TRUE); + + foreach ($data as $name) { + // Only export existing languages. + if (!empty($language_list[$name])) { + // Add language to exports. + $export['features']['language'][$name] = $name; + } + } + + // No pipe to return. + return array(); +} + +/** + * Implements hook_features_export_render(). + */ +function language_features_export_render($module, $data, $export = NULL) { + $code = array(); + $code[] = ' $languages = array();'; + $code[] = ''; + + $language_list = language_list(); + + foreach ($data as $name) { + // Only render existing languages. + if (!empty($language_list[$name])) { + + $var = (array) $language_list[$name]; + // Unset javascript hash + unset($var['javascript']); + + $lang_export = features_var_export($var, ' '); + $lang_identifier = features_var_export($name); + $code[] = " // Exported language: $name."; + $code[] = " \$languages[{$lang_identifier}] = {$lang_export};"; + } + } + + $code[] = ' return $languages;'; + $code = implode("\n", $code); + return array('locale_default_languages' => $code); +} + +/** + * Implements hook_features_revert(). + */ +function language_features_revert($module) { + return language_features_rebuild($module); +} + +/** + * Implements hook_features_rebuild(). + */ +function language_features_rebuild($module) { + if ($defaults = features_get_default('language', $module)) { + foreach ($defaults as $key => $language) { + _features_language_save((object) $language); + } + + // Set correct language count. + $enabled_languages = db_select('languages') + ->condition('enabled', 1) + ->fields('languages') + ->execute() + ->rowCount(); + variable_set('language_count', $enabled_languages); + } +} + +/** + * Helper function to save the language to database. + * + * @see locale_languages_edit_form_submit() + */ +function _features_language_save($language) { + + $current_language = db_select('languages') + ->condition('language', $language->language) + ->fields('languages') + ->execute() + ->fetchAssoc(); + + // Set the default language when needed. + $default = language_default(); + + // Insert new language via api function. + if (empty($current_language)) { + locale_add_language($language->language, + $language->name, + $language->native, + $language->direction, + $language->domain, + $language->prefix, + $language->enabled, + ($language->language == $default->language)); + // Additional params, locale_add_language does not implement. + db_update('languages') + ->fields(array( + 'plurals' => empty($language->plurals) ? 0 : $language->plurals, + 'formula' => empty($language->formula) ? '' : $language->formula, + 'weight' => empty($language->weight) ? 0 : $language->weight, + )) + ->condition('language', $language->language) + ->execute(); + } + // Update Existing language. + else { + // @TODO: get properties from schema. + $properties = array('language', 'name', 'native', 'direction', 'enabled', 'plurals', 'formula', 'domain', 'prefix', 'weight', 'javascript'); + // The javascript hash is not in the imported data but should be empty + if (!isset($language->javascript)) { + $language->javascript = ''; + } + + $fields = array_intersect_key((array) $language, array_flip($properties)); + db_update('languages') + ->fields($fields) + ->condition('language', $language->language) + ->execute(); + + // Set the default language when needed. + $default = language_default(); + if ($default->language == $language->language) { + variable_set('language_default', (object) $fields); + } + } +} diff --git a/docroot/sites/all/modules/features/includes/features.menu.inc b/docroot/sites/all/modules/features/includes/features.menu.inc new file mode 100644 index 0000000..edd4751 --- /dev/null +++ b/docroot/sites/all/modules/features/includes/features.menu.inc @@ -0,0 +1,427 @@ + array( + 'name' => t('Menus'), + 'default_hook' => 'menu_default_menu_custom', + 'feature_source' => TRUE, + 'default_file' => FEATURES_DEFAULTS_INCLUDED, + ), + 'menu_links' => array( + 'name' => t('Menu links'), + 'default_hook' => 'menu_default_menu_links', + 'feature_source' => TRUE, + 'default_file' => FEATURES_DEFAULTS_INCLUDED, + ), + // DEPRECATED + 'menu' => array( + 'name' => t('Menu items'), + 'default_hook' => 'menu_default_items', + 'default_file' => FEATURES_DEFAULTS_INCLUDED, + 'feature_source' => FALSE, + ), + ); +} + +/** + * Implements hook_features_export(). + * DEPRECATED: This implementation simply migrates deprecated `menu` items + * to the `menu_links` type. + */ +function menu_features_export($data, &$export, $module_name = '') { + $pipe = array(); + foreach ($data as $path) { + $pipe['menu_links'][] = "features:{$path}"; + } + return $pipe; +} + +/** + * Implements hook_features_export_options(). + */ +function menu_custom_features_export_options() { + $options = array(); + $result = db_query("SELECT * FROM {menu_custom} ORDER BY title", array(), array('fetch' => PDO::FETCH_ASSOC)); + foreach ($result as $menu) { + $options[$menu['menu_name']] = $menu['title']; + } + return $options; +} + +/** + * Implements hook_features_export(). + */ +function menu_custom_features_export($data, &$export, $module_name = '') { + // Default hooks are provided by the feature module so we need to add + // it as a dependency. + $export['dependencies']['features'] = 'features'; + $export['dependencies']['menu'] = 'menu'; + + // Collect a menu to module map + $pipe = array(); + $map = features_get_default_map('menu_custom', 'menu_name'); + foreach ($data as $menu_name) { + // If this menu is provided by a different module, add it as a dependency. + if (isset($map[$menu_name]) && $map[$menu_name] != $module_name) { + $export['dependencies'][$map[$menu_name]] = $map[$menu_name]; + } + else { + $export['features']['menu_custom'][$menu_name] = $menu_name; + } + } + return $pipe; +} + +/** + * Implements hook_features_export_render() + */ +function menu_custom_features_export_render($module, $data) { + $code = array(); + $code[] = ' $menus = array();'; + $code[] = ''; + + $translatables = array(); + foreach ($data as $menu_name) { + $row = db_select('menu_custom') + ->fields('menu_custom') + ->condition('menu_name', $menu_name) + ->execute() + ->fetchAssoc(); + if ($row) { + $export = features_var_export($row, ' '); + $code[] = " // Exported menu: {$menu_name}."; + $code[] = " \$menus['{$menu_name}'] = {$export};"; + $translatables[] = $row['title']; + $translatables[] = $row['description']; + } + } + if (!empty($translatables)) { + $code[] = features_translatables_export($translatables, ' '); + } + + $code[] = ' return $menus;'; + $code = implode("\n", $code); + return array('menu_default_menu_custom' => $code); +} + +/** + * Implements hook_features_revert(). + */ +function menu_custom_features_revert($module) { + menu_custom_features_rebuild($module); +} + +/** + * Implements hook_features_rebuild(). + */ +function menu_custom_features_rebuild($module) { + if ($defaults = features_get_default('menu_custom', $module)) { + foreach ($defaults as $menu) { + menu_save($menu); + } + } +} + +/** + * Implements hook_features_export_options(). + */ +function menu_links_features_export_options() { + global $menu_admin; + // Need to set this to TRUE in order to get menu links that the + // current user may not have access to (i.e. user/login) + $menu_admin = TRUE; + $use_menus = array_intersect_key(menu_get_menus(), array_flip(array_filter(variable_get('features_admin_menu_links_menus', array_keys(menu_get_menus()))))); + $menu_links = menu_parent_options($use_menus, array('mlid' => 0)); + $options = array(); + foreach ($menu_links as $key => $name) { + list($menu_name, $mlid) = explode(':', $key, 2); + if ($mlid != 0) { + $link = menu_link_load($mlid); + $identifier = menu_links_features_identifier($link, TRUE); + $options[$identifier] = "{$menu_name}: {$name}"; + } + } + $menu_admin = FALSE; + return $options; +} + +/** + * Callback for generating the menu link exportable identifier. + */ +function menu_links_features_identifier($link, $old = FALSE) { + // Add some uniqueness to these identifiers, allowing multiple links with the same path, but different titles. + $clean_title = features_clean_title(isset($link['title']) ? $link['title'] : $link['link_title']); + + // The old identifier is requested. + if ($old) { + // if identifier already exists + if (isset($link['options']['identifier'])) { + return $link['options']['identifier']; + } + // providing backward compatibility and allowing/enabling multiple links with same paths + else { + $identifier = isset($link['menu_name'], $link['link_path']) ? "{$link['menu_name']}:{$link['link_path']}" : FALSE; + // Checking if there are multiples of this identifier + if (features_menu_link_load($identifier) !== FALSE) { + // this is where we return the upgrade posibility for links. + return $identifier; + } + } + } + + return isset($link['menu_name'], $link['link_path']) ? "{$link['menu_name']}_{$clean_title}:{$link['link_path']}" : FALSE; +} + +/** + * Implements hook_features_export(). + */ +function menu_links_features_export($data, &$export, $module_name = '') { + // Default hooks are provided by the feature module so we need to add + // it as a dependency. + $export['dependencies']['features'] = 'features'; + $export['dependencies']['menu'] = 'menu'; + + // Collect a link to module map + $pipe = array(); + $map = features_get_default_map('menu_links', 'menu_links_features_identifier'); + foreach ($data as $key => $identifier) { + if ($link = features_menu_link_load($identifier)) { + // If this link is provided by a different module, add it as a dependency. + $new_identifier = menu_links_features_identifier($link, empty($export)); + if (isset($map[$identifier]) && $map[$identifier] != $module_name) { + $export['dependencies'][$map[$identifier]] = $map[$identifier]; + } + else { + $export['features']['menu_links'][$new_identifier] = $new_identifier; + } + // For now, exclude a variety of common menus from automatic export. + // They may still be explicitly included in a Feature if the builder + // chooses to do so. + if (!in_array($link['menu_name'], array('features', 'primary-links', 'secondary-links', 'navigation', 'admin', 'devel'))) { + $pipe['menu_custom'][] = $link['menu_name']; + } + } + } + return $pipe; +} + +/** + * Implements hook_features_export_render() + */ +function menu_links_features_export_render($module, $data, $export = NULL) { + $code = array(); + $code[] = ' $menu_links = array();'; + $code[] = ''; + + $translatables = array(); + foreach ($data as $identifier) { + + if ($link = features_menu_link_load($identifier)) { + $new_identifier = menu_links_features_identifier($link, empty($export)); + + // Replace plid with a parent path. + if (!empty($link['plid']) && $parent = menu_link_load($link['plid'])) { + // If the new identifier is different than the old, maintain + // 'parent_path' for backwards compatibility. + if ($new_identifier != menu_links_features_identifier($link)) { + $link['parent_path'] = $parent['link_path']; + } + else { + $clean_title = features_clean_title($parent['title']); + $link['parent_identifier'] = "{$parent['menu_name']}_{$clean_title}:{$parent['link_path']}"; + } + } + + if (isset($export)) { + // Don't show new identifier unless we are actually exporting. + $link['options']['identifier'] = $new_identifier; + // identifiers are renewed, => that means we need to update them in the db + $temp = $link; + menu_link_save($temp); + } + + unset($link['plid']); + unset($link['mlid']); + + $code[] = " // Exported menu link: {$new_identifier}."; + $code[] = " \$menu_links['{$new_identifier}'] = ". features_var_export($link, ' ') .";"; + $translatables[] = $link['link_title']; + } + } + $code[] = ''; + if (!empty($translatables)) { + $code[] = features_translatables_export($translatables, ' '); + } + + $code[] = ' return $menu_links;'; + $code = implode("\n", $code); + return array('menu_default_menu_links' => $code); +} + +/** + * Implements hook_features_revert(). + */ +function menu_links_features_revert($module) { + menu_links_features_rebuild($module); +} + +/** + * Implements hook_features_rebuild(). + */ +function menu_links_features_rebuild($module) { + if ($menu_links = features_get_default('menu_links', $module)) { + menu_links_features_rebuild_ordered($menu_links); + } +} + +/** + * Generate a depth tree of all menu links. + */ +function menu_links_features_rebuild_ordered($menu_links, $reset = FALSE) { + static $ordered; + static $all_links; + if (!isset($ordered) || $reset) { + $ordered = array(); + $unordered = features_get_default('menu_links'); + + // Order all links by depth. + if ($unordered) { + do { + $current = count($unordered); + foreach ($unordered as $key => $link) { + $identifier = menu_links_features_identifier($link); + $parent = isset($link['parent_identifier']) ? $link['parent_identifier'] : ''; + $weight = 0; + // Parent has been seen, so weigh this above parent. + if (isset($ordered[$parent])) { + $weight = $ordered[$parent] + 1; + } + // Next loop will try to find parent weight instead. + elseif ($parent) { + continue; + } + $ordered[$identifier] = $weight; + $all_links[$identifier] = $link; + unset($unordered[$key]); + } + // Exit out when the above does no changes this loop. + } while (count($unordered) < $current); + } + // Add all remaining unordered items to the ordered list. + foreach ($unordered as $link) { + $identifier = menu_links_features_identifier($link); + $ordered[$identifier] = 0; + $all_links[$identifier] = $link; + } + asort($ordered); + } + + // Ensure any default menu items that do not exist are created. + foreach (array_keys($ordered) as $identifier) { + $link = $all_links[$identifier]; + + $existing = features_menu_link_load($identifier); + if (!$existing || in_array($link, $menu_links)) { + // Retrieve the mlid if this is an existing item. + if ($existing) { + $link['mlid'] = $existing['mlid']; + } + // Retrieve the plid for a parent link. + if (!empty($link['parent_identifier']) && $parent = features_menu_link_load($link['parent_identifier'])) { + $link['plid'] = $parent['mlid']; + } + // This if for backwards compatibility. + elseif (!empty($link['parent_path']) && $parent = features_menu_link_load("{$link['menu_name']}:{$link['parent_path']}")) { + $link['plid'] = $parent['mlid']; + } + else { + $link['plid'] = 0; + } + menu_link_save($link); + } + } +} + +/** + * Load a menu link by its menu_name_cleantitle:link_path identifier. + * Also matches links with unique menu_name:link_path + */ +function features_menu_link_load($identifier) { + $menu_name = ''; + $link_path = ''; + // This gets variables for menu_name_cleantitle:link_path format. + if (strstr($identifier, "_")) { + $link_path = substr($identifier, strpos($identifier, ":") + 1); + list($menu_name) = explode('_', $identifier, 2); + $clean_title = substr($identifier, strpos($identifier, "_") + 1, strpos($identifier, ":") - strpos($identifier, "_") - 1); + } + // This gets variables for traditional identifier format. + else { + $clean_title = ''; + list($menu_name, $link_path) = explode(':', $identifier, 2); + } + $links = db_select('menu_links') + ->fields('menu_links', array('menu_name', 'mlid', 'plid', 'link_path', 'router_path', 'link_title', 'options', 'module', 'hidden', 'external', 'has_children', 'expanded', 'weight', 'customized')) + ->condition('menu_name', $menu_name) + ->condition('link_path', $link_path) + ->addTag('features_menu_link') + ->execute() + ->fetchAllAssoc('mlid'); + + foreach($links as $link) { + $link->options = unserialize($link->options); + + // Title or previous identifier matches. + if ((isset($link->options['identifier']) && strcmp($link->options['identifier'], $identifier) == 0) + || (isset($clean_title) && strcmp(features_clean_title($link->link_title), $clean_title) == 0)) { + + return (array)$link; + } + } + + // Only one link with the requested menu_name and link_path does exists, + // -- providing an upgrade possibility for links saved in a feature before the + // new identifier-pattern was added. + if (count($links) == 1 && empty($clean_title)) { + $link = reset($links); // get the first item + return (array)$link; + } + // If link_path was changed on an existing link, we need to find it by + // searching for link_title. + else if (isset($clean_title)) { + $links = db_select('menu_links') + ->fields('menu_links', array('menu_name', 'mlid', 'plid', 'link_path', 'router_path', 'link_title', 'options', 'module', 'hidden', 'external', 'has_children', 'expanded', 'weight')) + ->condition('menu_name', $menu_name) + ->execute() + ->fetchAllAssoc('mlid'); + + foreach($links as $link) { + $link->options = unserialize($link->options); + // Links with a stored identifier must only be matched on that identifier, + // to prevent cross over assumptions. + if (isset($link->options['identifier'])) { + if (strcmp($link->options['identifier'], $identifier) == 0) { + return (array)$link; + } + } + elseif ((strcmp(features_clean_title($link->link_title), $clean_title) == 0)) { + return (array)$link; + } + } + } + return FALSE; +} + +/** + * Returns a lowercase clean string with only letters, numbers and dashes + */ +function features_clean_title($str) { + return strtolower(preg_replace_callback('/(\s)|([^a-zA-Z\-0-9])/i', create_function( + '$matches', + 'return $matches[1]?"-":"";' + ), $str)); +} diff --git a/docroot/sites/all/modules/features/includes/features.node.inc b/docroot/sites/all/modules/features/includes/features.node.inc new file mode 100644 index 0000000..25a2c1c --- /dev/null +++ b/docroot/sites/all/modules/features/includes/features.node.inc @@ -0,0 +1,174 @@ + array( + 'name' => t('Content types'), + 'feature_source' => TRUE, + 'default_hook' => 'node_info', + 'alter_type' => FEATURES_ALTER_TYPE_INLINE, + ), + ); +} + +/** + * Implements hook_features_export_options(). + */ +function node_features_export_options() { + return node_type_get_names(); +} + +/** + * Implements hook_features_export. + */ +function node_features_export($data, &$export, $module_name = '') { + $pipe = array(); + $map = features_get_default_map('node'); + + foreach ($data as $type) { + // Poll node module to determine who provides the node type. + if ($info = node_type_get_type($type)) { + // If this node type is provided by a different module, add it as a dependency + if (isset($map[$type]) && $map[$type] != $module_name) { + $export['dependencies'][$map[$type]] = $map[$type]; + } + // Otherwise export the node type. + elseif (in_array($info->base, array('node_content', 'features'))) { + $export['features']['node'][$type] = $type; + $export['dependencies']['node'] = 'node'; + $export['dependencies']['features'] = 'features'; + } + + $fields = field_info_instances('node', $type); + foreach ($fields as $name => $field) { + $pipe['field_instance'][] = "node-{$field['bundle']}-{$field['field_name']}"; + } + } + } + + return $pipe; +} + +/** + * Implements hook_features_export_render(). + */ +function node_features_export_render($module, $data, $export = NULL) { + $elements = array( + 'name' => TRUE, + 'base' => FALSE, + 'description' => TRUE, + 'has_title' => FALSE, + 'title_label' => TRUE, + 'help' => TRUE, + ); + $output = array(); + $output[] = ' $items = array('; + foreach ($data as $type) { + if ($info = node_type_get_type($type)) { + // Force module name to be 'features' if set to 'node. If we leave as + // 'node' the content type will be assumed to be database-stored by + // the node module. + $info->base = ($info->base === 'node') ? 'features' : $info->base; + $output[] = " '{$type}' => array("; + foreach ($elements as $key => $t) { + if ($t) { + $text = str_replace("'", "\'", $info->$key); + $text = !empty($text) ? "t('{$text}')" : "''"; + $output[] = " '{$key}' => {$text},"; + } + else { + $output[] = " '{$key}' => '{$info->$key}',"; + } + } + $output[] = " ),"; + } + } + $output[] = ' );'; + $output[] = ' drupal_alter(\'node_info\', $items);'; + $output[] = ' return $items;'; + $output = implode("\n", $output); + return array('node_info' => $output); +} + +/** + * Implements hook_features_revert(). + * + * @param $module + * name of module to revert content for + */ +function node_features_revert($module = NULL) { + if ($default_types = features_get_default('node', $module)) { + foreach ($default_types as $type_name => $type_info) { + // Delete node types + // We don't use node_type_delete() because we do not actually + // want to delete the node type (and invoke hook_node_type()). + // This can lead to bad consequences like CCK deleting field + // storage in the DB. + db_delete('node_type') + ->condition('type', $type_name) + ->execute(); + } + node_types_rebuild(); + menu_rebuild(); + } +} + +/** + * Implements hook_features_disable_feature(). + * + * When a features module is disabled, modify any node types it provides so + * they can be deleted manually through the content types UI. + * + * @param $module + * Name of module that has been disabled. + */ +function node_features_disable_feature($module) { + if ($default_types = features_get_default('node', $module)) { + foreach ($default_types as $type_name => $type_info) { + $type_info = node_type_load($type_name); + $type_info->module = 'node'; + $type_info->custom = 1; + $type_info->modified = 1; + $type_info->locked = 0; + $type_info->disabled = 0; + node_type_save($type_info); + } + } +} + +/** + * Implements hook_features_enable_feature(). + * + * When a features module is enabled, modify any node types it provides so + * they can no longer be deleted manually through the content types UI. + * + * Update the database cache of node types if needed. + * + * @param $module + * Name of module that has been enabled. + */ +function node_features_enable_feature($module) { + if ($default_types = features_get_default('node', $module)) { + $rebuild = FALSE; + foreach ($default_types as $type_name => $type_info) { + // Ensure the type exists. + if ($type_info = node_type_load($type_name)) { + $type_info->module = $module; + $type_info->custom = 0; + $type_info->modified = 0; + $type_info->locked = 1; + $type_info->disabled = 0; + node_type_save($type_info); + } + else { + $rebuild = TRUE; + } + } + if ($rebuild) { + node_types_rebuild(); + } + } +} diff --git a/docroot/sites/all/modules/features/includes/features.taxonomy.inc b/docroot/sites/all/modules/features/includes/features.taxonomy.inc new file mode 100644 index 0000000..a7c85cd --- /dev/null +++ b/docroot/sites/all/modules/features/includes/features.taxonomy.inc @@ -0,0 +1,105 @@ + array( + 'name' => t('Taxonomy'), + 'feature_source' => TRUE, + 'default_hook' => 'taxonomy_default_vocabularies', + 'default_file' => FEATURES_DEFAULTS_INCLUDED, + ), + ); +} + +/** + * Implements hook_features_export_options(). + */ +function taxonomy_features_export_options() { + $vocabularies = array(); + foreach (taxonomy_get_vocabularies() as $vocabulary) { + $vocabularies[$vocabulary->machine_name] = $vocabulary->name; + } + return $vocabularies; +} + +/** + * Implements hook_features_export(). + * + * @todo Test adding existing dependencies. + */ +function taxonomy_features_export($data, &$export, $module_name = '') { + $pipe = array(); + + // taxonomy_default_vocabularies integration is provided by Features. + $export['dependencies']['features'] = 'features'; + $export['dependencies']['taxonomy'] = 'taxonomy'; + + // Add dependencies for each vocabulary. + $map = features_get_default_map('taxonomy'); + foreach ($data as $machine_name) { + if (isset($map[$machine_name]) && $map[$machine_name] != $module_name) { + $export['dependencies'][$map[$machine_name]] = $map[$machine_name]; + } + else { + $export['features']['taxonomy'][$machine_name] = $machine_name; + + $fields = field_info_instances('taxonomy_term', $machine_name); + foreach ($fields as $name => $field) { + $pipe['field'][] = "taxonomy_term-{$field['bundle']}-{$field['field_name']}"; + $pipe['field_instance'][] = "taxonomy_term-{$field['bundle']}-{$field['field_name']}"; + } + } + } + return $pipe; +} + +/** + * Implements hook_features_export_render(). + */ +function taxonomy_features_export_render($module, $data) { + $vocabularies = taxonomy_get_vocabularies(); + $code = array(); + foreach ($data as $machine_name) { + foreach ($vocabularies as $vocabulary) { + if ($vocabulary->machine_name == $machine_name) { + // We don't want to break the entity cache, so we need to clone the + // vocabulary before unsetting the id. + $vocabulary = clone $vocabulary; + unset($vocabulary->vid); + $code[$machine_name] = $vocabulary; + } + } + } + $code = " return ". features_var_export($code, ' ') .";"; + return array('taxonomy_default_vocabularies' => $code); +} + +/** + * Implements hook_features_revert(). + */ +function taxonomy_features_revert($module) { + taxonomy_features_rebuild($module); +} + +/** + * Implements hook_features_rebuild(). + * + * Rebuilds Taxonomy vocabularies from code defaults. + */ +function taxonomy_features_rebuild($module) { + if ($vocabularies = features_get_default('taxonomy', $module)) { + $existing = taxonomy_get_vocabularies(); + foreach ($vocabularies as $vocabulary) { + $vocabulary = (object) $vocabulary; + foreach ($existing as $existing_vocab) { + if ($existing_vocab->machine_name === $vocabulary->machine_name) { + $vocabulary->vid = $existing_vocab->vid; + } + } + taxonomy_vocabulary_save($vocabulary); + } + } +} diff --git a/docroot/sites/all/modules/features/includes/features.user.inc b/docroot/sites/all/modules/features/includes/features.user.inc new file mode 100644 index 0000000..152c5a8 --- /dev/null +++ b/docroot/sites/all/modules/features/includes/features.user.inc @@ -0,0 +1,290 @@ + array( + 'name' => t('Roles'), + 'feature_source' => TRUE, + 'default_hook' => 'user_default_roles', + 'default_file' => FEATURES_DEFAULTS_INCLUDED, + ), + 'user_permission' => array( + 'name' => t('Permissions'), + 'feature_source' => TRUE, + 'default_hook' => 'user_default_permissions', + 'default_file' => FEATURES_DEFAULTS_INCLUDED, + ), + ); +} + +/** + * Implements hook_features_export(). + */ +function user_permission_features_export($data, &$export, $module_name = '') { + $export['dependencies']['features'] = 'features'; + + // Ensure the modules that provide the given permissions are included as dependencies. + $map = user_permission_get_modules(); + foreach ($data as $perm) { + $perm_name = $perm; + // Export vocabulary permissions using the machine name, instead of + // vocabulary id. + _user_features_change_term_permission($perm_name, 'machine_name'); + if (isset($map[$perm_name])) { + $perm_module = $map[$perm_name]; + $export['dependencies'][$perm_module] = $perm_module; + $export['features']['user_permission'][$perm] = $perm; + } + } + + return array(); +} + +/** + * Implements hook_features_export_options(). + */ +function user_permission_features_export_options() { + $modules = array(); + $module_info = system_get_info('module'); + foreach (module_implements('permission') as $module) { + $modules[$module] = $module_info[$module]['name']; + } + ksort($modules); + + $options = array(); + foreach ($modules as $module => $display_name) { + if ($permissions = module_invoke($module, 'permission')) { + foreach ($permissions as $perm => $perm_item) { + // Export vocabulary permissions using the machine name, instead of + // vocabulary id. + _user_features_change_term_permission($perm); + $options[$perm] = strip_tags("{$display_name}: {$perm_item['title']}"); + } + } + } + return $options; +} + +/** + * Implements hook_features_export_render(). + */ +function user_permission_features_export_render($module, $data) { + $perm_modules = &drupal_static(__FUNCTION__ . '_perm_modules'); + if (!isset($perm_modules)) { + $perm_modules = user_permission_get_modules(); + } + + $code = array(); + $code[] = ' $permissions = array();'; + $code[] = ''; + + $permissions = _user_features_get_permissions(); + + foreach ($data as $perm_name) { + $permission = array(); + // Export vocabulary permissions using the machine name, instead of + // vocabulary id. + $perm = $perm_name; + _user_features_change_term_permission($perm_name, 'machine_name'); + $permission['name'] = $perm; + if (!empty($permissions[$perm_name])) { + sort($permissions[$perm_name]); + $permission['roles'] = drupal_map_assoc($permissions[$perm_name]); + } + else { + $permission['roles'] = array(); + } + if (isset($perm_modules[$perm_name])) { + $permission['module'] = $perm_modules[$perm_name]; + } + $perm_identifier = features_var_export($perm); + $perm_export = features_var_export($permission, ' '); + $code[] = " // Exported permission: {$perm_identifier}."; + $code[] = " \$permissions[{$perm_identifier}] = {$perm_export};"; + $code[] = ""; + } + + $code[] = ' return $permissions;'; + $code = implode("\n", $code); + return array('user_default_permissions' => $code); +} + +/** + * Implements hook_features_revert(). + */ +function user_permission_features_revert($module) { + user_permission_features_rebuild($module); +} + +/** + * Implements hook_features_rebuild(). + * Iterate through default permissions and update the permissions map. + * + * @param $module + * The module whose default user permissions should be rebuilt. + */ +function user_permission_features_rebuild($module) { + if ($defaults = features_get_default('user_permission', $module)) { + // Make sure the list of available node types is up to date, especially when + // installing multiple features at once, for example from an install profile + // or via drush. + node_types_rebuild(); + + $modules = user_permission_get_modules(); + $roles = _user_features_get_roles(); + $permissions_by_role = _user_features_get_permissions(FALSE); + foreach ($defaults as $permission) { + $perm = $permission['name']; + _user_features_change_term_permission($perm, 'machine_name'); + if (empty($modules[$perm])) { + $args = array('!name' => $perm, '!module' => $module,); + $msg = t('Warning in features rebuild of !module. No module defines permission "!name".', $args); + drupal_set_message($msg, 'warning'); + continue; + } + // Export vocabulary permissions using the machine name, instead of + // vocabulary id. + foreach ($roles as $role) { + if (in_array($role, $permission['roles'])) { + $permissions_by_role[$role][$perm] = TRUE; + } + else { + $permissions_by_role[$role][$perm] = FALSE; + } + } + } + // Write the updated permissions. + foreach ($roles as $rid => $role) { + if (isset($permissions_by_role[$role])) { + user_role_change_permissions($rid, $permissions_by_role[$role]); + } + } + } +} + +/** + * Implements hook_features_export(). + */ +function user_role_features_export($data, &$export, $module_name = '') { + $export['dependencies']['features'] = 'features'; + $map = features_get_default_map('user_role', 'name'); + foreach ($data as $role) { + // Role is provided by another module. Add dependency. + if (isset($map[$role]) && $map[$role] != $module_name) { + $export['dependencies'][$map[$role]] = $map[$role]; + } + // Export. + elseif(user_role_load_by_name($role)) { + $export['features']['user_role'][$role] = $role; + } + } + return array(); +} + +/** + * Implements hook_features_export_options(). + */ +function user_role_features_export_options() { + return drupal_map_assoc(_user_features_get_roles(FALSE)); +} + +/** + * Implements hook_features_export_render(). + */ +function user_role_features_export_render($module, $data) { + $code = array(); + $code[] = ' $roles = array();'; + $code[] = ''; + + foreach ($data as $name) { + if ($role = user_role_load_by_name($name)) { + unset($role->rid); + $role_identifier = features_var_export($name); + $role_export = features_var_export($role , ' '); + $code[] = " // Exported role: {$name}."; + $code[] = " \$roles[{$role_identifier}] = {$role_export};"; + $code[] = ""; + } + } + + $code[] = ' return $roles;'; + $code = implode("\n", $code); + return array('user_default_roles' => $code); +} + +/** + * Implements hook_features_revert(). + */ +function user_role_features_revert($module) { + user_role_features_rebuild($module); +} + +/** + * Implements hook_features_rebuild(). + */ +function user_role_features_rebuild($module) { + if ($defaults = features_get_default('user_role', $module)) { + foreach ($defaults as $role) { + $role = (object) $role; + if ($existing = user_role_load_by_name($role->name)) { + $role->rid = $existing->rid; + } + user_role_save($role); + } + } +} + +/** + * Generate $rid => $role with role names untranslated. + */ +function _user_features_get_roles($builtin = TRUE) { + $roles = array(); + foreach (user_roles() as $rid => $name) { + switch ($rid) { + case DRUPAL_ANONYMOUS_RID: + if ($builtin) { + $roles[$rid] = 'anonymous user'; + } + break; + case DRUPAL_AUTHENTICATED_RID: + if ($builtin) { + $roles[$rid] = 'authenticated user'; + } + break; + default: + $roles[$rid] = $name; + break; + } + } + return $roles; +} + +/** + * Represent the current state of permissions as a perm to role name array map. + */ +function _user_features_get_permissions($by_role = TRUE) { + $map = user_permission_get_modules(); + $roles = _user_features_get_roles(); + $permissions = array(); + foreach (user_role_permissions($roles) as $rid => $role_permissions) { + if ($by_role) { + foreach (array_keys(array_filter($role_permissions)) as $permission) { + if (isset($map[$permission])) { + $permissions[$permission][] = $roles[$rid]; + } + } + } + else { + $permissions[$roles[$rid]] = array(); + foreach ($role_permissions as $permission => $status) { + if (isset($map[$permission])) { + $permissions[$roles[$rid]][$permission] = $status; + } + } + } + } + return $permissions; +} diff --git a/docroot/sites/all/modules/features/tests/features.test b/docroot/sites/all/modules/features/tests/features.test new file mode 100644 index 0000000..025ef23 --- /dev/null +++ b/docroot/sites/all/modules/features/tests/features.test @@ -0,0 +1,329 @@ + t('Component tests'), + 'description' => t('Run tests for components of Features.') , + 'group' => t('Features'), + ); + } + + /** + * Set up test. + */ + public function setUp() { + parent::setUp(array( + 'field', + 'filter', + 'image', + 'taxonomy', + 'views', + 'features', + 'features_test' + )); + + // Run a features rebuild to ensure our feature is fully installed. + features_rebuild(); + + $admin_user = $this->drupalCreateUser(array('administer features')); + $this->drupalLogin($admin_user); + } + + /** + * Run test. + */ + public function test() { + module_load_include('inc', 'features', 'features.export'); + + $components = array_filter(array( + 'field_instance' => 'field', + 'filter' => 'filter', + 'image' => 'image', + 'node' => 'node', + 'user_permission' => 'user', + 'views_view' => 'views', + ), 'module_exists'); + + foreach (array_keys($components) as $component) { + $callback = "_test_{$component}"; + + // Ensure that the component/default is properly available. + $object = $this->$callback('load'); + $this->assertTrue(!empty($object), t('@component present.', array('@component' => $component))); + + // Ensure that the component is defaulted. + $states = features_get_component_states(array('features_test'), FALSE, TRUE); + $this->assertTrue($states['features_test'][$component] === FEATURES_DEFAULT, t('@component state: Default.', array('@component' => $component))); + + // Override component and test that Features detects the override. + $this->$callback('override', $this); + $states = features_get_component_states(array('features_test'), FALSE, TRUE); + $this->assertTrue($states['features_test'][$component] === FEATURES_OVERRIDDEN, t('@component state: Overridden.', array('@component' => $component))); + } + + // Revert component and ensure that component has reverted. + // Do this in separate loops so we only have to run + // drupal_flush_all_caches() once. + foreach (array_keys($components) as $component) { + features_revert(array('features_test' => array($component))); + } + drupal_flush_all_caches(); + foreach (array_keys($components) as $component) { + // Reload so things like Views can clear it's cache + $this->$callback('load'); + $states = features_get_component_states(array('features_test'), FALSE, TRUE); + $this->assertTrue($states['features_test'][$component] === FEATURES_DEFAULT, t('@component reverted.', array('@component' => $component))); + } + } + + protected function _test_field_instance($op = 'load') { + switch ($op) { + case 'load': + return field_info_instance('node', 'field_features_test', 'features_test'); + case 'override': + $field_instance = field_info_instance('node', 'field_features_test', 'features_test'); + $field_instance['label'] = 'Foo bar'; + field_update_instance($field_instance); + break; + } + } + + protected function _test_filter($op = 'load') { + // So... relying on our own API functions to test is pretty lame. + // But these modules don't have APIs either. So might as well use + // the ones we've written for them... + features_include(); + switch ($op) { + case 'load': + return features_filter_format_load('features_test'); + case 'override': + $format = features_filter_format_load('features_test'); + unset($format->filters['filter_url']); + filter_format_save($format); + break; + } + } + + protected function _test_image($op = 'load') { + switch ($op) { + case 'load': + return image_style_load('features_test'); + case 'override': + $style = image_style_load('features_test'); + $style = image_style_save($style); + foreach ($style['effects'] as $effect) { + $effect['data']['width'] = '120'; + image_effect_save($effect); + } + break; + } + } + + protected function _test_node($op = 'load') { + switch ($op) { + case 'load': + return node_type_get_type('features_test'); + case 'override': + $type = node_type_get_type('features_test'); + $type->description = 'Foo bar baz.'; + $type->modified = TRUE; + node_type_save($type); + break; + } + } + + protected function _test_views_view($op = 'load') { + switch ($op) { + case 'load': + return views_get_view('features_test', TRUE); + case 'override': + $view = views_get_view('features_test', TRUE); + $view->set_display('default'); + $view->display_handler->override_option('title', 'Foo bar'); + $view->save(); + // Clear the load cache from above + views_get_view('features_test', TRUE); + break; + } + } + + protected function _test_user_permission($op = 'load') { + switch ($op) { + case 'load': + $permissions = user_role_permissions(array(DRUPAL_AUTHENTICATED_RID => 'authenticated user')); + return !empty($permissions[DRUPAL_AUTHENTICATED_RID]['create features_test content']); + case 'override': + user_role_change_permissions(DRUPAL_AUTHENTICATED_RID, array('create features_test content' => 0)); + break; + } + } +} + +/** + * Tests enabling of feature modules. + */ +class FeaturesEnableTestCase extends DrupalWebTestCase { + protected $profile = 'testing'; + + /** + * Test info. + */ + public static function getInfo() { + return array( + 'name' => t('Features enable tests'), + 'description' => t('Run tests for enabling of features.') , + 'group' => t('Features'), + ); + } + + + /** + * Run test for features_get_components on enable. + */ + public function testFeaturesGetComponents() { + + // Testing that features_get_components returns correct after enable. + $modules = array( + 'features', + 'taxonomy', + 'features_test', + ); + + // Make sure features_get_components is cached if features already enabled. + if (!module_exists('features')) { + drupal_load('module', 'features'); + } + features_get_components(); + + module_enable($modules); + + // Make sure correct information for enabled modules is now cached. + $components = features_get_components(); + $taxonomy_component_info = taxonomy_features_api(); + $this->assertTrue(!empty($components['taxonomy']) && $components['taxonomy'] == $taxonomy_component_info['taxonomy'], 'features_get_components returns correct taxonomy information on enable'); + + features_rebuild(); + $this->assertNotNull(taxonomy_vocabulary_machine_name_load('taxonomy_features_test'), 'Taxonomy vocabulary correctly enabled on enable.'); + } +} + + +/** + * Tests integration of ctools for features. + */ +class FeaturesCtoolsIntegrationTest extends DrupalWebTestCase { + protected $profile = 'testing'; + + /** + * Test info. + */ + public static function getInfo() { + return array( + 'name' => t('Features Chaos Tools integration'), + 'description' => t('Run tests for ctool integration of features.') , + 'group' => t('Features'), + ); + } + + /** + * Set up test. + */ + public function setUp() { + parent::setUp(array( + 'features', + 'ctools', + )); + } + + /** + * Run test. + */ + public function testModuleEnable() { + $try = array( + 'strongarm', + 'views', + ); + + // Trigger the first includes and the static to be set. + features_include(); + $function_ends = array( + 'features_export', + 'features_export_options', + 'features_export_render', + 'features_revert', + ); + foreach ($try as $module) { + $function = $module . '_features_api'; + $this->assertFalse(function_exists($function), 'Chaos tools functions for ' . $module . ' do not exist while it is disabled.'); + // Module enable will trigger declaring the new functions. + module_enable(array($module)); + } + + // CTools hooks only created when there is an actual feature exportable + // enabled. + module_enable(array('features_test')); + + foreach ($try as $module) { + if (module_exists($module)) { + $function_exists = function_exists($function); + if ($function_exists) { + foreach ($function() as $component_type => $component_info) { + foreach ($function_ends as $function_end) { + $function_exists = $function_exists && function_exists($component_type . '_' . $function_end); + } + } + } + $this->assertTrue($function_exists, 'Chaos tools functions for ' . $module . ' exist when it is enabled.'); + } + } + } +} + + +/** + * Test detecting modules as features. + */ +class FeaturesDetectionTestCase extends DrupalWebTestCase { + protected $profile = 'testing'; + + /** + * Test info. + */ + public static function getInfo() { + return array( + 'name' => t('Feature Detection tests'), + 'description' => t('Run tests for detecting items as features.') , + 'group' => t('Features'), + ); + } + + /** + * Set up test. + */ + public function setUp() { + parent::setUp(array( + 'features', + )); + } + + /** + * Run test. + */ + public function test() { + module_load_include('inc', 'features', 'features.export'); + // First test that features_populate inserts the features api key. + $export = features_populate(array(), array(), 'features_test_empty_fake'); + $this->assertTrue(!empty($export['features']['features_api']) && key($export['features']['features_api']) == 'api:' . FEATURES_API, 'Features API key added to new export.'); + $this->assertTrue((bool)features_get_features('features_test'), 'Features test recognized as a feature.'); + $this->assertFalse((bool)features_get_features('features'), 'Features module not recognized as a feature.'); + } +} diff --git a/docroot/sites/all/modules/features/tests/features_test/features_test.features.field_base.inc b/docroot/sites/all/modules/features/tests/features_test/features_test.features.field_base.inc new file mode 100644 index 0000000..b07f00c --- /dev/null +++ b/docroot/sites/all/modules/features/tests/features_test/features_test.features.field_base.inc @@ -0,0 +1,43 @@ + 1, + 'cardinality' => 1, + 'deleted' => 0, + 'entity_types' => array(), + 'field_name' => 'field_features_test', + 'foreign keys' => array( + 'format' => array( + 'columns' => array( + 'format' => 'format', + ), + 'table' => 'filter_format', + ), + ), + 'indexes' => array( + 'format' => array( + 0 => 'format', + ), + ), + 'locked' => 0, + 'module' => 'text', + 'settings' => array( + 'max_length' => 255, + ), + 'translatable' => 1, + 'type' => 'text', + ); + + return $field_bases; +} diff --git a/docroot/sites/all/modules/features/tests/features_test/features_test.features.field_instance.inc b/docroot/sites/all/modules/features/tests/features_test/features_test.features.field_instance.inc new file mode 100644 index 0000000..8796ff4 --- /dev/null +++ b/docroot/sites/all/modules/features/tests/features_test/features_test.features.field_instance.inc @@ -0,0 +1,76 @@ + 'features_test', + 'default_value' => NULL, + 'deleted' => 0, + 'description' => '', + 'display' => array( + 'default' => array( + 'label' => 'above', + 'module' => 'text', + 'settings' => array(), + 'type' => 'text_default', + 'weight' => 0, + ), + 'full' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'print' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'rss' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + 'teaser' => array( + 'label' => 'above', + 'settings' => array(), + 'type' => 'hidden', + 'weight' => 0, + ), + ), + 'entity_type' => 'node', + 'field_name' => 'field_features_test', + 'label' => 'Test', + 'required' => 0, + 'settings' => array( + 'text_processing' => 0, + 'user_register_form' => FALSE, + ), + 'widget' => array( + 'active' => 1, + 'module' => 'text', + 'settings' => array( + 'size' => 60, + ), + 'type' => 'text_textfield', + 'weight' => -4, + ), + ); + + // Translatables + // Included for use with string extractors like potx. + t('Test'); + + return $field_instances; +} diff --git a/docroot/sites/all/modules/features/tests/features_test/features_test.features.filter.inc b/docroot/sites/all/modules/features/tests/features_test/features_test.features.filter.inc new file mode 100644 index 0000000..34cd5e9 --- /dev/null +++ b/docroot/sites/all/modules/features/tests/features_test/features_test.features.filter.inc @@ -0,0 +1,56 @@ + 'features_test', + 'name' => 'features_test', + 'cache' => 1, + 'status' => 1, + 'weight' => 0, + 'filters' => array( + 'filter_autop' => array( + 'weight' => 10, + 'status' => 1, + 'settings' => array(), + ), + 'filter_html' => array( + 'weight' => 10, + 'status' => 1, + 'settings' => array( + 'allowed_html' => ' -
-
- ',
+ 'filter_html_help' => 1,
+ 'filter_html_nofollow' => 0,
+ ),
+ ),
+ 'filter_htmlcorrector' => array(
+ 'weight' => 10,
+ 'status' => 1,
+ 'settings' => array(),
+ ),
+ 'filter_html_escape' => array(
+ 'weight' => 10,
+ 'status' => 1,
+ 'settings' => array(),
+ ),
+ 'filter_url' => array(
+ 'weight' => 10,
+ 'status' => 1,
+ 'settings' => array(
+ 'filter_url_length' => 72,
+ ),
+ ),
+ ),
+ );
+
+ return $formats;
+}
diff --git a/docroot/sites/all/modules/features/tests/features_test/features_test.features.inc b/docroot/sites/all/modules/features/tests/features_test/features_test.features.inc
new file mode 100644
index 0000000..8d0646f
--- /dev/null
+++ b/docroot/sites/all/modules/features/tests/features_test/features_test.features.inc
@@ -0,0 +1,64 @@
+ "1");
+ }
+}
+
+/**
+ * Implements hook_views_api().
+ */
+function features_test_views_api() {
+ return array("api" => "3.0");
+}
+
+/**
+ * Implements hook_image_default_styles().
+ */
+function features_test_image_default_styles() {
+ $styles = array();
+
+ // Exported image style: features_test.
+ $styles['features_test'] = array(
+ 'effects' => array(
+ 2 => array(
+ 'name' => 'image_scale',
+ 'data' => array(
+ 'width' => 100,
+ 'height' => 100,
+ 'upscale' => 0,
+ ),
+ 'weight' => 1,
+ ),
+ ),
+ 'label' => 'features_test',
+ );
+
+ return $styles;
+}
+
+/**
+ * Implements hook_node_info().
+ */
+function features_test_node_info() {
+ $items = array(
+ 'features_test' => array(
+ 'name' => t('Testing: Features'),
+ 'base' => 'node_content',
+ 'description' => t('Content type provided for Features tests.'),
+ 'has_title' => '1',
+ 'title_label' => t('Title'),
+ 'help' => '',
+ ),
+ );
+ return $items;
+}
diff --git a/docroot/sites/all/modules/features/tests/features_test/features_test.features.taxonomy.inc b/docroot/sites/all/modules/features/tests/features_test/features_test.features.taxonomy.inc
new file mode 100644
index 0000000..c5ab0fa
--- /dev/null
+++ b/docroot/sites/all/modules/features/tests/features_test/features_test.features.taxonomy.inc
@@ -0,0 +1,36 @@
+ array(
+ 'name' => 'Taxonomy Features Test',
+ 'machine_name' => 'taxonomy_features_test',
+ 'description' => 'Taxonomy vocabulary',
+ 'hierarchy' => 0,
+ 'module' => 'taxonomy',
+ 'weight' => 0,
+ 'rdf_mapping' => array(
+ 'rdftype' => array(
+ 0 => 'skos:ConceptScheme',
+ ),
+ 'name' => array(
+ 'predicates' => array(
+ 0 => 'dc:title',
+ ),
+ ),
+ 'description' => array(
+ 'predicates' => array(
+ 0 => 'rdfs:comment',
+ ),
+ ),
+ ),
+ ),
+ );
+}
diff --git a/docroot/sites/all/modules/features/tests/features_test/features_test.features.user_permission.inc b/docroot/sites/all/modules/features/tests/features_test/features_test.features.user_permission.inc
new file mode 100644
index 0000000..30b192f
--- /dev/null
+++ b/docroot/sites/all/modules/features/tests/features_test/features_test.features.user_permission.inc
@@ -0,0 +1,24 @@
+ 'create features_test content',
+ 'roles' => array(
+ 'anonymous user' => 'anonymous user',
+ 'authenticated user' => 'authenticated user',
+ ),
+ 'module' => 'node',
+ );
+
+ return $permissions;
+}
diff --git a/docroot/sites/all/modules/features/tests/features_test/features_test.info b/docroot/sites/all/modules/features/tests/features_test/features_test.info
new file mode 100644
index 0000000..efe7101
--- /dev/null
+++ b/docroot/sites/all/modules/features/tests/features_test/features_test.info
@@ -0,0 +1,29 @@
+name = Features Tests
+description = Test module for Features testing.
+core = 7.x
+package = Testing
+php = 5.2.0
+dependencies[] = features
+dependencies[] = image
+dependencies[] = strongarm
+dependencies[] = taxonomy
+dependencies[] = views
+features[ctools][] = strongarm:strongarm:1
+features[ctools][] = views:views_default:3.0
+features[features_api][] = api:2
+features[field_base][] = field_features_test
+features[field_instance][] = node-features_test-field_features_test
+features[filter][] = features_test
+features[image][] = features_test
+features[node][] = features_test
+features[taxonomy][] = taxonomy_features_test
+features[user_permission][] = create features_test content
+features[views_view][] = features_test
+hidden = 1
+
+; Information added by Drupal.org packaging script on 2015-10-14
+version = "7.x-2.7"
+core = "7.x"
+project = "features"
+datestamp = "1444829630"
+
diff --git a/docroot/sites/all/modules/features/tests/features_test/features_test.module b/docroot/sites/all/modules/features/tests/features_test/features_test.module
new file mode 100644
index 0000000..762d6e5
--- /dev/null
+++ b/docroot/sites/all/modules/features/tests/features_test/features_test.module
@@ -0,0 +1,3 @@
+name = 'features_test';
+ $view->description = 'Test view provided by Features testing module.';
+ $view->tag = 'testing';
+ $view->base_table = 'node';
+ $view->human_name = '';
+ $view->core = 0;
+ $view->api_version = '3.0';
+ $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
+
+ /* Display: Defaults */
+ $handler = $view->new_display('default', 'Defaults', 'default');
+ $handler->display->display_options['title'] = 'Test';
+ $handler->display->display_options['use_more_always'] = FALSE;
+ $handler->display->display_options['access']['type'] = 'none';
+ $handler->display->display_options['cache']['type'] = 'none';
+ $handler->display->display_options['query']['type'] = 'views_query';
+ $handler->display->display_options['query']['options']['query_comment'] = FALSE;
+ $handler->display->display_options['exposed_form']['type'] = 'basic';
+ $handler->display->display_options['pager']['type'] = 'full';
+ $handler->display->display_options['style_plugin'] = 'default';
+ $handler->display->display_options['row_plugin'] = 'node';
+ $export['features_test'] = $view;
+
+ return $export;
+}
diff --git a/docroot/sites/all/modules/features/theme/features-admin-components.tpl.php b/docroot/sites/all/modules/features/theme/features-admin-components.tpl.php
new file mode 100644
index 0000000..04213a0
--- /dev/null
+++ b/docroot/sites/all/modules/features/theme/features-admin-components.tpl.php
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $key)) ?>
+
+
+
+
+
+
+
+
diff --git a/docroot/sites/all/modules/features/theme/theme.inc b/docroot/sites/all/modules/features/theme/theme.inc
new file mode 100644
index 0000000..e0f3701
--- /dev/null
+++ b/docroot/sites/all/modules/features/theme/theme.inc
@@ -0,0 +1,362 @@
+ $status) {
+ $rows[] = array(
+ array(
+ 'data' => isset($modules[$dependency]->info['name']) ? $modules[$dependency]->info['name'] : $dependency,
+ 'class' => 'component'
+ ),
+ theme('features_module_status', array('status' => $status)),
+ );
+ }
+ $vars['dependencies'] = theme('table', array('header' => array(t('Dependency'), t('Status')), 'rows' => $rows));
+
+ // Components
+ $rows = array();
+ $components = features_get_components();
+
+ // Display key for conflicting elements.
+ if (!empty($form['#conflicts'])) {
+ $vars['key'][] = array(
+ 'title' => theme('features_storage_link', array('storage' => FEATURES_CONFLICT, 'text' => t('Conflicts with another feature'))),
+ 'html' => TRUE,
+ );
+ }
+
+ if (!empty($form['#info']['features'])) {
+ foreach ($form['#info']['features'] as $component => $items) {
+ if (!empty($items)) {
+ $conflicts = array_key_exists($component, $form['#conflicts'])
+ ? $form['#conflicts'][$component]
+ : NULL;
+
+ $header = $data = array();
+ if (element_children($form['revert'])) {
+ $header[] = array(
+ 'data' => isset($form['revert'][$component]) ? drupal_render($form['revert'][$component]) : '',
+ 'header' => TRUE
+ );
+ }
+ $header[] = array(
+ 'data' => isset($components[$component]['name']) ? $components[$component]['name'] : $component,
+ 'header' => TRUE
+ );
+ $header[] = array(
+ 'data' => drupal_render($form['components'][$component]),
+ 'header' => TRUE
+ );
+ $rows[] = $header;
+
+ if (element_children($form['revert'])) {
+ $data[] = '';
+ }
+ $data[] = array(
+ 'data' => theme('features_component_list', array('components' => $items, 'source' => $items, 'conflicts' => $conflicts)),
+ 'colspan' => 2,
+ 'class' => 'component'
+ );
+ $rows[] = $data;
+ }
+ }
+ }
+ $vars['components'] = theme('table', array('header' => array(), 'rows' => $rows));
+
+ // Other elements
+ $vars['buttons'] = drupal_render($form['buttons']);
+ $vars['form'] = $form;
+ $vars['lock_feature'] = theme('features_lock_link', array('feature' => $form['#feature']->name));
+}
+
+/**
+ * Themes a module status display.
+ */
+function theme_features_module_status($vars) {
+ switch ($vars['status']) {
+ case FEATURES_MODULE_ENABLED:
+ $text_status = t('Enabled');
+ $class = 'admin-enabled';
+ break;
+ case FEATURES_MODULE_DISABLED:
+ $text_status = t('Disabled');
+ $class = 'admin-disabled';
+ break;
+ case FEATURES_MODULE_MISSING:
+ $text_status = t('Missing');
+ $class = 'admin-missing';
+ break;
+ case FEATURES_MODULE_CONFLICT:
+ $text_status = t('Enabled');
+ $class = 'admin-conflict';
+ break;
+ }
+ $text = !empty($vars['module']) ? $vars['module'] . ' (' . $text_status . ')' : $text_status;
+ return "$text";
+}
+
+/**
+ * Themes a lock link
+ */
+function theme_features_lock_link($vars) {
+ drupal_add_library('system', 'ui');
+ drupal_add_library('system', 'drupal.ajax');
+ $component = $vars['component'] ? $vars['component'] : '';
+ if ($component && features_component_is_locked($component)) {
+ return l(t('Component locked'), 'admin/structure/features/settings', array(
+ 'attributes' => array(
+ 'class' => 'features-lock-icon ui-icon ui-icon-locked',
+ 'title' => t('This component is locked on a global level.'),
+ ),
+ 'fragment' => 'edit-lock-components',
+ ));
+ }
+ $feature = $vars['feature'];
+ $is_locked = features_feature_is_locked($feature, $component);
+ $options = array(
+ 'attributes' => array(
+ 'class' => array('use-ajax features-lock-icon ui-icon ' . ($is_locked ? ' ui-icon-locked' : ' ui-icon-unlocked')),
+ 'id' => 'features-lock-link-' . $feature . ($component ? '-' . $component : ''),
+ 'title' => $is_locked ? t('This item is locked and features will not be rebuilt or reverted.') : t('This item is unlocked and will be rebuilt/reverted as normal.'),
+ ),
+ 'query' => array('token' => drupal_get_token('features/' . $feature . '/' . $component)),
+ );
+ $path = "admin/structure/features/" . $feature . "/lock/nojs" . ($component ? '/' . $component: '');
+ return l($is_locked ? t('UnLock') : t('Lock'), $path, $options);
+}
+
+/**
+ * Themes a module status display.
+ */
+function theme_features_storage_link($vars) {
+ $classes = array(
+ FEATURES_OVERRIDDEN => 'admin-overridden',
+ FEATURES_DEFAULT => 'admin-default',
+ FEATURES_NEEDS_REVIEW => 'admin-needs-review',
+ FEATURES_REBUILDING => 'admin-rebuilding',
+ FEATURES_REBUILDABLE => 'admin-rebuilding',
+ FEATURES_CONFLICT => 'admin-conflict',
+ FEATURES_DISABLED => 'admin-disabled',
+ FEATURES_CHECKING => 'admin-loading',
+ );
+ $default_text = array(
+ FEATURES_OVERRIDDEN => t('Overridden'),
+ FEATURES_DEFAULT => t('Default'),
+ FEATURES_NEEDS_REVIEW => t('Needs review'),
+ FEATURES_REBUILDING => t('Rebuilding'),
+ FEATURES_REBUILDABLE => t('Rebuilding'),
+ FEATURES_CONFLICT => t('Conflict'),
+ FEATURES_DISABLED => t('Disabled'),
+ FEATURES_CHECKING => t('Checking...'),
+ );
+ $text = isset($vars['text']) ? $vars['text'] : $default_text[$vars['storage']];
+ if ($vars['path']) {
+ $vars['options']['attributes']['class'][] = $classes[$vars['storage']];
+ $vars['options']['attributes']['class'][] = 'features-storage';
+ return l($text, $vars['path'], $vars['options']);
+ }
+ else {
+ return "{$text}";
+ }
+}
+
+/**
+ * Theme function for displaying form buttons
+ */
+function theme_features_form_buttons(&$vars) {
+ drupal_add_css(drupal_get_path('module', 'features') . '/features.css');
+
+ $output = drupal_render_children($vars['element']);
+ return !empty($output) ? "" : '';
+}
+
+/**
+ * Theme for features management form.
+ */
+function theme_features_form_package(&$vars) {
+ drupal_add_css(drupal_get_path('module', 'features') . '/features.css');
+ drupal_add_js(drupal_get_path('module', 'features') . '/features.js');
+
+ $output = '';
+
+ $header = array('', t('Feature'), t('Signature'));
+ if (isset($vars['form']['state'])) {
+ $header[] = t('State');
+ }
+ if (isset($vars['form']['actions'])) {
+ $header[] = t('Actions');
+ }
+
+ $rows = array();
+ foreach (element_children($vars['form']['status']) as $element) {
+ // Yank title & description fields off the form element for
+ // rendering in their own cells.
+ $name = "";
+ $name .= "{$vars['form']['status'][$element]['#title']}";
+ $name .= "{$vars['form']['status'][$element]['#description']}";
+ $name .= "";
+ unset($vars['form']['status'][$element]['#title']);
+ unset($vars['form']['status'][$element]['#description']);
+
+
+ // Determine row & cell classes
+ $class = $vars['form']['status'][$element]['#default_value'] ? 'enabled' : 'disabled';
+
+ $row = array();
+ $row['status'] = array('data' => drupal_render($vars['form']['status'][$element]), 'class' => array('status'));
+ $row['name'] = array('data' => $name, 'class' => 'name');
+ $row['sign'] = array('data' => drupal_render($vars['form']['sign'][$element]), 'class' => array('sign'));
+
+ if (isset($vars['form']['state'])) {
+ $row['state'] = array('data' => drupal_render($vars['form']['state'][$element]), 'class' => array('state'));
+ }
+ if (isset($vars['form']['actions'])) {
+ $row['actions'] = array('data' => drupal_render($vars['form']['actions'][$element]), 'class' => array('actions'));
+ }
+ $rows[] = array('data' => $row, 'class' => array($class));
+ }
+
+ if (empty($rows)) {
+ $rows[] = array('', array('data' => t('No features available.'), 'colspan' => count($header)));
+ }
+
+ $class = count($header) > 3 ? 'features features-admin' : 'features features-manage';
+ $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'features-form-table', 'class' => array($class))));
+
+ // Prevent section from being rendered by drupal_render().
+
+ $output .= drupal_render($vars['form']['buttons']);
+ $output .= drupal_render_children($vars['form']);
+ return $output;
+}
+
+/**
+ * Theme functions ====================================================
+ */
+
+/**
+ * Export selection / display for features export form.
+ */
+function theme_features_form_export(&$vars) {
+ drupal_add_css(drupal_get_path('module', 'features') . '/features.css');
+ drupal_add_js(drupal_get_path('module', 'features') . '/features.js');
+
+ $output = '';
+ $output .= "";
+ $output .= "" . drupal_render($vars['form']['components']) . drupal_render($vars['form']['sources']) . "";
+ $output .= "" . drupal_render($vars['form']['preview']) . drupal_render($vars['form']['features']) . "";
+ $output .= "";
+ $output .= drupal_render_children($vars['form']);
+ return $output;
+}
+
+/**
+ * Theme a set of features export components.
+ */
+function theme_features_form_components(&$vars) {
+ $output = '';
+ foreach (element_children($vars['form']) as $key) {
+ unset($vars['form'][$key]['#title']);
+ $output .= "" . drupal_render($vars['form'][$key]) . "";
+ }
+ $output .= drupal_render_children($vars['form']);
+ return $output;
+}
+
+/**
+ * Theme a set of features export components.
+ */
+function theme_features_components($vars) {
+ $info = $vars['info'];
+ $sources = $vars['sources'];
+
+ $output = '';
+ $rows = array();
+ $components = features_get_components();
+ if (!empty($info['features']) || !empty($info['dependencies']) || !empty($sources)) {
+ $export = array_unique(array_merge(
+ array_keys($info['features']),
+ array_keys($sources),
+ array('dependencies')
+ ));
+ foreach ($export as $component) {
+ if ($component === 'dependencies') {
+ $feature_items = isset($info[$component]) ? $info[$component] : array();
+ }
+ else {
+ $feature_items = isset($info['features'][$component]) ? $info['features'][$component] : array();
+ }
+ $source_items = isset($sources[$component]) ? $sources[$component] : array();
+ if (!empty($feature_items) || !empty($source_items)) {
+ $rows[] = array(array(
+ 'data' => isset($components[$component]['name']) ? $components[$component]['name'] : $component,
+ 'header' => TRUE
+ ));
+ $rows[] = array(array(
+ 'data' => theme('features_component_list', array('components' => $feature_items, 'source' => $source_items)),
+ 'class' => 'component'
+ ));
+ }
+ }
+ $output .= theme('table', array('header' => array(), 'rows' => $rows));
+ $output .= theme('features_component_key', array());
+ }
+ return $output;
+}
+
+/**
+ * Theme individual components in a component list.
+ */
+function theme_features_component_list($vars) {
+ $components = $vars['components'];
+ $source = $vars['source'];
+ $conflicts = $vars['conflicts'];
+
+ $list = array();
+ foreach ($components as $component) {
+ // If component is not in source list, it was autodetected
+ if (!in_array($component, $source)) {
+ $list[] = "". check_plain($component) ."";
+ }
+ elseif (is_array($conflicts) && in_array($component, $conflicts)) {
+ $list[] = "". check_plain($component) ."";
+ }
+ else {
+ $list[] = "". check_plain($component) ."";
+ }
+ }
+ foreach ($source as $component) {
+ // If a source component is no longer in the items, it was removed because
+ // it is provided by a dependency.
+ if (!in_array($component, $components)) {
+ $list[] = "". check_plain($component) ."";
+ }
+ }
+ return "". implode(' ', $list) ."";
+}
+
+/**
+ * Provide a themed key for a component list.
+ */
+function theme_features_component_key($vars) {
+ $list = array();
+ $list[] = "" . t('Normal') . "";
+ $list[] = "" . t('Auto-detected') . "";
+ $list[] = "" . t('Provided by dependency') . "";
+ return "" . implode(' ', $list) . "";
+}
diff --git a/docroot/sites/all/modules/form_fun/form_fun.cake.inc b/docroot/sites/all/modules/form_fun/form_fun.cake.inc
new file mode 100644
index 0000000..b8cf98f
--- /dev/null
+++ b/docroot/sites/all/modules/form_fun/form_fun.cake.inc
@@ -0,0 +1,50 @@
+ 'select',
+ '#title' => t('Cake or pie?'),
+ '#description' => t('Would you like cake or pie?'),
+ '#options' => array(
+ 'cake' => t('Cake please'),
+ 'pie' => t('Pie I guess'),
+ ),
+ '#default_value' => 'cake',
+ '#required' => TRUE,
+ );
+
+ $form['buttons']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit'),
+ );
+
+ $form['buttons']['unsure'] = array(
+ '#type' => 'submit',
+ '#value' => t('Equivocate'),
+ '#submit' => array('form_fun_cake_unsure'),
+ '#validate' => array(),
+ );
+
+ return $form;
+}
+
+function form_fun_cake_validate(&$form, &$form_state){
+ if ($form_state['values']['choice'] == 'cake'){
+ form_set_error('choice', t('We are out of cake'));
+ }
+}
+
+function form_fun_cake_submit(&$form, &$form_state){
+ dsm($form_state['values']);
+ $form_state['redirect'] = '';
+}
+
+function form_fun_cake_unsure(&$form, &$form_state){
+ drupal_set_message(t('Make up your mind.'), 'warning');
+}
\ No newline at end of file
diff --git a/docroot/sites/all/modules/form_fun/form_fun.info b/docroot/sites/all/modules/form_fun/form_fun.info
new file mode 100644
index 0000000..78568a5
--- /dev/null
+++ b/docroot/sites/all/modules/form_fun/form_fun.info
@@ -0,0 +1,3 @@
+name = Form Fun
+description = Just a demo of how to use forms.
+core = 7.x
\ No newline at end of file
diff --git a/docroot/sites/all/modules/form_fun/form_fun.module b/docroot/sites/all/modules/form_fun/form_fun.module
new file mode 100644
index 0000000..454c186
--- /dev/null
+++ b/docroot/sites/all/modules/form_fun/form_fun.module
@@ -0,0 +1,26 @@
+ 'Cake of Pie?',
+ 'page callback' => 'form_fun_cake_page',
+ 'access arguments' => array('access content'),
+ 'file' => 'form_fun.cake.inc',
+ 'weight' => 1,
+ );
+
+
+ $items['form_fun/tree'] = array(
+ 'title' => "I'm lost!",
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('form_fun_tree'),
+ 'access arguments' => array('access content'),
+ 'file' => 'form_fun.tree.inc',
+ 'weight' => 3,
+
+ );
+ return $items;
+
+
+}
\ No newline at end of file
diff --git a/docroot/sites/all/modules/menu_magic/menu_magic.context.inc b/docroot/sites/all/modules/menu_magic/menu_magic.context.inc
new file mode 100644
index 0000000..6791d86
--- /dev/null
+++ b/docroot/sites/all/modules/menu_magic/menu_magic.context.inc
@@ -0,0 +1,116 @@
+body['und'][0]['value']);
+ $output = array(
+ '#type' => 'markup',
+ '#markup' => $text,
+ );
+ return $output;
+}
+/**
+ * Helper function.
+ */
+function _menu_magicify($text){
+ $substitutions = array(
+ ' ' => ' ',
+ '!' => "¡", # ¡
+ '"' => "„", # „
+ '#' => '#',
+ '$' => '$',
+ '%' => '%',
+ '&' => "⅋", # ⅋
+ "'" => "͵", # ͵
+ '(' => ')',
+ ')' => '(',
+ '*' => '*',
+ '+' => '+',
+ ',' => "‘", # ‘
+ '-' => '-',
+ '.' => "˙", # ˙
+ '/' => '/',
+ '0' => '0',
+ '1' => "⃓", # ,⃓ can be improved
+ '2' => "ჷ", # ჷ
+ '3' => "ε", # ε
+ '4' => "⇁⃓", # ⇁⃓ can be improved
+ '5' => "ᔕ", # ᔕ or maybe just "S"
+ '6' => '9',
+ '7' => "_̸", # _̸
+ '8' => '8',
+ '9' => '6',
+ ':' => ':',
+ ';' => "⋅̕", # ⋅̕ sloppy, should be improved
+ '<' => '>',
+ '=' => '=',
+ '>' => '<',
+ '?' => "¿", # ¿
+ '@' => '@', # can be improved
+ 'A' => "Ꮜ", # Ꮜ
+ 'B' => "ϴ", # ϴ can be improved
+ 'C' => "Ɔ", # Ɔ
+ 'D' => 'p', # should be an uppercase D!!
+ 'E' => "Ǝ", # Ǝ
+ 'F' => "Ⅎ", # Ⅎ
+ 'G' => "⅁", # ⅁
+ 'H' => 'H',
+ 'I' => 'I',
+ 'J' => "ſ", # ſ̲
+ 'K' => "ʞ", # ʞ should be an uppercase K!!
+ 'L' => "⅂", # ⅂
+ 'M' => "Ɯ", # Ɯ or maybe just "W"
+ 'N' => 'N',
+ 'O' => 'O',
+ 'P' => 'd', # should be uppercase P
+ 'Q' => "Ծ", # Ծ can be improved
+ 'R' => "Ȣ", # Ȣ can be improved
+ 'S' => 'S',
+ 'T' => "⊥", # ⊥
+ 'U' => "ᑎ", # ᑎ
+ 'V' => "Λ", # Λ
+ 'W' => 'M',
+ 'X' => 'X',
+ 'Y' => "⅄", # ⅄
+ 'Z' => 'Z',
+ '[' => ']',
+ '\\' => '\\',
+ ']' => '[',
+ '^' => "‿", # ‿
+ '_' => "‾", # ‾
+ '`' => " ̖", # ̖
+ 'a' => "ɐ", # ɐ
+ 'b' => 'q',
+ 'c' => "ɔ", # ɔ
+ 'd' => 'p',
+ 'e' => "ǝ", # ǝ
+ 'f' => "ɟ", # ɟ
+ 'g' => "ɓ", # ɓ
+ 'h' => "ɥ", # ɥ
+ 'i' => "ı̣", # ı̣
+ 'j' => "ſ", # ſ̣
+ 'k' => "ʞ", # ʞ
+ 'l' => "Ʈ", # Ʈ can be improved
+ 'm' => "ɯ", # ɯ
+ 'n' => 'u',
+ 'o' => 'o',
+ 'p' => 'd',
+ 'q' => 'b',
+ 'r' => "ɹ", # ɹ
+ 's' => 's',
+ 't' => "ʇ", # ʇ
+ 'u' => 'n',
+ 'v' => "ʌ", # ʌ
+ 'w' => "ʍ", # ʍ
+ 'x' => 'x',
+ 'y' => "ʎ", # ʎ
+ 'z' => 'z',
+ '{' => '}',
+ '|' => '|',
+ '}' => '{',
+ '~' => "∼", # ∼
+ );
+ $find = array_keys($substitutions);
+ $replace = array_values($substitutions);
+
+ return str_replace($find, $replace, $text);
+}
\ No newline at end of file
diff --git a/docroot/sites/all/modules/menu_magic/menu_magic.extra.inc b/docroot/sites/all/modules/menu_magic/menu_magic.extra.inc
new file mode 100644
index 0000000..3d45a63
--- /dev/null
+++ b/docroot/sites/all/modules/menu_magic/menu_magic.extra.inc
@@ -0,0 +1,9 @@
+ 'markup',
+ '#markup' => '
'.t('The wildcard contains the value "%wildcard".',array('%wildcard' => $wildcard)).'
'
+ );
+ return $content;
+}
\ No newline at end of file
diff --git a/docroot/sites/all/modules/menu_magic/menu_magic.info b/docroot/sites/all/modules/menu_magic/menu_magic.info
new file mode 100644
index 0000000..6b5cd1d
--- /dev/null
+++ b/docroot/sites/all/modules/menu_magic/menu_magic.info
@@ -0,0 +1,3 @@
+name = Menu Magic
+description = Demonstrate the use of hook_menu.
+core = 7.x
\ No newline at end of file
diff --git a/docroot/sites/all/modules/menu_magic/menu_magic.module b/docroot/sites/all/modules/menu_magic/menu_magic.module
new file mode 100644
index 0000000..a62fc61
--- /dev/null
+++ b/docroot/sites/all/modules/menu_magic/menu_magic.module
@@ -0,0 +1,82 @@
+ 'A little magic',
+ 'page callback' => 'menu_magic_basic',
+ 'access arguments' => array('access content'),
+ );
+
+ $items['magic/%'] = array(
+ 'title' => 'Even more magical',
+ 'page callback' => 'menu_magic_extra',
+ 'page arguments' => array(1),
+ 'access arguments' => array('access content'),
+ 'file' => 'menu_magic.extra.inc',
+ );
+
+ $items['user/%/magic'] = array(
+ 'title' => 'Magic',
+ 'description' => 'Magical magic for users',
+ 'page callback' => 'menu_magic_user_tab',
+ 'page arguments' => array(1),
+ 'access callback' => 'user_access',
+ 'access arguments' => array('administer users'),
+ 'file' => 'menu_magic.user.inc',
+ 'type' => MENU_LOCAL_TASK,
+ );
+
+ $items['node/%node/magic'] = array(
+ 'title' => 'Magic',
+ 'description' => 'Do amazing and magical things',
+ 'page callback' => 'menu_magic_node_context',
+ 'page arguments' => array(1),
+ 'access arguments' => array('access content'),
+ 'file' => 'menu_magic.context.inc',
+ 'type' => MENU_LOCAL_TASK,
+ 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
+ );
+
+ return $items;
+}
+
+function menu_magic_basic(){
+ $content = array();
+
+ //This is a very, very simple page element. It will appear on the page,
+ //but other modules can't customize it and themes can't override its markup.
+ $content['raw_markup'] = array(
+ '#type' => 'markup',
+ '#markup' => 'Truly, this is magical!',
+ '#prefix' => '',
+ '#suffix' => '
',
+ );
+
+ $variables = array(
+ 'path' => 'http://placekitten.com/440/400',
+ 'alt' => t('This is a magical kitten'),
+ 'title' => t('This is the title'),
+ );
+ $content['themed_data'] = array(
+ '#type' => 'markup',
+ '#markup' => theme('image', $variables),
+ );
+
+ $content['renderable_element'] =array(
+ '#theme' => 'item_list', //calls the function theme_item_list
+ '#title' => t('How do we know it\'s magic?'),
+ '#items' => array(
+ t("Is it made of wood?"),
+ t("Does it sink in water?"),
+ t("Does it weigh the same as a duck?"),
+ ),
+
+ );
+
+ return $content;
+}
\ No newline at end of file
diff --git a/docroot/sites/all/modules/menu_magic/menu_magic.user.inc b/docroot/sites/all/modules/menu_magic/menu_magic.user.inc
new file mode 100644
index 0000000..54a1fe1
--- /dev/null
+++ b/docroot/sites/all/modules/menu_magic/menu_magic.user.inc
@@ -0,0 +1,16 @@
+ 'markup',
+ '#markup' => t("%username is totally awesome.", array('%username' => $account->name)),
+ );
+ }
+ else{
+ return drupal_not_found();
+ }
+}
\ No newline at end of file