Installing site from existing config fails when message_digest_ui module is part of the install

Created on 18 July 2023, over 1 year ago

Problem/Motivation

When installing a site from existing configuration (we do this for platform applications), and message_digest_ui is installed as part of that, the installation fails with the following error (both installing through Drush and through the browser UI):

 You are about to:
 * DROP all tables in your 'db' database.

 // Do you want to continue?: yes.                                                                                      

 [notice] Starting Drupal installation. This takes a while.
 [notice] Performed install task: install_select_language
 [notice] Performed install task: install_select_profile
 [notice] Performed install task: install_load_profile
 [notice] Performed install task: install_verify_requirements
 [notice] Performed install task: install_verify_database_ready
 [notice] Performed install task: install_base_system
 [notice] Performed install task: install_bootstrap_full

In EntityType.php line 885:
                                                                  
  Missing bundle entity, entity type flag, entity id email_node.

Steps to reproduce

  1. Setup a Drupal Composer project.
  2. Add a config sync directory and set the absolute path to this as the value for $settings['config_sync_directory'] in settings.php.
  3. composer require drupal/message_digest
  4. drush si minimal -y --no-interaction
  5. drush en taxonomy
  6. drush en message_digest_ui -y --no-interaction
  7. drush cex -y
  8. drush si --existing-config -y --no-interaction
  9. Confirm the error above.

The error stems from the message_digest_ui_install(), lines 27-41:

  // Add the `message_digest` field to flagging types.
  $prefix = \Drupal::config('message_subscribe_email.settings')->get('flag_prefix');
  foreach (['node', 'term', 'user'] as $name) {
    $display = \Drupal::service('entity_display.repository')->getFormDisplay('flagging', $prefix . '_' . $name, 'default');
    if (!$display->getComponent('message_digest')) {
      $settings = [
        'type' => 'options_select',
        'weight' => 0,
        'region' => 'content',
        'settings' => [],
        'third_party_settings' => [],
      ];
      $display->setComponent('message_digest', $settings);
      $display->save();
    }
  }

Assuming that $prefix = 'email';, the issue here is the flagging bundles email_node, email_taxonomy, and email_user do not exist yet during a fresh install from configuration, and so it blows up when you try to save a new form display configuration for a bundle that does not exist.

Proposed resolution

I'm not sure what the best path is yet, but initial thoughts are to improve module code to account for this possibility.

I took an initial stab at seeing what would happen if I leveraged the $is_syncing argument, and immediately return from the method if it is TRUE. The result was a bunch of errors when plugins are generated that look like this:

 [error]  Unexpected error during import with operation create for system.action.message_digest_interval.email_node.daily: The "message_digest_interval:email_node:daily" plugin does not exist. Valid plugin IDs for Drupal\Core\Action\ActionManager are: flag_delete_flagging, flag_action:email_node_flag, flag_action:email_node_unflag, flag_action:subscribe_node_flag, flag_action:subscribe_node_unflag, message_delete_action, message_digest_interval:email_node:immediate, message_digest_interval:email_term:immediate, message_digest_interval:email_user:immediate, node_unpublish_by_keyword_action, node_make_sticky_action, node_assign_owner_action, node_unpromote_action, node_make_unsticky_action, node_promote_action, user_remove_role_action, user_add_role_action, user_block_user_action, user_cancel_user_action, user_unblock_user_action, action_send_email_action, entity:delete_action:node, entity:publish_action:node, entity:publish_action:path_alias, entity:publish_action:taxonomy_term, action_message_action, entity:unpublish_action:node, entity:unpublish_action:path_alias, entity:unpublish_action:taxonomy_term, action_goto_action, entity:save_action:node, entity:save_action:taxonomy_term, entity:save_action:user
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇺🇸United States lpeabody

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024