Introduce new Cms helper
This is modeled after the Backend helper. Primarily used to generate URLs for the frontend, these are piped through the CmsController action. It would also be a good place to add a hook, if necessary later.
This commit is contained in:
parent
3698f13acb
commit
c8d8d4e931
|
|
@ -7,9 +7,7 @@ class Backend extends Facade
|
|||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* Resolves to:
|
||||
* - Backend\Helpers\Backend
|
||||
*
|
||||
* @see \Backend\Helpers\Backend
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ use Backend\Classes\Skin;
|
|||
* Backend Helper
|
||||
*
|
||||
* @package october\backend
|
||||
* @see \Backend\Facades\Backend
|
||||
* @author Alexey Bobkov, Samuel Georges
|
||||
*/
|
||||
class Backend
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
<?php namespace Cms\Classes;
|
||||
|
||||
use Cms;
|
||||
use Url;
|
||||
use Str;
|
||||
use App;
|
||||
use File;
|
||||
use View;
|
||||
use Lang;
|
||||
use Route;
|
||||
use Event;
|
||||
use Config;
|
||||
use Session;
|
||||
|
|
@ -1124,19 +1124,7 @@ class Controller
|
|||
return null;
|
||||
}
|
||||
|
||||
if (substr($url, 0, 1) == '/') {
|
||||
$url = substr($url, 1);
|
||||
}
|
||||
|
||||
$routeAction = 'Cms\Classes\CmsController@run';
|
||||
$actionExists = Route::getRoutes()->getByAction($routeAction) !== null;
|
||||
|
||||
if ($actionExists) {
|
||||
return Url::action($routeAction, ['slug' => $url]);
|
||||
}
|
||||
else {
|
||||
return Url::to($url);
|
||||
}
|
||||
return Cms::url($url);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
<?php namespace Cms\Facades;
|
||||
|
||||
use October\Rain\Support\Facade;
|
||||
|
||||
class Cms extends Facade
|
||||
{
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @see \Cms\Helpers\Cms
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'cms.helper';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?php namespace Cms\Helpers;
|
||||
|
||||
use Url;
|
||||
use Route;
|
||||
|
||||
/**
|
||||
* CMS Helper
|
||||
*
|
||||
* @package october\cms
|
||||
* @see \Cms\Facades\Cms
|
||||
* @author Alexey Bobkov, Samuel Georges
|
||||
*/
|
||||
class Cms
|
||||
{
|
||||
protected static $actionExists = null;
|
||||
|
||||
/**
|
||||
* Returns a URL in context of the Frontend
|
||||
*/
|
||||
public function url($path = null)
|
||||
{
|
||||
$routeAction = 'Cms\Classes\CmsController@run';
|
||||
|
||||
if (self::$actionExists === null) {
|
||||
self::$actionExists = Route::getRoutes()->getByAction($routeAction) !== null;
|
||||
}
|
||||
|
||||
if (substr($path, 0, 1) == '/') {
|
||||
$path = substr($path, 1);
|
||||
}
|
||||
|
||||
if (self::$actionExists) {
|
||||
return Url::action($routeAction, ['slug' => $path]);
|
||||
}
|
||||
else {
|
||||
return Url::to($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -94,6 +94,10 @@ class ServiceProvider extends ModuleServiceProvider
|
|||
*/
|
||||
protected function registerSingletons()
|
||||
{
|
||||
App::singleton('cms.helper', function () {
|
||||
return new \Cms\Helpers\Cms;
|
||||
});
|
||||
|
||||
App::singleton('backend.helper', function () {
|
||||
return new \Backend\Helpers\Backend;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ return [
|
|||
'Twig' => October\Rain\Support\Facades\Twig::class,
|
||||
'DbDongle' => October\Rain\Support\Facades\DbDongle::class,
|
||||
'Schema' => October\Rain\Support\Facades\Schema::class,
|
||||
'Cms' => Cms\Facades\Cms::class,
|
||||
'Backend' => Backend\Facades\Backend::class,
|
||||
'BackendMenu' => Backend\Facades\BackendMenu::class,
|
||||
'BackendAuth' => Backend\Facades\BackendAuth::class,
|
||||
|
|
|
|||
Loading…
Reference in New Issue