diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php index 8fe73cb..88e6ce5 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php @@ -46,6 +46,13 @@ public $targetEntityType; /** + * The bundles for which this view mode is enabled or not. + * + * @var array + */ + public $targetBundles = array(); + + /** * Whether or not this form or view mode has custom settings by default. * * If FALSE, entities displayed in this mode will reuse the 'default' display diff --git a/core/modules/field/field.module b/core/modules/field/field.module index c355e67..f9530dc 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -455,54 +455,6 @@ function field_sync_field_status() { } /** - * Gets or sets administratively defined bundle settings. - * - * @param string $entity_type - * The type of $entity; e.g., 'node' or 'user'. - * @param string $bundle - * The bundle name. - * @param array|null $settings - * (optional) The settings to store, an associative array with the following - * elements: - * - view_modes: An associative array keyed by view mode, with the following - * key/value pairs: - * - status: Boolean specifying whether the view mode uses a dedicated set - * of display options (TRUE), or the 'default' options (FALSE). Defaults - * to FALSE. - * - extra_fields: An associative array containing the form and display - * settings for extra fields (also known as pseudo-fields): - * - form: An associative array whose keys are the names of extra fields, - * and whose values are associative arrays with the following elements: - * - weight: The weight of the extra field, determining its position on an - * entity form. - * - display: An associative array whose keys are the names of extra fields, - * and whose values are associative arrays keyed by the name of view - * modes. This array must include an item for the 'default' view mode. - * Each view mode sub-array contains the following elements: - * - weight: The weight of the extra field, determining its position when - * an entity is viewed. - * - visible: TRUE if the extra field is visible, FALSE otherwise. - * - * @return array|null - * If no $settings are passed, the current settings are returned. - */ -function field_bundle_settings($entity_type, $bundle, $settings = NULL) { - if (isset($settings)) { - variable_set('field_bundle_settings_' . $entity_type . '__' . $bundle, $settings); - field_info_cache_clear(); - } - else { - $settings = variable_get('field_bundle_settings_' . $entity_type . '__' . $bundle, array()); - $settings += array( - 'view_modes' => array(), - 'form_modes' => array(), - ); - - return $settings; - } -} - -/** * Returns form mode settings in a given bundle. * * @param string $entity_type @@ -520,8 +472,6 @@ function field_form_mode_settings($entity_type, $bundle) { $cache = &drupal_static(__FUNCTION__, array()); if (!isset($cache[$entity_type][$bundle])) { - $bundle_settings = field_bundle_settings($entity_type, $bundle); - $settings = $bundle_settings['form_modes']; // Include form modes for which nothing has been stored yet, but whose // definition in hook_entity_info_alter() specify they should use custom // settings by default. @@ -555,16 +505,18 @@ function field_view_mode_settings($entity_type, $bundle) { $cache = &drupal_static(__FUNCTION__, array()); if (!isset($cache[$entity_type][$bundle])) { - $bundle_settings = field_bundle_settings($entity_type, $bundle); - $settings = $bundle_settings['view_modes']; - // Include view modes for which nothing has been stored yet, but whose - // definition in hook_entity_info_alter() specify they should use custom - // settings by default. + $settings = array(); $view_modes = entity_get_view_modes($entity_type); foreach ($view_modes as $view_mode => $view_mode_info) { - if (!isset($settings[$view_mode]['status']) && $view_mode_info['status']) { + if (isset($view_mode_info['targetBundles'][$bundle])) { + $settings[$view_mode]['status'] = $view_mode_info['targetBundles'][$bundle]; + } + else if ($view_mode_info['status']) { $settings[$view_mode]['status'] = TRUE; } + else { + $settings[$view_mode]['status'] = FALSE; + } } $cache[$entity_type][$bundle] = $settings; } diff --git a/core/modules/field/lib/Drupal/field/FieldInfo.php b/core/modules/field/lib/Drupal/field/FieldInfo.php index 2639c25..18cf72b 100644 --- a/core/modules/field/lib/Drupal/field/FieldInfo.php +++ b/core/modules/field/lib/Drupal/field/FieldInfo.php @@ -607,24 +607,8 @@ public function prepareInstance($instance, $field_type) { * The list of extra fields completed for the current runtime context. */ public function prepareExtraFields($extra_fields, $entity_type, $bundle) { - $entity_type_info = entity_get_info($entity_type); - $bundle_settings = field_bundle_settings($entity_type, $bundle); $extra_fields += array('form' => array(), 'display' => array()); - - $result = array(); - // Extra fields in forms. - foreach ($extra_fields['form'] as $name => $field_data) { - $settings = isset($bundle_settings['extra_fields']['form'][$name]) ? $bundle_settings['extra_fields']['form'][$name] : array(); - if (isset($settings['weight'])) { - $field_data['weight'] = $settings['weight']; - } - $result['form'][$name] = $field_data; - } - - // Extra fields in displayed entities. - $result['display'] = $extra_fields['display']; - - return $result; + return $extra_fields; } } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php index 841c056..3ea66fa 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php @@ -147,9 +147,11 @@ protected function getDisplayModeSettings() { * {@inheritdoc} */ protected function saveDisplayModeSettings($display_mode_settings) { - $bundle_settings = field_bundle_settings($this->entity_type, $this->bundle); - $bundle_settings['view_modes'] = NestedArray::mergeDeep($bundle_settings['view_modes'], $display_mode_settings); - field_bundle_settings($this->entity_type, $this->bundle, $bundle_settings); + foreach ($display_mode_settings as $view_mode => $status) { + $entity_view_mode = entity_load('view_mode', $this->entity_type . '.' . $view_mode); + $entity_view_mode->targetBundles[$this->bundle] = $status; + $entity_view_mode->save(); + } } /** 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 8e727a6..40ee948 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php @@ -512,7 +512,7 @@ public function submitForm(array &$form, array &$form_state) { $path = $this->getOverviewPath($mode); drupal_set_message(t('The %display_mode mode now uses custom display settings. You might want to configure them.', array('%display_mode' => $display_mode_label, '@url' => url($path)))); } - $display_mode_bundle_settings[$mode]['status'] = !empty($value); + $display_mode_bundle_settings[$mode] = !empty($value); } // Save updated bundle settings. diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php index d2ab86a..4bc48b7 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php @@ -107,9 +107,11 @@ protected function getDisplayModeSettings() { * {@inheritdoc} */ protected function saveDisplayModeSettings($display_mode_settings) { - $bundle_settings = field_bundle_settings($this->entity_type, $this->bundle); - $bundle_settings['form_modes'] = NestedArray::mergeDeep($bundle_settings['form_modes'], $display_mode_settings); - field_bundle_settings($this->entity_type, $this->bundle, $bundle_settings); + foreach ($display_mode_settings as $form_mode => $status) { + $entity_form_mode = entity_load('form_mode', $this->entity_type . '.' . $form_mode); + $entity_form_mode->targetBundles[$this->bundle] = $status; + $entity_form_mode->save(); + } } /**