mirror of
https://github.com/flarum/core.git
synced 2025-08-17 13:54:18 +02:00
feat: Use an extensible document title driver implementation (#3109)
* feat: Use an extensible document title driver implementation * chore: Add todo to use DI in 2.0
This commit is contained in:
@@ -35,6 +35,7 @@ class Frontend implements ExtenderInterface
|
||||
private $removedRoutes = [];
|
||||
private $content = [];
|
||||
private $preloadArrs = [];
|
||||
private $titleDriver;
|
||||
|
||||
/**
|
||||
* @param string $frontend: The name of the frontend.
|
||||
@@ -159,12 +160,23 @@ class Frontend implements ExtenderInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new title driver to change the title of frontend documents.
|
||||
*/
|
||||
public function title(string $driverClass): self
|
||||
{
|
||||
$this->titleDriver = $driverClass;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function extend(Container $container, Extension $extension = null)
|
||||
{
|
||||
$this->registerAssets($container, $this->getModuleName($extension));
|
||||
$this->registerRoutes($container);
|
||||
$this->registerContent($container);
|
||||
$this->registerPreloads($container);
|
||||
$this->registerTitleDriver($container);
|
||||
}
|
||||
|
||||
private function registerAssets(Container $container, string $moduleName): void
|
||||
@@ -295,4 +307,13 @@ class Frontend implements ExtenderInterface
|
||||
{
|
||||
return $extension ? $extension->getId() : 'site-custom';
|
||||
}
|
||||
|
||||
private function registerTitleDriver(Container $container): void
|
||||
{
|
||||
if ($this->titleDriver) {
|
||||
$container->extend('flarum.frontend.title_driver', function ($driver, Container $container) {
|
||||
return $container->make($this->titleDriver);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user