Created
March 11, 2019 12:41
-
-
Save opi/cdc6735e7a3b9936a206a73596b2d4cd to your computer and use it in GitHub Desktop.
Drupal 8 Custom form mode
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 | |
/** | |
* Implements hook_entity_form_display_alter(). | |
*/ | |
function MY_MODULE_entity_form_display_alter(&$form_display, array $context) { | |
if ($context['entity_type'] == 'node' && $context['bundle'] == 'MY_BUNDLE') { | |
$current_user = \Drupal::currentUser(); | |
if ($current_user->hasPermission('CUSTOM PERMISSION')) { | |
$storage = \Drupal::entityManager()->getStorage('entity_form_display'); | |
$new_form_display = $storage->load('node.MY_BUNDLE.FORM_MODE_ID'); | |
if ($new_form_display) { | |
$form_display = $new_form_display; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment