Custom view mode settings are overridden on every feature revert

Created on 23 October 2017, over 6 years ago
Updated 15 January 2024, 5 months ago

I have all message related configuration in my project managed with features module. I noticed that my custom view mode settings are overridden on every feature revert.
This seems be caused by message_notify_field_attach_create_bundle() that doesn't take in account view modes other than 'email subject' and 'email body'; when it save the display settings for the extra fields (message__message_text__0 and message__message_text__1) it override (and delete) the other view modes configuration

/**
 * Implements hook_field_attach_create_bundle().
 *
 * We cannot easily set the the visibilty of extra fields, so we set the
 * bundle settings upon creation of new message bundle.
 */
function message_notify_field_attach_create_bundle($entity_type, $bundle) {
  if ($entity_type != 'message') {
    return;
  }

  $bundle_settings = field_bundle_settings('message', $bundle);
  $display = &$bundle_settings['extra_fields']['display'];

  $visible = array('visible' => TRUE, 'weight' => 0);
  $hidden = array('visible' => FALSE, 'weight' => 0);

  // custom setting are overridden -->
  $display['message__message_text__0'] = array(
    'message_notify_email_subject' => $visible,
    'message_notify_email_body' => $hidden,
  );

  // custom setting are overridden -->
  $display['message__message_text__1'] = array(
    'message_notify_email_subject' => $hidden,
    'message_notify_email_body' => $visible,
  );

  field_bundle_settings('message', $bundle, $bundle_settings);
}

this function should handle only the needed extra fields for the view mode managed by message_notify without override custom configuration

🐛 Bug report
Status

Closed: outdated

Version

2.0

Component

Code

Created by

🇮🇹Italy willzyx

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024