From 3a55bd502b138db013668b6fa2ff6e39d0fac2b9 Mon Sep 17 00:00:00 2001 From: David Wheatley Date: Sun, 12 Dec 2021 01:29:35 +0000 Subject: [PATCH] wip: add `prependNamespace` support --- src/Extend/View.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Extend/View.php b/src/Extend/View.php index 6995f953b..ecc49f7bc 100644 --- a/src/Extend/View.php +++ b/src/Extend/View.php @@ -44,6 +44,8 @@ class View implements ExtenderInterface, LifecycleInterface /** * Override an existing namespace of Laravel views. + * + * **If you're only replacing one or a few views, you probably want to `->prepend()` the new views instead.** * * Views are PHP files that use the Laravel Blade syntax for creation of server-side generated HTML. * Flarum core uses them for error pages, the installer, HTML emails, and the skeletons for the forum and admin sites. @@ -61,12 +63,34 @@ class View implements ExtenderInterface, LifecycleInterface return $this; } + /** + * Extend an existing namespace of Laravel views. + * + * Views are PHP files that use the Laravel Blade syntax for creation of server-side generated HTML. + * Flarum core uses them for error pages, the installer, HTML emails, and the skeletons for the forum and admin sites. + * To replace views within a namespace, you will need to put them in a folder in your extension, and register that folder under an existing namespace. + * + * @param string $namespace: The name of the namespace. + * @param string|string[] $hints: This is a path (or an array of paths) to the folder(s) + * where view files are stored, relative to the extend.php file. + * @return self + */ + public function prepend(string $namespace, $hints): self + { + $this->prependNamespaces[$namespace] = $hints; + + return $this; + } + public function extend(Container $container, Extension $extension = null) { $container->resolving(Factory::class, function (Factory $view) { foreach ($this->namespaces as $namespace => $hints) { $view->addNamespace($namespace, $hints); } + foreach ($this->prependNamespaces as $namespace => $hints) { + $view->prependNamespace($namespace, $hints); + } foreach ($this->replaceNamespaces as $namespace => $hints) { $view->replaceNamespace($namespace, $hints); }