diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 0458d70..03a8851 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormController.php +++ b/core/lib/Drupal/Core/Entity/EntityFormController.php @@ -149,12 +149,8 @@ public function form(array $form, array &$form_state) { field_attach_form($entity, $form, $form_state, $this->getFormLangcode($form_state)); } - // Assign the weights configured in the form display. - foreach ($this->getFormDisplay($form_state)->getComponents() as $name => $options) { - if (isset($form[$name])) { - $form[$name]['#weight'] = $options['weight']; - } - } + // Add a process callback so we can assign weights and hide extra fields. + $form['#process'][] = array($this, 'processForm'); if (!isset($form['langcode'])) { // If the form did not specify otherwise, default to keeping the existing @@ -169,6 +165,31 @@ public function form(array $form, array &$form_state) { } /** + * Process callback: assigns weights and hides extra fields. + * + * @see \Drupal\Core\Entity\EntityFormController::form() + */ + public function processForm($element, $form_state, $form) { + // Assign the weights configured in the form display. + $components = $this->getFormDisplay($form_state)->getComponents(); + foreach ($components as $name => $options) { + if (isset($element[$name])) { + $element[$name]['#weight'] = $options['weight']; + } + } + + // Hide extra fields. + $extra_fields = field_info_extra_fields($this->entity->entityType(), $this->entity->bundle(), 'form'); + foreach ($extra_fields as $extra_field => $info) { + if (!isset($components[$extra_field])) { + $element[$extra_field]['#access'] = FALSE; + } + } + + return $element; + } + + /** * Returns the action form element for the current entity form. */ protected function actionsElement(array $form, array &$form_state) { diff --git a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php index 0c9dabd..bea11bf 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php +++ b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php @@ -31,12 +31,8 @@ public function form(array $form, array &$form_state) { field_attach_form($entity, $form, $form_state, $this->getFormLangcode($form_state)); } - // Assign the weights configured in the form display. - foreach ($this->getFormDisplay($form_state)->getComponents() as $name => $options) { - if (isset($form[$name])) { - $form[$name]['#weight'] = $options['weight']; - } - } + // Add a process callback so we can assign weights and hide extra fields. + $form['#process'][] = array(array($this, 'processForm')); return $form; } diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index 78b75f1..3922825 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -313,9 +313,9 @@ function contact_mail($key, &$message, $params) { * * Add the enable personal contact form to an individual user's account page. * - * @see user_profile_form() + * @see \Drupal\user\ProfileFormController::form() */ -function contact_form_user_profile_form_alter(&$form, &$form_state) { +function contact_form_user_form_alter(&$form, &$form_state) { $form['contact'] = array( '#type' => 'details', '#title' => t('Contact settings'), diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php index 0a7ff40..99008e2 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php @@ -163,7 +163,7 @@ public function createCopy($mode) { public function getComponents() { $result = array(); foreach ($this->content as $name => $options) { - if (!isset($options['visible']) || $options['visible'] === TRUE) { + if (!isset($options['visible']) || $options['visible'] == TRUE) { unset($options['visible']); $result[$name] = $options; } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php index f30fff8..609bd48 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php @@ -124,9 +124,8 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, // Custom display settings. if ($this->mode == 'default') { - $display_modes = $this->getDisplayModes(); - // Only show the settings if there is more than one view mode. - if (count($display_modes) > 1) { + // Only show the settings if there is at least one custom display mode. + if ($display_modes = $this->getDisplayModes()) { $form['modes'] = array( '#type' => 'details', '#title' => t('Custom display settings'), diff --git a/core/modules/overlay/overlay.module b/core/modules/overlay/overlay.module index b158083..ca8ce28 100644 --- a/core/modules/overlay/overlay.module +++ b/core/modules/overlay/overlay.module @@ -99,7 +99,7 @@ function overlay_field_extra_fields() { /** * Implements hook_form_FORM_ID_alter(). */ -function overlay_form_user_profile_form_alter(&$form, &$form_state) { +function overlay_form_user_form_alter(&$form, &$form_state) { $account = $form_state['controller']->getEntity(); if (user_access('access overlay', $account)) { $account_data = Drupal::service('user.data')->get('overlay', $account->id(), 'enabled');