Drupal - How to disable 'promote to front page' and 'sticky' options?

There are 3 places, where those options can be seen:

  • on admin/structure/types/manage/article, for the "Article" content type

    screenshot

  • on node/2/edit, for the node with ID equal to 2

    screenshot

  • on admin/content, between the "Update options"

    screenshot

If you need to remove the options from those setting/administrative pages, then you need to alter the following form builders:

  • node_type_form()
  • node_form()
  • node_admin_nodes()

node_admin_nodes() is the form builder for the node administration overview in admin/content, which includes the "Update options" field that allows the users with the right permission to promote/demote a node from the front page, and to make a node sticky. The field lists all the node operations implemented by modules; in the list of the operations obtained with $operations = module_invoke_all('node_operations'), those operations are represented from $operations['promote'], $operations['demote'], $operations['sticky'], and $operations['unsticky'].


Here is a custom module I wrote for Drupal 7 that removes "promote to front page" and "sticky at top of lists" on node add/edit forms, content type add/edit forms and the admin/content dropdown. This module does not alter any database settings so it won't change existing content, you can always disable it and get your options back and everything will work just like it did before.

Paste this code into a hide_sticky_promote.module and make a corresponding hide_sticky_promote.info file, enable module and wallah, no more sticky and promote checkboxes or dropdown selections.

/**
 * Remove sticky/promote entirely from add and edit content type forms.
 *
 * Implements hook_form_FORM_ID_alter().
 */
function hide_sticky_promote_form_node_type_form_alter(&$form, &$form_state, $form_id) {
  // Remove sticky/promote entirely from add and edit content type forms.
  $options = array('promote', 'sticky');
  foreach ($options as $key) {
    unset($form['workflow']['node_options']['#options'][$key]);    
  }
}

/**
 * Remove sticky/promote entirely from node/X/edit & node/X/add forms.
 * 
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function hide_sticky_promote_form_node_form_alter(&$form, &$form_state, $form_id) {
  $options = array('promote', 'sticky');
  foreach ($options as $key) {
    $form['options'][$key]['#access'] = FALSE;
  }
}

/**
 * Remove some sticky/promote update options on admin/content.
 *
 * Implements hook_form_FORM_ID_alter().
 */
function hide_sticky_promote_form_node_admin_content_alter(&$form, &$form_state, $form_id) {
  $options = array('demote', 'promote', 'sticky', 'unsticky', );
  foreach ($options as $key) {
    unset($form['admin']['options']['operation']['#options'][$key]);
  }
}

Or grab it from here in module form: https://github.com/StudioZut/hide-sticky-promote


Use the following:

/**
 * Implements hook_form_alter().
 * This is remove the promote to frontpage, and make sticky options from node edit pages
 */
function alter_drupal_form_alter(&$form, &$form_state, $form_id) {
  if (strpos($form_id, '_node_form') !== FALSE) {
    unset($form['options']['sticky']);
    unset($form['options']['promote']);
  }

  if (strpos($form_id, 'node_admin_content') !== FALSE) {
    //$opt[''] = '- Select -';
    $opt['publish'] = 'Publish selected content'; 
    $opt['unpublish'] = 'Unpublish selected content'; 
    $opt['delete'] = 'Delete selected content'; 
    $opt['pathauto_update_alias'] = 'Update URL alias'; 
    $form['admin']['options']['operation']['#options'] = $opt;


    // print_r($form['admin']['options']['operation']['#options']);
  }
}

Tags:

Nodes