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
- Run the original post_update script
- 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
Comment #2
nickgeorgiou commentedComment #3
nickgeorgiou commentedComment #4
nickgeorgiou commentedComment #5
nickgeorgiou commentedComment #6
richardgaunt commentedThanks @nick this is great adding to next patch release.
Comment #7
richardgaunt commentedComment #8
richardgaunt commentedComment #9
richardgaunt commentedTested and deleted content and removed fields correctly.
Thanks @nick.georgiou and @awset
Comment #10
richardgaunt commented