Skip to content

Instantly share code, notes, and snippets.

@WengerK
Created February 27, 2014 15:26
Show Gist options
  • Save WengerK/266d326f804793c37e3f to your computer and use it in GitHub Desktop.
Save WengerK/266d326f804793c37e3f to your computer and use it in GitHub Desktop.
Drupal custom module - How to disable 'promote to front page' and 'sticky' options?
<?php
/**
* Use hook_form_alter to unset both options on node edit forms.
* But on the main admin content page, the options still appear under 'Update options' dropdown.
*/
/**
* 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']);
}
}
@KostasBlank
Copy link

In drupal 8/9/10, instead of unset, the following works:

$form['sticky']['#access'] = FALSE;
$form['promote']['#access'] = FALSE;

@WengerK
Copy link
Author

WengerK commented Feb 14, 2023

In drupal 8/9/10, instead of unset, the following works:

$form['sticky']['#access'] = FALSE; $form['promote']['#access'] = FALSE;

Thanks for the tips

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment