From 7463f81f1dd2125fea72701e75ff91ffe6e34e3c Mon Sep 17 00:00:00 2001 From: Paul Weidner Date: Mon, 27 Jun 2022 11:28:10 -0700 Subject: [PATCH] Implement BaseFormIdInterface and build a unique form ID from the id route parameter. --- CHANGELOG.md | 1 + modules/core/quick/src/Form/QuickForm.php | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cb95c9a5..739665eea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [Issue #3290929: Provide a farmOS map form element](https://www.drupal.org/project/farm/issues/3290929) - [Issue #3290993: Add "Move asset" button next to the current location field](https://www.drupal.org/project/farm/issues/3290993) +- [Generate unique form IDs for quick forms #547](https://github.com/farmOS/farmOS/pull/547) ### Security diff --git a/modules/core/quick/src/Form/QuickForm.php b/modules/core/quick/src/Form/QuickForm.php index bb9a98198..7837e3a95 100644 --- a/modules/core/quick/src/Form/QuickForm.php +++ b/modules/core/quick/src/Form/QuickForm.php @@ -2,6 +2,7 @@ namespace Drupal\farm_quick\Form; +use Drupal\Core\Form\BaseFormIdInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Session\AccountInterface; @@ -13,7 +14,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * * @ingroup farm */ -class QuickForm extends FormBase { +class QuickForm extends FormBase implements BaseFormIdInterface { /** * The quick form manager. @@ -51,10 +52,18 @@ class QuickForm extends FormBase { /** * {@inheritdoc} */ - public function getFormId() { + public function getBaseFormId() { return 'quick_form'; } + /** + * {@inheritdoc} + */ + public function getFormId() { + $id = $this->getRouteMatch()->getParameter('id'); + return $this->getBaseFormId() . "_$id"; + } + /** * Get the title of the quick form. *