-
-
Save flocondetoile/167ee660b85c89747fe21bbc2b928187 to your computer and use it in GitHub Desktop.
Drupal 8 Custom form mode
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 | |
/** | |
* 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