Created
February 27, 2014 15:26
-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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']); | |
} | |
} |
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
In drupal 8/9/10, instead of unset, the following works:
$form['sticky']['#access'] = FALSE;
$form['promote']['#access'] = FALSE;