function publish_button_form_node_form_alter in Publish button 7
Implements hook_form_BASE_FORM_ID_alter().
File
- ./
publish_button.module, line 55 - Functions to create a publish button. Real simple, but could be needed.
Code
function publish_button_form_node_form_alter(&$form, &$form_state, $form_id) {
// Now for the button itself.
// For best practice, make the user object global, because we are checking
// permissions. Usually we have the object, but we should declare that we
// need it. We want to be the good guys, don't we?
global $user;
if (variable_get('publish_button_content_type_' . $form['#node']->type) == TRUE) {
// First we check if the node have the status TRUE. That could be TRUE
// also for unpublished nodes. A little bit sci-fi, isn't it?
if ($form['#node']->status == TRUE) {
// So we check if nid have value, so we do not try to unpublish a node
// that does not exists, that should destroy the universe. We do not
// want that.
if (isset($form['nid']['#value'])) {
if ($form['nid']['#value'] !== NULL) {
// Add the unpublish button to the actions array.
if (_publish_button_unpublish_permissions($form['#node']->type) == TRUE) {
// Check if we are on a delete confirm page.
if ($form['#form_id'] != 'node_delete_confirm') {
$form['actions']['unpublish'] = publish_button_render_unpublish_button();
}
}
}
}
else {
if (_publish_button_publish_permissions($form['#node']->type) == TRUE && isset($form['actions'])) {
// Check if we are on a delete confirm page.
if ($form['#form_id'] != 'node_delete_confirm') {
$form['actions']['publish'] = publish_button_render_publish_button();
}
}
}
}
// Then we check if the node have status FALSE.
if ($form['#node']->status == FALSE) {
// Add the publish button to the action array.
if (_publish_button_publish_permissions($form['#node']->type) == TRUE && isset($form['actions'])) {
// Check if we are on a delete confirm page.
if ($form['#form_id'] != 'node_delete_confirm') {
$form['actions']['publish'] = publish_button_render_publish_button();
}
}
}
}
// Add functionality to work with inline entity form.
if (!empty($form_state['inline_entity_form'])) {
// Try to find the main submit button in the most common places.
$submit_element = NULL;
if (!empty($form['submit'])) {
$submit_element =& $form['submit'];
}
elseif (!empty($form['actions']['publish'])) {
$submit_element =& $form['actions']['publish'];
}
if ($submit_element) {
$submit = array_merge(array(
'inline_entity_form_trigger_submit',
), $submit_element['#submit']);
$submit_element['#submit'] = $submit;
}
}
}