3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00

Provide a route for each quick form.

This commit is contained in:
paul121 2021-10-25 13:24:17 -07:00 committed by Michael Stenta
parent b3428fc737
commit ac1679841d
4 changed files with 35 additions and 11 deletions

View file

@ -5,10 +5,6 @@ farm.quick:
_title: 'Quick forms'
requirements:
_permission: 'view quick forms index'
farm.quick.form:
path: '/quick/{id}'
defaults:
_form: 'Drupal\farm_quick\Form\QuickForm'
_title_callback: 'Drupal\farm_quick\Form\QuickForm::getTitle'
requirements:
_custom_access: 'Drupal\farm_quick\Form\QuickForm::access'
route_callbacks:
- 'plugin.manager.quick_form:getRoutes'

View file

@ -48,7 +48,7 @@ class QuickFormController extends ControllerBase {
$quick_forms = $this->quickFormManager->getDefinitions();
$items = [];
foreach ($quick_forms as $quick_form) {
$url = Url::fromRoute('farm.quick.form', ['id' => $quick_form['id']]);
$url = Url::fromRoute('farm.quick.' . $quick_form['id']);
if ($url->access()) {
$items[] = [
'title' => $quick_form['label'],

View file

@ -50,11 +50,11 @@ class QuickFormMenuLink extends DeriverBase implements ContainerDeriverInterface
// Add links for quick form.
$quick_forms = $this->quickFormManager->getDefinitions();
foreach ($quick_forms as $quick_form) {
$links['farm.quick.' . $quick_form['id']] = [
$route_id = 'farm.quick.' . $quick_form['id'];
$links[$route_id] = [
'title' => $quick_form['label'],
'parent' => 'farm.quick',
'route_name' => 'farm.quick.form',
'route_parameters' => ['id' => $quick_form['id']],
'route_name' => $route_id,
] + $base_plugin_definition;
}

View file

@ -5,6 +5,9 @@ namespace Drupal\farm_quick;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\farm_quick\Form\QuickForm;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
/**
* Quick form manager class.
@ -34,4 +37,29 @@ class QuickFormManager extends DefaultPluginManager {
$this->setCacheBackend($cache_backend, 'quick_forms');
}
/**
* Provides routes for quick forms.
*
* @return \Symfony\Component\Routing\RouteCollection
* Returns a route collection.
*/
public function getRoutes(): RouteCollection {
$route_collection = new RouteCollection();
foreach ($this->getDefinitions() as $id => $definition) {
$route = new Route(
"/quick/$id",
[
'_form' => QuickForm::class,
'_title_callback' => QuickForm::class . '::getTitle',
'id' => $id,
],
[
'_custom_access' => QuickForm::class . '::access',
],
);
$route_collection->add("farm.quick.$id", $route);
}
return $route_collection;
}
}