I am attempting to get multi-site working (sub_directory) and have implemented setup.php. In this case, I am sharing the themes and plugins between the multiple sites, located in user/sites. The setup.php is being called, I can see output in my browser.
Here’s the setup.php. I’ve added php logging to the browser console so I can see what’s going on.
<?php
/**
* Multisite setup for sub-directories or path based
* URLs for subsites.
*
* DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING!
*
* Modified Sept 2020 to share themes and plugins folders across
* subsites.
*/
function console_log($output, $with_script_tags = true) {
$js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) .
');';
if ($with_script_tags) {
$js_code = '<script>' . $js_code . '</script>';
}
echo $js_code;
}
use Grav\Common\Filesystem\Folder;
// Get relative path from Grav root.
$path = isset($_SERVER['PATH_INFO'])
? $_SERVER['PATH_INFO']
: Folder::getRelativePath($_SERVER['REQUEST_URI'], ROOT_DIR);
// Extract name of subsite from path
$name = Folder::shift($path);
$folder = "sites/{$name}";
$prefix = "/{$name}";
console_log("subsite info:");
console_log("path: {$path}");
console_log("name: {$name}");
console_log("folder: {$folder}");
console_log("user/folder: user/{$folder}");
console_log("prefix: {$prefix}");
if (!$name || !is_dir(ROOT_DIR . "user/{$folder}")) {
console_log("\$name is not defined for \$folder does not exist");
return [];
}
// Prefix all pages with the name of the subsite
$container['pages']->base($prefix);
// default paths for themes and plugins
$themes = ["user/themes"];
$plugins = ["user/plugins"];
// is there a themes folder in the subsite?
// if so, prepend default array with subsite themes path
//if (is_dir(__DIR__ . "/user/{$folder}/themes")) {
// array_unshift($themes, "user/{$folder}/themes");
//}
// is there a plugins folder in the subsite?
// if so, prepend default array with subsite plugins path
//if (is_dir(__DIR__ . "/user/{$folder}/plugins")) {
// array_unshift($plugins, "user/{$folder}/plugins");
//}
$retval = [
'environment' => $environment,
'streams' => [
'schemes' => [
'user' => [
'type' => 'ReadOnlyStream',
'prefixes' => [
'' => ["user/{$folder}"],
]
],
// set theme path for subsite
'themes' => [
'type' => 'ReadOnlyStream',
'prefixes' => ['' => $themes]
],
// set plugins path for subsite
'plugins' => [
'type' => 'ReadOnlyStream',
'prefixes' => ['' => $plugins]
]
]
]
];
$msg = print_r($retval, true);
console_log("returned: {$msg}");
return $retval;
And here is my console output from what is returned.
returned: Array
(
[environment] => <mywebsite url>
[streams] => Array
(
[schemes] => Array
(
[user] => Array
(
[type] => ReadOnlyStream
[prefixes] => Array
(
[] => Array
(
[0] => user/sites/actin5
)
)
)
[themes] => Array
(
[type] => ReadOnlyStream
[prefixes] => Array
(
[] => Array
(
[0] => user/themes
)
)
)
[plugins] => Array
(
[type] => ReadOnlyStream
[prefixes] => Array
(
[] => Array
(
[0] => user/plugins
)
)
)
)
)
)
It looks good, but I get these errors, as if the stream mapping is not working.
Any ideas as to what I’m missing or doing wrong?