updated features
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -158,7 +158,7 @@ function field_base_features_export_render($module, $data, $export = NULL) {
|
||||
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 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['storage']['details'])) {
|
||||
unset($field['storage']['details']);
|
||||
@@ -170,10 +170,10 @@ function field_base_features_export_render($module, $data, $export = NULL) {
|
||||
$field_identifier = features_var_export($identifier);
|
||||
if (features_field_export_needs_wrap($field_prefix, $field_identifier)) {
|
||||
$code[] = rtrim($field_prefix);
|
||||
$code[] = " // {$field_identifier}";
|
||||
$code[] = " // {$field_identifier}.";
|
||||
}
|
||||
else {
|
||||
$code[] = $field_prefix . $field_identifier;
|
||||
$code[] = $field_prefix . $field_identifier . '.';
|
||||
}
|
||||
$code[] = " \$field_bases[{$field_identifier}] = {$field_export};";
|
||||
$code[] = "";
|
||||
@@ -201,10 +201,10 @@ function field_instance_features_export_render($module, $data, $export = NULL) {
|
||||
$instance_identifier = features_var_export($identifier);
|
||||
if (features_field_export_needs_wrap($instance_prefix, $instance_identifier)) {
|
||||
$code[] = rtrim($instance_prefix);
|
||||
$code[] = " // {$instance_identifier}";
|
||||
$code[] = " // {$instance_identifier}.";
|
||||
}
|
||||
else {
|
||||
$code[] = $instance_prefix . $instance_identifier;
|
||||
$code[] = $instance_prefix . $instance_identifier . '.';
|
||||
}
|
||||
$code[] = " \$field_instances[{$instance_identifier}] = {$field_export};";
|
||||
$code[] = "";
|
||||
@@ -276,11 +276,21 @@ function field_base_features_rebuild($module) {
|
||||
$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)) {
|
||||
field_update_field($field);
|
||||
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 {
|
||||
field_create_field($field);
|
||||
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);
|
||||
@@ -410,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']);
|
||||
@@ -562,5 +572,6 @@ function features_field_load($identifier) {
|
||||
* @see https://www.drupal.org/node/1354
|
||||
*/
|
||||
function features_field_export_needs_wrap($prefix, $identifier) {
|
||||
return (strlen($prefix) + strlen($identifier) > 80);
|
||||
// Check for 79 characters, since the comment ends with a full stop.
|
||||
return (strlen($prefix) + strlen($identifier) > 79);
|
||||
}
|
||||
|
@@ -141,8 +141,8 @@ function _features_language_save($language) {
|
||||
}
|
||||
// Update Existing language.
|
||||
else {
|
||||
// @TODO: get properties from schema.
|
||||
$properties = array('language', 'name', 'native', 'direction', 'enabled', 'plurals', 'formula', 'domain', 'prefix', 'weight', 'javascript');
|
||||
// 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 = '';
|
||||
|
@@ -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);
|
||||
@@ -248,7 +247,7 @@ function menu_links_features_export_render($module, $data, $export = NULL) {
|
||||
unset($link['plid']);
|
||||
unset($link['mlid']);
|
||||
|
||||
$code[] = " // Exported menu link: {$new_identifier}";
|
||||
$code[] = " // Exported menu link: {$new_identifier}.";
|
||||
$code[] = " \$menu_links['{$new_identifier}'] = ". features_var_export($link, ' ') .";";
|
||||
$translatables[] = $link['link_title'];
|
||||
}
|
||||
@@ -316,6 +315,7 @@ function menu_links_features_rebuild_ordered($menu_links, $reset = FALSE) {
|
||||
foreach ($unordered as $link) {
|
||||
$identifier = menu_links_features_identifier($link);
|
||||
$ordered[$identifier] = 0;
|
||||
$all_links[$identifier] = $link;
|
||||
}
|
||||
asort($ordered);
|
||||
}
|
||||
|
@@ -145,11 +145,14 @@ function node_features_disable_feature($module) {
|
||||
* 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)) {
|
||||
@@ -160,6 +163,12 @@ function node_features_enable_feature($module) {
|
||||
$type_info->disabled = 0;
|
||||
node_type_save($type_info);
|
||||
}
|
||||
else {
|
||||
$rebuild = TRUE;
|
||||
}
|
||||
}
|
||||
if ($rebuild) {
|
||||
node_types_rebuild();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user