Problem/Motivation

Uncaught PHP Exception InvalidArgumentException: "The configuration property conditions.current_theme.theme.olivero doesn't exist." at ... /core/lib/Drupal/Core/Config/Schema/ArrayElement.php line 76

Steps to reproduce

Select any Theme under "configuration" while trying to save a custom CSS ... apparently the Theme does not exist.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Carlo created an issue. See original summary.

Carlo’s picture

Issue summary: View changes
pookmish’s picture

Title: Theme doesn't exist » Fatal error: Schema error for theme condition selection field
Priority: Normal » Major

Bumping this to major. It is a problem with Drupal core 9.5 and 10.0.0. The issue does not exist in Drupal <= 9.4.9.

This seems to be a problem perhaps due to a change in the theme condition plugin schema and/or the ability to choose multiple themes in the condition. By forcing the form to only single theme selection, the form no longer errors.

There might be two solutions to this:
1. alter the schema of the core theme plugin, but only when it's saved in the asset injector config. This would prevent the need for an update hook
2. Keep the schema from core and limit the theme selection to single select. This would likely require a db update to duplicate any assets that have multiple themes configured.

pookmish’s picture

Version: 8.x-2.13 » 8.x-2.x-dev

Caused by #2787529: Missing configuration schema for current_theme condition plugin. It seems that Drupal 9.4.9 didn't actually have any schema for the theme condition plugin which is why there was no failure in the that version or prior. The schema was added 2 weeks ago which also explains why the error didn't pop up sooner in D10 compatibility review.

I will attempt to resolve this in the near future if nobody is able to assist.

pookmish’s picture

As it appears, existing assets do not break in their functionality after updating Drupal core. The issue only exists when attempting to save the asset. The solution I think is best would be to present a warning to the user on the edit form for any assets that are configured for 2+ themes. If an asset condition is configured for only 1 theme, no issue exists when saving.

If an asset is configured for two themes, it's the recommendation to duplicate the asset and set the appropriate theme for each asset.

  • pookmish committed 76a9b482 on 8.x-2.x
    Issue #3329577: Fatal error: Schema error for theme condition selection...
pookmish’s picture

Status: Active » Fixed
eswiderski’s picture

This also happens with 1 theme.

pookmish’s picture

It did result in an error when saving with 1 or more themes chosen. There were no errors with any number of themes chosen when simply using the assets (ie no WSOD when viewing your node pages etc). The error only occurred when editing/adding an asset. The latest version of the module should fix the error. Please update to fix the issue.

eswiderski’s picture

@pookmish confirmed, updated to latest release and saves without errors now. Thanks!

Status: Fixed » Closed (fixed)

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

aleix’s picture

Just note that it also happens to me when using config_inspector module and going to /admin/reports/config-inspector:
The configuration property conditions.current_theme.theme.claro doesn't exist.
Upgrading as pookmish says and resaving all assets (2 in my case) fixes this.

Also reported in https://www.drupal.org/project/config_inspector/issues/3359846#comment-1...

codebymikey’s picture

A database upgrade hook would've been ideal here to normalize the asset injector configs which have just a single theme as well as warn users about asset injector entries with multiple themes which needed addressing, removing any manual legwork.

edit: Also, wouldn't it be easier to create an asset_injector condition based on core that supports multiple themes and then migrate across to it similar to #3375026: Provide upgrade path for the "node_type" condition

Example post update hook:


/**
 * Resave asset injector CSS.
 */
function asset_injector_post_update_resave_asset_injector_css(&$sandbox) {
  \Drupal::classResolver(\Drupal\Core\Config\Entity\ConfigEntityUpdater::class)->update($sandbox, 'asset_injector_css', '_asset_injector_update_default_theme');
}

/**
 * Resave asset injector JS.
 */
function asset_injector_post_update_resave_asset_injector_js(&$sandbox) {
  \Drupal::classResolver(\Drupal\Core\Config\Entity\ConfigEntityUpdater::class)->update($sandbox, 'asset_injector_js', '_asset_injector_update_default_theme');
}

function _asset_injector_update_default_theme(\Drupal\asset_injector\AssetInjectorInterface $asset_injector) {
  $condition_collections = $asset_injector->getConditionsCollection();
  if ($condition_collections->has('current_theme')) {
    $current_theme = $asset_injector->getConditionsInstance('current_theme');
    $configuration = $current_theme->getConfiguration();
    if (isset($configuration['theme']) && is_array($configuration['theme'])) {
      if (count($configuration['theme']) < 2) {
        $configuration['theme'] = (string) reset($configuration['theme']);
        $current_theme->setConfiguration($configuration);
        return TRUE;
      }

      \Drupal::logger('asset_injector')->warning('Theme conditions are now only limited to a single theme per asset. Please review the theme condition settings on the @asset_injector_type: %asset_injector_id.', [
        '@asset_injector_type' => $asset_injector->getEntityType()->getLabel(),
        '%asset_injector_id' => $asset_injector->id(),
      ]);
    }
  }
  return FALSE;
}