Problem/Motivation

The config update to delete field_c_p_attributes deletes the field and field storage but doesn't remove it from core.entity_view_display.paragraph.civictheme_iframe.default.yml or core.entity_form_display.paragraph.civictheme_iframe.default.yml

Steps to reproduce

  1. Run the original post_update script
  2. Attempt to import config -- this should trigger the errors:
    Configuration <em class="placeholder">core.entity_view_display.paragraph.ci  
      victheme_iframe.default</em> depends on the <em class="placeholder">field.f  
      ield.paragraph.civictheme_iframe.field_c_p_attributes</em> configuration th  
      at will not exist after import. 
    

Proposed resolution

Existing users

Users on 1.12.0 can manually remove the configuration manually (delete the config items in the yaml relating to field_c_p_attributes. A more robust solution for civictheme team to fix is provided below:

Steps to fix

/**
 * Removes 'field_c_p_attributes' from civictheme_iframe paragraph.
 *
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
 * @SuppressWarnings(PHPMD.StaticAccess)
 */
function civictheme_post_update_remove_civictheme_iframe_field_c_p_attributes_2(): string {
  $field_config_name = 'field.field.paragraph.civictheme_iframe.field_c_p_attributes';
  $field_storage_config_name = 'field.storage.paragraph.field_c_p_attributes';

  $config_factory = \Drupal::configFactory();

  // Remove field instance if exists.
  $field_config = $config_factory->getEditable($field_config_name);
  if (!$field_config->isNew()) {
    $field_config->delete();
  }

  // Remove field storage if exists.
  $field_storage_config = $config_factory->getEditable($field_storage_config_name);
  if (!$field_storage_config->isNew()) {
    $field_storage_config->delete();
  }

  // Remove the field from all entity view & form displays.
  $display_config_prefixes = [
    'core.entity_view_display.paragraph.civictheme_iframe',
    'core.entity_form_display.paragraph.civictheme_iframe',
  ];

  /** @var \Drupal\Core\Config\StorageInterface $config_storage */
  $config_storage = \Drupal::service('config.storage');

  foreach ($display_config_prefixes as $prefix) {
    // Get all config names with the prefix.
    $all_config_names = $config_storage->listAll($prefix);
    // Find all possible display configs (including .default and custom displays).
    foreach ($all_config_names as $config_name) {
      if (strpos($config_name, $prefix) === 0) {
        $display_config = $config_factory->getEditable($config_name);
        $display = $display_config->get();
        $changed = FALSE;
        if (isset($display['content']['field_c_p_attributes'])) {
          unset($display['content']['field_c_p_attributes']);
          $changed = TRUE;
        }
        if (isset($display['fields']['field_c_p_attributes'])) {
          unset($display['fields']['field_c_p_attributes']);
          $changed = TRUE;
        }
        if ($changed) {
          $display_config->setData($display);
          $display_config->save();
        }
      }
    }
  }

  return (string) new TranslatableMarkup("Removed civictheme_iframe field 'field_c_p_attributes' from field instance, field storage, and all civictheme_iframe paragraph displays (view and form) if they existed.");
}

Remaining tasks

User interface changes

API changes

Data model changes

Comments

nickgeorgiou created an issue. See original summary.

nickgeorgiou’s picture

Issue summary: View changes
nickgeorgiou’s picture

Issue summary: View changes
nickgeorgiou’s picture

Title: Config update to delete field_c_p_attributes is incomplete » Config update to delete field_c_p_attributes from civictheme_iframe is incomplete
nickgeorgiou’s picture

Issue summary: View changes
richardgaunt’s picture

Version: 1.12.1 » 1.x-dev

Thanks @nick this is great adding to next patch release.

richardgaunt’s picture

Assigned: Unassigned » richardgaunt
Status: Active » Needs review
richardgaunt’s picture

richardgaunt’s picture

Status: Needs review » Reviewed & tested by the community

Tested and deleted content and removed fields correctly.

Thanks @nick.georgiou and @awset

richardgaunt’s picture

Version: 1.x-dev » 1.13.0
Assigned: richardgaunt » Unassigned
Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.