View source
<?php
function node_configuration_api() {
return array(
'node' => array(
'name' => t('Content types'),
'feature_source' => TRUE,
'default_hook' => 'configuration_node_info',
'default_file' => CONFIGURATION_DEFAULTS_INCLUDED,
),
);
}
function node_configuration_export_options() {
return node_type_get_names();
}
function node_configuration_export($data, &$export, $module_name = '') {
$pipe = array();
$map = configuration_get_default_map('node');
foreach ($data as $type) {
$new_dependencies = array();
if ($info = node_type_get_type($type)) {
if (isset($map[$type]) && $map[$type] != $module_name) {
$new_dependencies[$map[$type]] = $map[$type];
}
if (in_array($info->base, array(
'node_content',
'configuration',
))) {
$export['configuration']['node'][$type] = $type;
$new_dependencies['node'] = 'node';
$new_dependencies['configuration'] = 'configuration';
}
$export['dependencies'] = array_merge($export['dependencies'], $new_dependencies);
$fields = field_info_instances('node', $type);
foreach ($fields as $name => $field) {
$export['configuration_dependency']['configuration']['field']["node-{$field['bundle']}-{$field['field_name']}"] = $type;
$export['configuration_dependency']['modules']['field']["node-{$field['bundle']}-{$field['field_name']}"] = serialize($new_dependencies);
$pipe['field'][] = "node-{$field['bundle']}-{$field['field_name']}";
}
}
}
return $pipe;
}
function node_configuration_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)) {
$info->base = $info->base === 'node' ? 'configuration' : $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[] = ' return $items;';
$output = implode("\n", $output);
return array(
'configuration_node_info' => $output,
);
}
function node_configuration_revert($identifiers, $module_name = 'configuration') {
if ($default_types = configuration_get_default('node', $module_name)) {
foreach ($default_types as $type_name => $type_info) {
if (in_array($type_name, $identifiers)) {
db_delete('node_type')
->condition('type', $type_name)
->execute();
}
}
configuration_node_types_rebuild($identifiers, $module_name);
menu_rebuild();
foreach ($default_types as $type_name => $type_info) {
configuration_check_node($type_name);
}
cache_clear_all('config_export', 'cache');
}
}
function configuration_node_types_rebuild($identifiers, $module_name = 'configuration') {
$_node_types = (object) array(
'types' => array(),
'names' => array(),
);
$info_array = call_user_func($module_name . '_configuration_node_info');
foreach ($info_array as $type => $info) {
if (in_array($type, $identifiers) || !empty($identifiers) && $identifiers[0] == '#import_all') {
$info['type'] = $type;
$_node_types->types[$type] = node_type_set_defaults($info);
$_node_types->types[$type]->module = 'configuration';
$_node_types->names[$type] = $info['name'];
}
}
foreach ($_node_types->types as $type => $type_object) {
node_type_save($type_object);
}
node_types_rebuild();
}
function node_configuration_disable($module) {
if ($default_types = configuration_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;
node_type_save($type_info);
}
}
}
function node_configuration_enable($module) {
if ($default_types = configuration_get_default('node', $module)) {
foreach ($default_types as $type_name => $type_info) {
if ($type_info = node_type_load($type_name)) {
$type_info->module = $module;
$type_info->custom = 0;
$type_info->modified = 0;
$type_info->locked = 1;
node_type_save($type_info);
}
}
}
}
function configuration_check_node($identifier) {
$from_activestore =& drupal_static('configuration_from_activestore');
$component = 'node';
if (file_exists("config://configuration.node.inc")) {
include_once drupal_realpath("config://configuration.node.inc");
if (function_exists('configuration_configuration_node_info')) {
node_type_cache_reset();
module_load_include('inc', 'configuration', 'configuration.export');
$code = node_configuration_export_render('configuration', array(
$identifier,
));
eval(array_pop($code));
$items_code = configuration_configuration_node_info();
if (empty($items)) {
configuration_set_status($component, $identifier, CONFIGURATION_TRACKED_DATASTORE_ONLY);
}
configuration_update_component_status($component, $identifier, $items, $items_code, $from_activestore);
}
}
}
function configuration_hash_node($identifier) {
module_load_include('inc', 'configuration', 'configuration.export');
$data = node_configuration_export_options();
$code = node_configuration_export_render('configuration', array(
$identifier,
));
eval(array_pop($code));
return md5(serialize($items[$identifier]));
}