Skip to content
Snippets Groups Projects

Issue #3387531: Provide upgrade path for the "current_theme" condition

1 file
+ 51
0
Compare changes
  • Side-by-side
  • Inline
@@ -5,6 +5,8 @@
* Post update functions for the Asset Injector module.
*/
use Drupal\Core\Render\Markup;
/**
* Update node type conditions from "node_type" to "entity_bundle:node".
*/
@@ -38,3 +40,52 @@ function asset_injector_post_update_update_node_type_conditions() {
return NULL;
}
/**
* Attempt to normalize the "current_theme" conditions.
*/
function asset_injector_post_update_normalize_current_theme_conditions() {
$updated_configs = [];
$unsupported_configs = [];
foreach (\Drupal::configFactory()->listAll('asset_injector.') as $asset_injector_config_name) {
$asset_injector_config = \Drupal::configFactory()->getEditable($asset_injector_config_name);
// Load asset injector entities and normalize the "current_theme" condition.
if ($asset_injector_config->get('id') && $asset_injector_config->get('conditions.current_theme')) {
$current_theme = $asset_injector_config->get('conditions.current_theme');
if (isset($current_theme['theme']) && is_array($current_theme['theme'])) {
if (count($current_theme['theme']) < 2) {
$current_theme['theme'] = (string) reset($current_theme['theme']);
$asset_injector_config
->set('conditions.current_theme', $current_theme)
->save(TRUE);
$updated_configs[] = $asset_injector_config_name;
}
else {
$unsupported_configs[] = $asset_injector_config_name;
}
}
}
}
$output = [];
if ($updated_configs) {
$output[] = t('Normalized the "current_theme" condition on %config_names.', [
'%config_names' => implode(', ', $updated_configs),
]);
}
if ($unsupported_configs) {
$output[] = t('Could not normalize the "current_theme" condition on %config_names.', [
'%config_names' => implode(', ', $unsupported_configs),
]);
\Drupal::logger('asset_injector')->warning('Theme conditions are now only limited to a single theme per asset. Please review the theme condition settings for %config_names', [
'%config_names' => implode(', ', $unsupported_configs),
]);
}
if ($output) {
return Markup::create(implode("\n", $output));
}
return NULL;
}
Loading