Skip to content

Commit 4f80b2b

Browse files
authored
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; } }); ```
1 parent 0c4d27f commit 4f80b2b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

modules/cms/routes.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
* });
1717
*
1818
*/
19-
Event::fire('cms.beforeRoute');
19+
$result = Event::fire('cms.beforeRoute', [], true);
20+
if ($result === false) {
21+
return;
22+
}
2023

2124
/*
2225
* The CMS module handles all URLs that have not already been handled by the other modules & plugins.

0 commit comments

Comments
 (0)