1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 16:36:47 +02:00

feat: allow replacing of blade template namespaces

This commit is contained in:
David Wheatley
2021-11-19 01:00:33 +00:00
committed by GitHub
parent 7242b18ff0
commit e3f7251073

View File

@@ -17,17 +17,18 @@ use Illuminate\Contracts\View\Factory;
class View implements ExtenderInterface, LifecycleInterface
{
private $namespaces = [];
private $replaceNamespaces = [];
/**
* Register a new namespace of Laravel views.
*
* Views are php files that use the Laravel Blade syntax for creation of server-side generated html.
* 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 create and use views in your extension, you will need to put them in a folder, and register that folder as a namespace.
*
* Views can then be used in your extension by injecting an instance of `Illuminate\Contracts\View\Factory`,
* and calling its `make` method. The `make` method takes the view parameter in the format NAMESPACE::VIEW_NAME.
* You can also pass variables into a view: for more information, see https://laravel.com/api/8.x/Illuminate/View/Factory.html#method_make
* You can also pass variables into a view. For more information, see: https://laravel.com/api/8.x/Illuminate/View/Factory.html#method_make
*
* @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)
@@ -41,12 +42,34 @@ class View implements ExtenderInterface, LifecycleInterface
return $this;
}
/**
* Override 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, 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 replace(string $namespace, $hints): self
{
$this->replaceNamespaces[$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->replaceNamespaces as $namespace => $hints) {
$view->replaceNamespace($namespace, $hints);
}
});
}