Theme content provisioning creates invalid config views.view.civictheme_media

Created on 16 April 2024, 7 months ago
Updated 23 June 2024, 5 months ago

Problem/Motivation

When installing Civictheme via profile, theme content provisioning creates an invalid config for views.view.civictheme_media which causes a fatal error for drush config:import

$ drush config:import
 [success] Config import start.
+------------+-----------------------------+-----------+
| Collection | Config                      | Operation |
+------------+-----------------------------+-----------+
|            | block.block.xxx             | Create    |
|            | ...                         | ...       |
|            | views.view.civictheme_media | Delete    |
+------------+-----------------------------+-----------+

 // Import the listed configuration changes?: yes.                              

>  [error]  Error: Call to a member function setSyncing() on null in Drupal\Core\Config\Entity\ConfigEntityStorage->importDelete() (line 383 of /app/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php) #0 /app/web/core/lib/Drupal/Core/Config/ConfigImporter.php(1059): Drupal\Core\Config\Entity\ConfigEntityStorage->importDelete()
> #1 /app/web/core/lib/Drupal/Core/Config/ConfigImporter.php(842): Drupal\Core\Config\ConfigImporter->importInvokeOwner()
> #2 /app/web/core/lib/Drupal/Core/Config/ConfigImporter.php(663): Drupal\Core\Config\ConfigImporter->processConfiguration()
> #3 /app/web/core/lib/Drupal/Core/Config/ConfigImporter.php(561): Drupal\Core\Config\ConfigImporter->processConfigurations()
> #4 /app/vendor/drush/drush/src/Commands/config/ConfigImportCommands.php(259): Drupal\Core\Config\ConfigImporter->doSyncStep()
> #5 /app/vendor/drush/drush/includes/drush.inc(62): Drush\Commands\config\ConfigImportCommands->doImport()
> #6 /app/vendor/drush/drush/includes/drush.inc(53): drush_call_user_func_array()

Analysis

The function civictheme_provision__media_view() is responsible for creating the said config and it has an incorrect usage of \Drupal::configFactory()->getEditable()


  // Enable the 'views.view.civictheme_media' view.
  \Drupal::configFactory()
    ->getEditable('views.view.civictheme_media')
    ->set('status', TRUE)
    ->save();

When the config does not exist, getEditable() returns an empty ImmutableConfig object and saving the object will cause an invalid config that cannot be removed by config:import.

Proposed resolution

  // Enable the 'views.view.civictheme_media' view.
  $config = \Drupal::configFactory()
    ->getEditable('views.view.civictheme_media');
  if (!$config->isNew()) {
    $config->set('status', TRUE)
      ->save();

Remaining tasks

User interface changes

API changes

N/A

Data model changes

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇦🇺Australia sonnykt Melbourne, Australia

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