Skip to content

Commit

Permalink
now with cofig hack
Browse files Browse the repository at this point in the history
  • Loading branch information
rnsrk committed Dec 19, 2024
1 parent ef46bac commit 7ba109b
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 1 deletion.
123 changes: 123 additions & 0 deletions ConfigConfigurator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php

declare(strict_types=1);

namespace Drupal\Core\Recipe;

use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\StorageInterface;

/**
* @internal
* This API is experimental.
*/
final class ConfigConfigurator {

public readonly ?string $recipeConfigDirectory;

/**
* @param array $config
* Config options for a recipe.
* @param string $recipe_directory
* The path to the recipe.
* @param \Drupal\Core\Config\StorageInterface $active_configuration
* The active configuration storage.
*/
public function __construct(public readonly array $config, string $recipe_directory, StorageInterface $active_configuration) {
$this->recipeConfigDirectory = is_dir($recipe_directory . '/config') ? $recipe_directory . '/config' : NULL;
$recipe_storage = $this->getConfigStorage();
foreach ($recipe_storage->listAll() as $config_name) {
if ($active_data = $active_configuration->read($config_name)) {
// @todo https://www.drupal.org/i/3439714 Investigate if there is any
// generic code in core for this.
unset($active_data['uuid'], $active_data['_core']);
if (empty($active_data['dependencies'])) {
unset($active_data['dependencies']);
}
$recipe_data = $recipe_storage->read($config_name);
if (empty($recipe_data['dependencies'])) {
unset($recipe_data['dependencies']);
}
// Ensure we don't get a false mismatch due to differing key order.
// @todo When https://www.drupal.org/project/drupal/issues/3230826 is
// fixed in core, use that API instead to sort the config data.
self::recursiveSortByKey($active_data);
self::recursiveSortByKey($recipe_data);
#if ($active_data !== $recipe_data) {
# throw new RecipePreExistingConfigException($config_name, sprintf("The configuration '%s' exists already and does not match the recipe's configuration", $config_name));
#}
}
}
}

/**
* Sorts an array recursively, by key, alphabetically.
*
* @param mixed[] $data
* The array to sort, passed by reference.
*
* @todo Remove when https://www.drupal.org/project/drupal/issues/3230826 is
* fixed in core.
*/
private static function recursiveSortByKey(array &$data): void {
// If the array is a list, it is by definition already sorted.
if (!array_is_list($data)) {
ksort($data);
}
foreach ($data as &$value) {
if (is_array($value)) {
self::recursiveSortByKey($value);
}
}
}

/**
* Gets a config storage object for reading config from the recipe.
*
* @return \Drupal\Core\Config\StorageInterface
* The config storage object for reading config from the recipe.
*/
public function getConfigStorage(): StorageInterface {
$storages = [];

if ($this->recipeConfigDirectory) {
// Config provided by the recipe should take priority over config from
// extensions.
$storages[] = new FileStorage($this->recipeConfigDirectory);
}
if (!empty($this->config['import'])) {
/** @var \Drupal\Core\Extension\ModuleExtensionList $module_list */
$module_list = \Drupal::service('extension.list.module');
/** @var \Drupal\Core\Extension\ThemeExtensionList $theme_list */
$theme_list = \Drupal::service('extension.list.theme');
foreach ($this->config['import'] as $extension => $config) {
// If the recipe explicitly does not want to import any config from this
// extension, skip it.
if ($config === NULL) {
continue;
}
$path = match (TRUE) {
$module_list->exists($extension) => $module_list->getPath($extension),
$theme_list->exists($extension) => $theme_list->getPath($extension),
default => throw new \RuntimeException("$extension is not a theme or module")
};
$config = $config === '*' ? [] : $config;
$storages[] = new RecipeExtensionConfigStorage($path, $config);
}
}

return RecipeConfigStorageWrapper::createStorageFromArray($storages);
}

/**
* Determines if the recipe has any config or config actions to apply.
*
* @return bool
* TRUE if the recipe has any config or config actions to apply, FALSE if
* not.
*/
public function hasTasks(): bool {
return $this->recipeConfigDirectory !== NULL || count($this->config);
}

}
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM drupal:11.1.0-rc1-php8.3-apache-bookworm
FROM drupal:11.0.5-php8.3-apache-bookworm

LABEL org.opencontainers.image.source=https://github.com/soda-collections-objects-data-literacy/wisski-base-image.git
LABEL org.opencontainers.image.description="Plain Drupal with preinstalled Site and basic WissKI environment with only core components with connection to triplestore provided by env variables."
Expand Down Expand Up @@ -72,6 +72,9 @@ RUN composer require drush/drush
# add composer bin to PATH
RUN ln -s /opt/drupal/vendor/bin/drush /usr/local/bin/drush

# Add ConfigConfigurator
COPY ConfigConfigurator.php /opt/drupal/ConfigConfigurator.php

# Change ownerships
RUN chown -R www-data:www-data /var/www/html

Expand Down
4 changes: 4 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ else
} 1> /dev/null
echo -e "\033[0;32mDEVELOPMENT MODULES INSTALLED.\033[0m\n"

echo -e "\033[0;33mHACK CONFIGURATION.\033[0m"
mv /opt/drupal/ConfigConfigurator.php /opt/drupal/web/core/lib/Drupal/Core/Recipe/ConfigConfigurator.php
echo -e "\033[0;32mCONFIGURATION HACKED.\033[0m\n"

# Add Drupal Recipe Composer plugin
echo -e "\033[0;33mINSTALL RECIPE COMPOSER PLUGIN.\033[0m"
{
Expand Down

0 comments on commit 7ba109b

Please sign in to comment.