From f6fb3a13a4f1c8a85b242e1ca5269d60b86ed1fe Mon Sep 17 00:00:00 2001 From: Evan Willhite Date: Thu, 6 Sep 2018 14:16:19 -0500 Subject: [PATCH] paths dependent on install --- pl_attach-library.function.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pl_attach-library.function.php b/pl_attach-library.function.php index 3e02ee6..b2bd3b3 100644 --- a/pl_attach-library.function.php +++ b/pl_attach-library.function.php @@ -14,6 +14,17 @@ $yamlFile = glob('*.libraries.yml'); $yamlOutput = Yaml::parseFile($yamlFile[0]); + $directoryPath = explode('/', dirname(__FILE__)); + + $rootPathString = ''; + // If the themes directory is in the path (Drupal). + if (in_array('themes', $directoryPath)) { + $rootPathLocation = array_search('themes', $directoryPath); + $themePathOffset = -1 * (count($directoryPath) - array_search('components', $directoryPath)); + $rootPath = array_slice($directoryPath, $rootPathLocation, $themePathOffset, true); + $rootPathString = implode('/', $rootPath) . '/'; + } + // For each item in .libraries.yml file. foreach($yamlOutput as $key => $value) { @@ -22,7 +33,7 @@ $files = $yamlOutput[$key]['js']; // For each file, create an async script to insert to the Twig component. foreach($files as $key => $jsPath) { - $scriptString = ''; + $scriptString = ''; $stringLoader = \PatternLab\Template::getStringLoader(); $output = $stringLoader->render(array("string" => $scriptString, "data" => [])); return $output;