Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save junaidpv/db0b973456e1a49cc639986fadc857ea to your computer and use it in GitHub Desktop.
Save junaidpv/db0b973456e1a49cc639986fadc857ea to your computer and use it in GitHub Desktop.
Modify the config_split module Folder storage option to look relative to the site directory instead of Drupal root.
diff --git a/src/ConfigSplitManager.php b/src/ConfigSplitManager.php
index 575680e..a85a2f0 100644
--- a/src/ConfigSplitManager.php
+++ b/src/ConfigSplitManager.php
@@ -512,7 +512,7 @@ protected function getSplitStorage(ImmutableConfig $config, StorageInterface $tr
}
if ('folder' === $storage) {
// Here we could determine to use relative paths etc.
- $directory = $config->get('folder');
+ $directory = \Drupal::getContainer()->getParameter('site.path') . '/' . $config->get('folder');
if (!is_dir($directory)) {
// If the directory doesn't exist, attempt to create it.
// This might have some negative consequences, but we trust the user to
diff --git a/src/Form/ConfigSplitEntityForm.php b/src/Form/ConfigSplitEntityForm.php
index f21da51..23f52c4 100644
--- a/src/Form/ConfigSplitEntityForm.php
+++ b/src/Form/ConfigSplitEntityForm.php
@@ -446,7 +446,7 @@ public function save(array $form, FormStateInterface $form_state) {
]));
}
$folder = $form_state->getValue('folder');
- if ($form_state->getValue('storage') === 'folder' && !empty($folder) && !file_exists($folder)) {
+ if ($form_state->getValue('storage') === 'folder' && !empty($folder) && !file_exists(\Drupal::getContainer()->getParameter('site.path') . '/' . $folder)) {
$this->messenger()->addWarning(
$this->t('The storage path "%path" for %label Configuration Split setting does not exist. Make sure it exists and is writable.',
[
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment