Created
September 20, 2017 06:13
-
-
Save sumanthkumarc/3400d2a8d23b16e5f64eab276330c5ed to your computer and use it in GitHub Desktop.
Drupal 8: Altering the actions available for a node form, either add or edit.
This file contains hidden or 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 | |
function hook_MY_MODULE_form_alter(){ | |
// Altering the actions available for a node form, either add or edit. | |
$build_info = $form_state->getBuildInfo(); | |
if (isset($build_info['base_form_id']) && $build_info['base_form_id'] == 'node_form') { | |
$form_object = $form_state->getFormObject(); | |
$entity = $form_object->getEntity(); | |
$bundle = $entity->bundle(); | |
// Any bundle key added here, will have unpublish option, else action is removed. | |
$allowed_bundles = [ | |
'article', | |
]; | |
if (!in_array($bundle, $allowed_bundles)) { | |
unset($form['actions']['unpublish']); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment