winter/modules/cms/routes.php
Luke Towers 4f80b2bc6f
Make cms.beforeRoute a halting event
This change allows developers to prevent the CMS route from being registered.

An example use case for this is loading the CMS content under a set path prefix by re-registering the CMS route with the appropriate prefix in place. Preventing the registration of the default CMS route is required in order to override the mapping of the controller action to URL (and thus have the Cms::url() helper generate the correct URLs in this example). 

Example:
```php
Route::any('docs/{slug?}', 'Cms\Classes\CmsController@run')->where('slug', '(.*)?')->middleware('web');

Event::listen('cms.beforeRoute', function () {
    $path = Request::path();
    // Disable the CMS routes so that the docs/ route can take over for URL generation
    if (Str::startsWith($path, 'docs')) {
        return false;
    }
});
```
2023-07-06 20:46:40 -06:00

42 lines
958 B
PHP

<?php
Event::listen('system.route', function () {
/**
* Register CMS routes before all user routes.
*/
/**
* @event cms.beforeRoute
* Fires before cms routes get added
*
* Example usage:
*
* Event::listen('cms.beforeRoute', function () {
* // your code here
* });
*
*/
$result = Event::fire('cms.beforeRoute', [], true);
if ($result === false) {
return;
}
/*
* The CMS module handles all URLs that have not already been handled by the other modules & plugins.
*/
Route::any('{slug?}', 'Cms\Classes\CmsController@run')->where('slug', '(.*)?')->middleware('web');
/**
* @event cms.route
* Fires after cms routes get added
*
* Example usage:
*
* Event::listen('cms.route', function () {
* // your code here
* });
*
*/
Event::fire('cms.route');
}, PHP_INT_MIN);