Quick form actions cause RouteNotFoundException: Route farm.quick.[id] does not exist. #727
Revert "Refactor quick form route building to a single route"
This reverts commit 3505e80124
.
This commit is contained in:
parent
6ed8f3ccec
commit
96b6002f5d
|
@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
- [Fix asset_lookup and term_lookup exception messages #731](https://github.com/farmOS/farmOS/pull/731)
|
||||
- [Prevent saving invalid ID tag types #725](https://github.com/farmOS/farmOS/issues/725)
|
||||
- [Quick form actions cause RouteNotFoundException: Route farm.quick.[id] does not exist. #727](https://github.com/farmOS/farmOS/issues/727)
|
||||
|
||||
## [2.2.0] 2023-10-06
|
||||
|
||||
|
|
|
@ -1,9 +1,2 @@
|
|||
farm_quick.quick_form:
|
||||
title: Quick Form
|
||||
route_name: farm_quick.quick_form
|
||||
base_route: farm_quick.quick_form
|
||||
|
||||
farm_quick.configure:
|
||||
title: Configure
|
||||
route_name: farm_quick.configure
|
||||
base_route: farm_quick.quick_form
|
||||
farm.quick:
|
||||
deriver: Drupal\farm_quick\Plugin\Derivative\QuickFormTaskLink
|
||||
|
|
|
@ -20,9 +20,12 @@ function farm_quick_help($route_name, RouteMatchInterface $route_match) {
|
|||
}
|
||||
|
||||
// Load help text for individual quick forms.
|
||||
if ($route_name == 'farm_quick.quick_form') {
|
||||
if (($quick_form_id = $route_match->getParameter('quick_form')) && $quick_form = \Drupal::service('quick_form.instance_manager')->getInstance($quick_form_id)) {
|
||||
if ($help_text = $quick_form->getHelpText()) {
|
||||
if (strpos($route_name, 'farm.quick.') === 0) {
|
||||
$quick_form_id = $route_match->getParameter('id');
|
||||
if ($route_name == 'farm.quick.' . $quick_form_id) {
|
||||
$quick_form = \Drupal::service('quick_form.instance_manager')->getInstance($quick_form_id);
|
||||
$help_text = $quick_form->getHelpText();
|
||||
if (!empty($help_text)) {
|
||||
$output .= '<p>' . $help_text . '</p>';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,18 +6,6 @@ farm.quick:
|
|||
requirements:
|
||||
_permission: 'view quick_form'
|
||||
|
||||
farm_quick.quick_form:
|
||||
path: /quick/{quick_form}
|
||||
defaults:
|
||||
_form: \Drupal\farm_quick\Form\QuickForm
|
||||
_title_callback: \Drupal\farm_quick\Form\QuickForm::getTitle
|
||||
requirements:
|
||||
_custom_access: \Drupal\farm_quick\Form\QuickForm::access
|
||||
options:
|
||||
parameters:
|
||||
quick_form:
|
||||
type: string
|
||||
|
||||
farm_quick.configure:
|
||||
path: /quick/{quick_form}/configure
|
||||
defaults:
|
||||
|
@ -29,3 +17,6 @@ farm_quick.configure:
|
|||
parameters:
|
||||
quick_form:
|
||||
type: string
|
||||
|
||||
route_callbacks:
|
||||
- '\Drupal\farm_quick\Routing\QuickFormRoutes::routes'
|
||||
|
|
|
@ -59,7 +59,7 @@ class QuickFormController extends ControllerBase {
|
|||
$quick_forms = $this->quickFormInstanceManager->getInstances();
|
||||
$items = [];
|
||||
foreach ($quick_forms as $id => $quick_form) {
|
||||
$url = Url::fromRoute('farm_quick.quick_form', ['quick_form' => $id]);
|
||||
$url = Url::fromRoute('farm.quick.' . $id);
|
||||
if ($url->access()) {
|
||||
$cacheability->addCacheableDependency($quick_form);
|
||||
$items[] = [
|
||||
|
|
|
@ -62,7 +62,7 @@ class QuickForm extends FormBase implements BaseFormIdInterface {
|
|||
*/
|
||||
public function getFormId() {
|
||||
$form_id = $this->getBaseFormId();
|
||||
$id = $this->getRouteMatch()->getParameter('quick_form');
|
||||
$id = $this->getRouteMatch()->getParameter('id');
|
||||
if (!is_null($id)) {
|
||||
$form_id .= '_' . $this->quickFormInstanceManager->getInstance($id)->getPlugin()->getFormId();
|
||||
}
|
||||
|
@ -72,14 +72,14 @@ class QuickForm extends FormBase implements BaseFormIdInterface {
|
|||
/**
|
||||
* Get the title of the quick form.
|
||||
*
|
||||
* @param string $quick_form
|
||||
* @param string $id
|
||||
* The quick form ID.
|
||||
*
|
||||
* @return string
|
||||
* Quick form title.
|
||||
*/
|
||||
public function getTitle(string $quick_form) {
|
||||
return $this->quickFormInstanceManager->getInstance($quick_form)->getLabel();
|
||||
public function getTitle(string $id) {
|
||||
return $this->quickFormInstanceManager->getInstance($id)->getLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,14 +87,14 @@ class QuickForm extends FormBase implements BaseFormIdInterface {
|
|||
*
|
||||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* Run access checks for this account.
|
||||
* @param string $quick_form
|
||||
* @param string $id
|
||||
* The quick form ID.
|
||||
*
|
||||
* @return \Drupal\Core\Access\AccessResultInterface
|
||||
* The access result.
|
||||
*/
|
||||
public function access(AccountInterface $account, string $quick_form) {
|
||||
if ($quick_form = $this->quickFormInstanceManager->getInstance($quick_form)) {
|
||||
public function access(AccountInterface $account, string $id) {
|
||||
if ($quick_form = $this->quickFormInstanceManager->getInstance($id)) {
|
||||
return $quick_form->getPlugin()->access($account);
|
||||
}
|
||||
|
||||
|
@ -105,13 +105,13 @@ class QuickForm extends FormBase implements BaseFormIdInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $quick_form = NULL) {
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $id = NULL) {
|
||||
|
||||
// Save the quick form ID.
|
||||
$this->quickFormId = $quick_form;
|
||||
$this->quickFormId = $id;
|
||||
|
||||
// Load the quick form.
|
||||
$form = $this->quickFormInstanceManager->getInstance($quick_form)->getPlugin()->buildForm($form, $form_state);
|
||||
$form = $this->quickFormInstanceManager->getInstance($id)->getPlugin()->buildForm($form, $form_state);
|
||||
|
||||
// Add a submit button, if one wasn't provided.
|
||||
if (empty($form['actions']['submit'])) {
|
||||
|
|
|
@ -63,10 +63,7 @@ class QuickFormMenuLink extends DeriverBase implements ContainerDeriverInterface
|
|||
$links[$route_id] = [
|
||||
'title' => $quick_form->getLabel(),
|
||||
'parent' => 'farm.quick:farm.quick',
|
||||
'route_name' => 'farm_quick.quick_form',
|
||||
'route_parameters' => [
|
||||
'quick_form' => $id,
|
||||
],
|
||||
'route_name' => $route_id,
|
||||
] + $base_plugin_definition;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_quick\Plugin\Derivative;
|
||||
|
||||
use Drupal\Component\Plugin\Derivative\DeriverBase;
|
||||
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\farm_quick\QuickFormInstanceManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides task links for farmOS Quick Forms.
|
||||
*/
|
||||
class QuickFormTaskLink extends DeriverBase implements ContainerDeriverInterface {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* The quick form instance manager.
|
||||
*
|
||||
* @var \Drupal\farm_quick\QuickFormInstanceManagerInterface
|
||||
*/
|
||||
protected $quickFormInstanceManager;
|
||||
|
||||
/**
|
||||
* QuickFormTaskLink constructor.
|
||||
*
|
||||
* @param \Drupal\farm_quick\QuickFormInstanceManagerInterface $quick_form_instance_manager
|
||||
* The quick form plugin manager.
|
||||
*/
|
||||
public function __construct(QuickFormInstanceManagerInterface $quick_form_instance_manager) {
|
||||
$this->quickFormInstanceManager = $quick_form_instance_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, $base_plugin_id) {
|
||||
return new static(
|
||||
$container->get('quick_form.instance_manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
$links = [];
|
||||
|
||||
// Load quick forms.
|
||||
$quick_forms = $this->quickFormInstanceManager->getInstances();
|
||||
|
||||
// Add links for each quick form.
|
||||
foreach ($quick_forms as $id => $quick_form) {
|
||||
$route_name = 'farm.quick.' . $id;
|
||||
$links[$route_name] = [
|
||||
'title' => $this->t('Quick form'),
|
||||
'route_name' => $route_name,
|
||||
'base_route' => $route_name,
|
||||
'weight' => 0,
|
||||
] + $base_plugin_definition;
|
||||
|
||||
// If the quick form is configurable, add a link to the config form.
|
||||
if ($quick_form->getPlugin()->isConfigurable()) {
|
||||
$links["farm.quick.$id.configure"] = [
|
||||
'title' => $this->t('Configure'),
|
||||
'route_name' => 'farm_quick.configure',
|
||||
'route_parameters' => [
|
||||
'quick_form' => $id,
|
||||
],
|
||||
'base_route' => $route_name,
|
||||
'weight' => 100,
|
||||
] + $base_plugin_definition;
|
||||
}
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_quick\Routing;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Drupal\farm_quick\Form\QuickForm;
|
||||
use Drupal\farm_quick\QuickFormInstanceManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
/**
|
||||
* Defines quick form routes.
|
||||
*/
|
||||
class QuickFormRoutes implements ContainerInjectionInterface {
|
||||
|
||||
/**
|
||||
* The quick form instance manager.
|
||||
*
|
||||
* @var \Drupal\farm_quick\QuickFormInstanceManagerInterface
|
||||
*/
|
||||
protected $quickFormInstanceManager;
|
||||
|
||||
/**
|
||||
* Constructs a QuickFormRoutes object.
|
||||
*
|
||||
* @param \Drupal\farm_quick\QuickFormInstanceManagerInterface $quick_form_instance_manager
|
||||
* The quick form instance manager.
|
||||
*/
|
||||
public function __construct(QuickFormInstanceManagerInterface $quick_form_instance_manager) {
|
||||
$this->quickFormInstanceManager = $quick_form_instance_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('quick_form.instance_manager'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides routes for quick forms.
|
||||
*
|
||||
* @return \Symfony\Component\Routing\RouteCollection
|
||||
* Returns a route collection.
|
||||
*/
|
||||
public function routes(): RouteCollection {
|
||||
$route_collection = new RouteCollection();
|
||||
/** @var \Drupal\farm_quick\Entity\QuickFormInstanceInterface[] $quick_forms */
|
||||
$quick_forms = $this->quickFormInstanceManager->getInstances();
|
||||
foreach ($quick_forms as $id => $quick_form) {
|
||||
|
||||
// Build a route for the quick form.
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue