From 1608388efa865526371bcaa9cc7eb9849db7a659 Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Tue, 24 Oct 2017 14:11:48 -0700 Subject: [PATCH] Issue #2915036 by Dane Powell: Fixed view modes not updating in response to new fields. --- core/modules/field/field.module | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 1a18b91d73..c461efa499 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -347,6 +347,39 @@ function field_form_config_admin_import_form_alter(&$form, FormStateInterface $f } } +/** + * Allow other view modes to update their configuration for the new field. + */ +function _field_update_display_modes(FieldStorageConfigInterface $field_storage) { + $entity_type_id = $field_storage->getTargetEntityTypeId(); + + $view_modes = \Drupal::entityManager()->getViewModes($entity_type_id); + $form_modes = \Drupal::entityManager()->getFormModes($entity_type_id); + foreach ($field_storage->getBundles() as $bundle) { + // Update view modes. + foreach ($view_modes as $view_mode_id => $view_mode) { + if ($view_mode['status']) { + entity_get_display($entity_type_id, $bundle, $view_mode_id) + ->save(); + } + } + // Update form modes. + foreach ($form_modes as $form_mode_id => $form_mode) { + if ($form_mode['status']) { + entity_get_form_display($entity_type_id, $bundle, $form_mode_id) + ->save(); + } + } + } +} + +/** + * Implements hook_ENTITY_TYPE_insert() for 'field_storage_config'. + */ +function field_field_storage_config_insert(FieldStorageConfigInterface $field_storage) { + _field_update_display_modes($field_storage); +} + /** * Implements hook_ENTITY_TYPE_update() for 'field_storage_config'. * @@ -379,6 +412,8 @@ function field_field_storage_config_update(FieldStorageConfigInterface $field_st $field->save(); } } + + _field_update_display_modes($field_storage); } /** -- 2.14.1