function node_patterns_build in Patterns 7.2
Same name and namespace in other branches
- 7 patterns_components/components/node.inc \node_patterns_build()
File
- patterns_components/
components/ node.inc, line 332
Code
function node_patterns_build($action, $form_id, &$data = NULL, &$a) {
$status = PATTERNS_SUCCESS;
$msg = '';
$result = NULL;
//content_clear_type_cache();
// TODO: instead: cache_clear_all();
module_load_include('inc', 'content', 'includes/content.admin');
module_load_include('inc', 'node', 'content_types');
// TODO: Isn't this already loaded?
if ($form_id == 'node_delete_confirm') {
$data['confirm'] = 1;
}
elseif ($form_id == 'node_type_form') {
module_load_include('inc', 'node', 'content_types');
$type = $data['type'];
$name = $data['name'];
/*
$types = node_type_get_names();
if (!isset($types[$type])) {
// Set the name of the new content type if missing
if (!$data['name']) {
$data['name'] = $type;
}
$defaults = _node_type_set_defaults($data);
$data = array_merge($defaults, $data);
}
*/
// TODO: update these
/*
if (empty($data['node_options'])) {
$node_options = array('status', 'promote', 'sticky', 'revision');
$default_options = variable_get('node_options_' . $type, NULL);
$options = array();
if (!empty($default_options)) {
$options = array_combine($default_options, $default_options);
}
foreach ($data as $key => $value) {
if (in_array($key, $node_options)) {
if (!empty($value)) {
$options[$key] = $key;
}
else {
unset($options[$key]);
}
unset($data[$key]);
}
}
$data['node_options'] = array_values($options);
$data['node_options']['overwrite'] = TRUE;
}
*/
// TODO
if (isset($data['has_body']) && !$data['has_body']) {
$data['body_label'] = '';
}
}
elseif ($form_id == 'node_type_delete_confirm') {
$data['op'] = t('Delete');
$data['confirm'] = 1;
}
else {
// $data['type'] . '_node_form'
$data['changed'] = time();
$data['op'] = t('Save');
$node = clone $data['node'];
// unset($node->body);
// unset($node->title);
// build Content Type fields
$type = $data['type'];
$form_id = $type . '_node_form';
$form_state = array(
'build_info' => array(
'args' => array(
$node,
),
'files' => array(
'menu' => 'modules/node/node.pages.inc',
),
),
// TODO: all these needed?
'rebuild' => FALSE,
'rebuild_info' => array(),
'redirect' => NULL,
'temporary' => array(),
'submitted' => FALSE,
'executed' => FALSE,
'programmed' => FALSE,
'cache' => FALSE,
'method' => 'post',
'groups' => array(),
'buttons' => array(),
'input' => array(),
);
require_once 'modules/node/node.pages.inc';
$form = drupal_retrieve_form($form_id, $form_state);
drupal_prepare_form($form_id, $form, $form_state);
/*
$content_type = content_types($type);
$fields_info = $content_type['fields'];
if (module_exists('fieldgroup')) {
$groups = fieldgroup_groups($type, FALSE, TRUE);
}
$fields = array();
$fields_diff = array();
if (!empty($groups)) {
foreach($groups as $key => $group) {
$fields = array_merge($fields, array_intersect_ukey($form[$key], $group['fields'], '_patterns_compare_keys'));
}
$fields_diff = array_diff_ukey($fields_info, $fields, '_patterns_compare_keys');
$fields = array_merge($fields, array_intersect_ukey($form, $fields_diff, '_patterns_compare_keys'));
}
else {
$fields = array_merge($fields, array_intersect_ukey($form, $fields_info, '_patterns_compare_keys'));
}
*/
}
$result = $data;
return patterns_results($status, $msg, $result);
}