function custom_pub_form_alter in Custom Publishing Options 7
Same name and namespace in other branches
- 6 custom_pub.module \custom_pub_form_alter()
Implements hook_form_alter().
_state _id
Parameters
$form:
File
- ./
custom_pub.module, line 121 - Adds the ability to add Custom publishing options to the node Add/Edit forms.
Code
function custom_pub_form_alter(&$form, $form_state, $form_id) {
if (isset($form['#node_edit_form']) && $form['#node_edit_form'] === TRUE) {
$node = $form['#node'];
$types = custom_pub_by_node_type($node);
foreach ($types as $type) {
$default_value = isset($node->{$type['type']}) ? $node->{$type['type']} : NULL;
$form['options'][$type['type']] = array(
'#type' => 'checkbox',
'#title' => check_plain(t($type['name'])),
'#default_value' => $default_value,
'#access' => user_access('administer content types') ? TRUE : user_access('edit_custom_pub_' . $type['type']),
);
}
// set access states on core publishing options so we don't create a security issue
$core = array(
'status',
'promote',
'sticky',
);
foreach ($core as $core_option) {
if (!isset($form['options'][$core_option]['#access'])) {
$form['options'][$core_option]['#access'] = user_access('administer nodes') ? TRUE : FALSE;
}
}
foreach ($form['options'] as $option) {
if (isset($option['#access']) && $option['#access'] === TRUE) {
$form['options']['#access'] = TRUE;
break;
}
}
}
// Add options to the node_type_form for editing default node options
if ($form_id == 'node_type_form') {
$node_type = $form['#node_type'];
$types = custom_pub_by_node_type($node_type);
foreach ($types as $type) {
$form['workflow']['node_options']['#options'][$type['type']] = check_plain(t($type['name']));
}
}
if ($form_id == 'node_admin_content') {
if (isset($form_state['values']['operation']) && $form_state['values']['operation'] == 'delete') {
array_unshift($form['#submit'], 'custom_pub_node_admin_inc_add');
}
}
}