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
Issue fork civictheme-3441209
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3441209-fix-provisioning
changes, plain diff MR !6
Comments
Comment #2
sonnyktComment #4
sonnyktComment #5
fionamorrison23 commentedComment #6
richardgaunt commentedReviewed and looks good to me.
Comment #8
alex.skrypnykThank you for your contribution, Sonny
All the development takes place in the GitHub repository, so we ported your changes there, which is now available in this repo as https://git.drupalcode.org/project/civictheme/-/commit/a95a07e88e41f2544...
The credit was not added in the commit message accidentally. Apologies for this. This is an oversight. I will add the credit in this issue.
This will be released in 1.8
Comment #9
alex.skrypnyk