Implement BaseFormIdInterface and build a unique form ID from the id route parameter.

This commit is contained in:
Paul Weidner 2022-06-27 11:28:10 -07:00
parent e434715e74
commit 7463f81f1d
2 changed files with 12 additions and 2 deletions

View File

@ -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 #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) - [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 ### Security

View File

@ -2,6 +2,7 @@
namespace Drupal\farm_quick\Form; namespace Drupal\farm_quick\Form;
use Drupal\Core\Form\BaseFormIdInterface;
use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
@ -13,7 +14,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* *
* @ingroup farm * @ingroup farm
*/ */
class QuickForm extends FormBase { class QuickForm extends FormBase implements BaseFormIdInterface {
/** /**
* The quick form manager. * The quick form manager.
@ -51,10 +52,18 @@ class QuickForm extends FormBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getFormId() { public function getBaseFormId() {
return 'quick_form'; return 'quick_form';
} }
/**
* {@inheritdoc}
*/
public function getFormId() {
$id = $this->getRouteMatch()->getParameter('id');
return $this->getBaseFormId() . "_$id";
}
/** /**
* Get the title of the quick form. * Get the title of the quick form.
* *