contrib modules security updates
This commit is contained in:
115
sites/all/modules/features/includes/features.contact.inc
Normal file
115
sites/all/modules/features/includes/features.contact.inc
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Features integration for 'contact' module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_features_api().
|
||||
*/
|
||||
function contact_features_api() {
|
||||
return array(
|
||||
'contact_categories' => 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -86,7 +86,6 @@ function ctools_features_export_render($module, $data) {
|
||||
$code[] = ' return array("api" => "3.0");';
|
||||
}
|
||||
else {
|
||||
$code[] = ' list($module, $api) = func_get_args();';
|
||||
$code[] = ' if ($module == "'. $info['module'] .'" && $api == "'. $info['api'] .'") {';
|
||||
$code[] = ' return array("version" => "'. $info['current_version'] .'");';
|
||||
$code[] = ' }';
|
||||
@@ -96,10 +95,13 @@ function ctools_features_export_render($module, $data) {
|
||||
$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] .= "\n" . implode("\n", $code);
|
||||
$component_exports[$plugin_api_hook_name]['code'] .= "\n" . implode("\n", $code);
|
||||
}
|
||||
else {
|
||||
$component_exports[$plugin_api_hook_name] = implode("\n", $code);
|
||||
$component_exports[$plugin_api_hook_name] = array(
|
||||
'code' => implode("\n", $code),
|
||||
'args' => '$module = NULL, $api = NULL',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -6,14 +6,375 @@
|
||||
function field_features_api() {
|
||||
return array(
|
||||
'field' => 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().
|
||||
@@ -37,48 +398,8 @@ function field_features_export_options() {
|
||||
*/
|
||||
function field_features_export($data, &$export, $module_name = '') {
|
||||
$pipe = array();
|
||||
$map = features_get_default_map('field');
|
||||
|
||||
// The field_default_fields() 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 ($field = features_field_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'][$identifier])) {
|
||||
unset($export['features']['field'][$identifier]);
|
||||
}
|
||||
$module = $map[$identifier];
|
||||
$export['dependencies'][$module] = $module;
|
||||
}
|
||||
// If the field has not yet been exported, add it
|
||||
else {
|
||||
$export['features']['field'][$identifier] = $identifier;
|
||||
$export['dependencies'][$field['field_config']['module']] = $field['field_config']['module'];
|
||||
if ($field['field_config']['storage']['type'] != variable_get('field_storage_default', 'field_sql_storage')) {
|
||||
$export['dependencies'][$field['field_config']['storage']['module']] = $field['field_config']['storage']['module'];
|
||||
}
|
||||
$export['dependencies'][$field['field_instance']['widget']['module']] = $field['field_instance']['widget']['module'];
|
||||
foreach ($field['field_instance']['display'] as $key => $display) {
|
||||
if (isset($display['module'])) {
|
||||
$export['dependencies'][$display['module']] = $display['module'];
|
||||
// @TODO: handle the pipe to image styles
|
||||
}
|
||||
}
|
||||
// If taxonomy field, add in the vocabulary
|
||||
if ($field['field_config']['type'] == 'taxonomy_term_reference' && !empty($field['field_config']['settings']['allowed_values'])) {
|
||||
foreach ($field['field_config']['settings']['allowed_values'] as $allowed_values) {
|
||||
if (!empty($allowed_values['vocabulary'])) {
|
||||
$pipe['taxonomy'][] = $allowed_values['vocabulary'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Convert 'field' to 'field_instance' on features-update.
|
||||
$pipe['field_instance'] = $data;
|
||||
return $pipe;
|
||||
}
|
||||
|
||||
@@ -99,7 +420,7 @@ function field_features_export_render($module, $data, $export = NULL) {
|
||||
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 noone would
|
||||
// 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']);
|
||||
@@ -173,12 +494,23 @@ function field_features_rebuild($module) {
|
||||
$field_config = $field['field_config'];
|
||||
if (isset($existing_fields[$field_config['field_name']])) {
|
||||
$existing_field = $existing_fields[$field_config['field_name']];
|
||||
if ($field_config + $existing_field != $existing_field) {
|
||||
field_update_field($field_config);
|
||||
$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 {
|
||||
field_create_field($field_config);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -186,7 +518,7 @@ function field_features_rebuild($module) {
|
||||
$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) {
|
||||
if ($field_instance + $existing_instance !== $existing_instance) {
|
||||
field_update_instance($field_instance);
|
||||
}
|
||||
}
|
||||
@@ -222,3 +554,24 @@ function features_field_load($identifier) {
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
@@ -86,16 +86,25 @@ function image_features_revert($module) {
|
||||
/**
|
||||
* Remove unnecessary keys for export.
|
||||
*/
|
||||
function _image_features_style_sanitize(&$style, $child = FALSE) {
|
||||
$omit = $child ? array('isid', 'ieid', 'storage') : array('isid', 'ieid', 'storage', 'module');
|
||||
if (is_array($style)) {
|
||||
foreach ($style as $k => $v) {
|
||||
if (in_array($k, $omit, TRUE)) {
|
||||
unset($style[$k]);
|
||||
}
|
||||
else if (is_array($v)) {
|
||||
_image_features_style_sanitize($style[$k], TRUE);
|
||||
}
|
||||
}
|
||||
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',
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
@@ -134,14 +134,19 @@ function _features_language_save($language) {
|
||||
->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');
|
||||
// Get field list from table schema.
|
||||
$properties = drupal_schema_fields_sql('languages');
|
||||
// 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')
|
||||
|
@@ -103,7 +103,6 @@ function menu_custom_features_export_render($module, $data) {
|
||||
$code[] = features_translatables_export($translatables, ' ');
|
||||
}
|
||||
|
||||
$code[] = '';
|
||||
$code[] = ' return $menus;';
|
||||
$code = implode("\n", $code);
|
||||
return array('menu_default_menu_custom' => $code);
|
||||
@@ -135,13 +134,14 @@ function menu_links_features_export_options() {
|
||||
// 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;
|
||||
$menu_links = menu_parent_options(menu_get_menus(), array('mlid' => 0));
|
||||
$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);
|
||||
$identifier = menu_links_features_identifier($link, TRUE);
|
||||
$options[$identifier] = "{$menu_name}: {$name}";
|
||||
}
|
||||
}
|
||||
@@ -152,8 +152,28 @@ function menu_links_features_export_options() {
|
||||
/**
|
||||
* Callback for generating the menu link exportable identifier.
|
||||
*/
|
||||
function menu_links_features_identifier($link) {
|
||||
return isset($link['menu_name'], $link['link_path']) ? "{$link['menu_name']}:{$link['link_path']}" : FALSE;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,14 +188,15 @@ function menu_links_features_export($data, &$export, $module_name = '') {
|
||||
// Collect a link to module map
|
||||
$pipe = array();
|
||||
$map = features_get_default_map('menu_links', 'menu_links_features_identifier');
|
||||
foreach ($data as $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'][$identifier] = $identifier;
|
||||
$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
|
||||
@@ -191,31 +212,51 @@ function menu_links_features_export($data, &$export, $module_name = '') {
|
||||
/**
|
||||
* Implements hook_features_export_render()
|
||||
*/
|
||||
function menu_links_features_export_render($module, $data) {
|
||||
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'])) {
|
||||
$link['parent_path'] = $parent['link_path'];
|
||||
// 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']}";
|
||||
}
|
||||
}
|
||||
unset($link['plid']);
|
||||
unset($link['mlid']);
|
||||
|
||||
$code[] = " // Exported menu link: {$identifier}";
|
||||
$code[] = " \$menu_links['{$identifier}'] = ". features_var_export($link, ' ') .";";
|
||||
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[] = '';
|
||||
$code[] = ' return $menu_links;';
|
||||
$code = implode("\n", $code);
|
||||
return array('menu_default_menu_links' => $code);
|
||||
@@ -253,26 +294,36 @@ function menu_links_features_rebuild_ordered($menu_links, $reset = FALSE) {
|
||||
$current = count($unordered);
|
||||
foreach ($unordered as $key => $link) {
|
||||
$identifier = menu_links_features_identifier($link);
|
||||
$parent = isset($link['parent_path']) ? "{$link['menu_name']}:{$link['parent_path']}" : '';
|
||||
if (empty($parent)) {
|
||||
$ordered[$identifier] = 0;
|
||||
$all_links[$identifier] = $link;
|
||||
unset($unordered[$key]);
|
||||
$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;
|
||||
}
|
||||
elseif (isset($ordered[$parent])) {
|
||||
$ordered[$identifier] = $ordered[$parent] + 1;
|
||||
$all_links[$identifier] = $link;
|
||||
unset($unordered[$key]);
|
||||
// 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.
|
||||
@@ -280,9 +331,13 @@ function menu_links_features_rebuild_ordered($menu_links, $reset = FALSE) {
|
||||
$link['mlid'] = $existing['mlid'];
|
||||
}
|
||||
// Retrieve the plid for a parent link.
|
||||
if (!empty($link['parent_path']) && $parent = features_menu_link_load("{$link['menu_name']}:{$link['parent_path']}")) {
|
||||
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;
|
||||
}
|
||||
@@ -292,19 +347,81 @@ function menu_links_features_rebuild_ordered($menu_links, $reset = FALSE) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a menu link by its menu_name:link_path identifier.
|
||||
* 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) {
|
||||
list($menu_name, $link_path) = explode(':', $identifier, 2);
|
||||
$link = 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'))
|
||||
$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()
|
||||
->fetchAssoc();
|
||||
if ($link) {
|
||||
$link['options'] = unserialize($link['options']);
|
||||
return $link;
|
||||
->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));
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ function node_features_api() {
|
||||
'name' => t('Content types'),
|
||||
'feature_source' => TRUE,
|
||||
'default_hook' => 'node_info',
|
||||
'alter_type' => FEATURES_ALTER_TYPE_INLINE,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -43,7 +44,7 @@ function node_features_export($data, &$export, $module_name = '') {
|
||||
|
||||
$fields = field_info_instances('node', $type);
|
||||
foreach ($fields as $name => $field) {
|
||||
$pipe['field'][] = "node-{$field['bundle']}-{$field['field_name']}";
|
||||
$pipe['field_instance'][] = "node-{$field['bundle']}-{$field['field_name']}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,6 +87,7 @@ function node_features_export_render($module, $data, $export = NULL) {
|
||||
}
|
||||
}
|
||||
$output[] = ' );';
|
||||
$output[] = ' drupal_alter(\'node_info\', $items);';
|
||||
$output[] = ' return $items;';
|
||||
$output = implode("\n", $output);
|
||||
return array('node_info' => $output);
|
||||
@@ -115,7 +117,7 @@ function node_features_revert($module = NULL) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_disable().
|
||||
* 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.
|
||||
@@ -123,7 +125,7 @@ function node_features_revert($module = NULL) {
|
||||
* @param $module
|
||||
* Name of module that has been disabled.
|
||||
*/
|
||||
function node_features_disable($module) {
|
||||
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);
|
||||
@@ -131,22 +133,26 @@ function node_features_disable($module) {
|
||||
$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().
|
||||
* 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($module) {
|
||||
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)) {
|
||||
@@ -154,8 +160,15 @@ function node_features_enable($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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -49,6 +49,7 @@ function taxonomy_features_export($data, &$export, $module_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']}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -29,8 +29,12 @@ function user_permission_features_export($data, &$export, $module_name = '') {
|
||||
// Ensure the modules that provide the given permissions are included as dependencies.
|
||||
$map = user_permission_get_modules();
|
||||
foreach ($data as $perm) {
|
||||
if (isset($map[$perm])) {
|
||||
$perm_module = $map[$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;
|
||||
}
|
||||
@@ -46,14 +50,17 @@ function user_permission_features_export_options() {
|
||||
$modules = array();
|
||||
$module_info = system_get_info('module');
|
||||
foreach (module_implements('permission') as $module) {
|
||||
$modules[$module_info[$module]['name']] = $module;
|
||||
$modules[$module] = $module_info[$module]['name'];
|
||||
}
|
||||
ksort($modules);
|
||||
|
||||
$options = array();
|
||||
foreach ($modules as $display_name => $module) {
|
||||
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']}");
|
||||
}
|
||||
}
|
||||
@@ -78,7 +85,11 @@ function user_permission_features_export_render($module, $data) {
|
||||
|
||||
foreach ($data as $perm_name) {
|
||||
$permission = array();
|
||||
$permission['name'] = $perm_name;
|
||||
// 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]);
|
||||
@@ -89,9 +100,9 @@ function user_permission_features_export_render($module, $data) {
|
||||
if (isset($perm_modules[$perm_name])) {
|
||||
$permission['module'] = $perm_modules[$perm_name];
|
||||
}
|
||||
$perm_identifier = features_var_export($perm_name);
|
||||
$perm_identifier = features_var_export($perm);
|
||||
$perm_export = features_var_export($permission, ' ');
|
||||
$code[] = " // Exported permission: {$perm_name}.";
|
||||
$code[] = " // Exported permission: {$perm_identifier}.";
|
||||
$code[] = " \$permissions[{$perm_identifier}] = {$perm_export};";
|
||||
$code[] = "";
|
||||
}
|
||||
@@ -122,10 +133,20 @@ function user_permission_features_rebuild($module) {
|
||||
// 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;
|
||||
|
Reference in New Issue
Block a user