You are here

function publishcontent_form_alter in Publish Content 6

Same name and namespace in other branches
  1. 5.2 publishcontent.module \publishcontent_form_alter()

Implements of hook_form_alter().

  • Enable / Disable publishcontent for specific node types
  • Allow to use the 'Publishing options' on the edit/add page

File

./publishcontent.module, line 185
Add button to publish or unpublish a node, with access control based on the node type

Code

function publishcontent_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'node_type_form') {
    $form['workflow']['publishcontent'] = array(
      '#type' => 'checkbox',
      '#title' => t('Enable publishcontent permissions for this node type.'),
      '#default_value' => variable_get('publishcontent_' . $form['#node_type']->type, TRUE),
      '#description' => t('Unchecking this option will disable publish and unpublish links for this node type.'),
    );
  }
  elseif (user_access('administer nodes') || empty($form['type']['#value']) || empty($form['#node']) || $form['type']['#value'] . '_node_form' != $form_id || !_publishcontent_unpublish_access($form['#node']) && !_publishcontent_publish_access($form['#node'])) {
    return;
  }
  $form['options']['status']['#access'] = TRUE;
  if (!empty($form['options']['#access'])) {
    return;
  }
  else {
    $form['options']['#access'] = TRUE;
  }
  foreach (element_children($form['options']) as $key) {

    // If another form has afforded access to a particular option, do not
    // override that access. Otherwise, disable it.
    $form['options'][$key]['#access'] = isset($form['options'][$key]['#access']) ? $form['options'][$key]['#access'] : FALSE;
  }
}