This blog describes how to hide "Promoted to front page" and "Sticky at top of lists" options from node form in drupal 7. When adding or editing a node, you can see "Publishing options" at bottom of the page which contains 'Published', 'Promoted to front page' and 'Sticky at top of lists' checkbox options. It should look like below image:
The "Published" option is used to publish the content. The "Promoted to front page" option is used to display content in the front page. The 'Sticky at top of lists' option is used to keep the content sticked to the top of front page. If you don't want to show "Promoted to front page" and "Sticky at top of lists" options, then you can hide those options using hook_form_alter(), hook_form_FORM_ID_alter() and hook_form_BASE_FORM_ID_alter().
If you want to hide "Promoted to front page" and "Sticky at top of lists" options in all node forms, then you can remove those options using hook_form_BASE_FORM_ID_alter() in drupal 7.
The "Published" option is used to publish the content. The "Promoted to front page" option is used to display content in the front page. The 'Sticky at top of lists' option is used to keep the content sticked to the top of front page. If you don't want to show "Promoted to front page" and "Sticky at top of lists" options, then you can hide those options using hook_form_alter(), hook_form_FORM_ID_alter() and hook_form_BASE_FORM_ID_alter().
Hide Promoted to front page & Sticky at top of lists options in single node form:
If you want to hide "Promoted to front page" and "Sticky at top of lists" options only in single node form, then you can remove those options from node form using either hook_form_alter() or hook_form_FORM_ID_alter() in drupal 7. For example, we go to hide those options from article node form.
/**
* Implement hook_form_alter().
*/
function phponwebsites_form_alter(&$form, &$form_state, $form_id) {
// to hide promoted to front page option
if (isset($form['options']['promote'])) {
$form['options']['promote']['#access'] = FALSE;
}
// to hide sticky at top of lists option
if (isset($form['options']['sticky'])) {
$form['options']['sticky']['#access'] = FALSE;
}
}
* Implement hook_form_alter().
*/
function phponwebsites_form_alter(&$form, &$form_state, $form_id) {
// to hide promoted to front page option
if (isset($form['options']['promote'])) {
$form['options']['promote']['#access'] = FALSE;
}
// to hide sticky at top of lists option
if (isset($form['options']['sticky'])) {
$form['options']['sticky']['#access'] = FALSE;
}
}
Now you go to article node form and check whether "Promoted to front page" and "Sticky at top of lists" options are hidden or not. You couldn’t see those options in article node form. It should look like below image:
Hide Promoted to front page & Sticky at top of lists options in multiple node forms:
If you want to hide "Promoted to front page" and "Sticky at top of lists" options in all node forms, then you can remove those options using hook_form_BASE_FORM_ID_alter() in drupal 7.
/**
* Implement hook_form_BASE_FORM_ID_alter().
*/
function phponwebsites_form_node_form_alter(&$form, &$form_state, $form_id) {
// to hide promoted to front page option
if (isset($form['options']['promote'])) {
$form['options']['promote']['#access'] = FALSE;
}
// to hide sticky at top of lists option
if (isset($form['options']['sticky'])) {
$form['options']['sticky']['#access'] = FALSE;
}
}
* Implement hook_form_BASE_FORM_ID_alter().
*/
function phponwebsites_form_node_form_alter(&$form, &$form_state, $form_id) {
// to hide promoted to front page option
if (isset($form['options']['promote'])) {
$form['options']['promote']['#access'] = FALSE;
}
// to hide sticky at top of lists option
if (isset($form['options']['sticky'])) {
$form['options']['sticky']['#access'] = FALSE;
}
}
Now you could not see those options in all node forms. Now you know how to hide "Promoted to front page" and "Sticky at top of lists" options from node form in drupal 7.
Thanks. Any idea how to do the same in Drupal 8?
ReplyDeleteProbably, you could use similar hooks to accomplish the same.
Deletehello,
ReplyDeleteyou should test form id. That way, the test is launch once time ;)
Drupaly
kuşadası
ReplyDeletetrabzon
zonguldak
balıkesir
hatay
LFD