From 92c3543b87cae50435a11d563644d7a3d0fe94b6 Mon Sep 17 00:00:00 2001 From: Michael Stenta Date: Mon, 13 Mar 2023 09:30:46 -0400 Subject: [PATCH] Add a ConfigureQuickForm for building, validating, and submitting configuration forms. --- .../quick/src/Form/ConfigureQuickForm.php | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 modules/core/quick/src/Form/ConfigureQuickForm.php diff --git a/modules/core/quick/src/Form/ConfigureQuickForm.php b/modules/core/quick/src/Form/ConfigureQuickForm.php new file mode 100644 index 000000000..016236cd0 --- /dev/null +++ b/modules/core/quick/src/Form/ConfigureQuickForm.php @@ -0,0 +1,91 @@ +quickFormInstanceManager->createInstance($id)->getLabel(); + return $this->t('Configure @quick_form', ['@quick_form' => $quick_form_title]); + } + + /** + * Checks access for configuration of a specific quick form. + * + * @param \Drupal\Core\Session\AccountInterface $account + * Run access checks for this account. + * @param string $id + * The quick form ID. + * + * @return \Drupal\Core\Access\AccessResultInterface + * The access result. + */ + public function access(AccountInterface $account, string $id) { + $configure_form_access = AccessResult::allowedIfHasPermissions($account, ['configure quick forms']); + return parent::access($account, $id)->andIf($configure_form_access); + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state, $id = NULL) { + + // Save the quick form ID. + $this->quickFormId = $id; + + // Load the quick form's configuration form. + $form = $this->quickFormInstanceManager->createInstance($id)->getPlugin()->buildConfigurationForm($form, $form_state); + + // Add a submit button. + $form['actions'] = [ + '#type' => 'actions', + '#weight' => 1000, + ]; + $form['actions']['submit'] = [ + '#type' => 'submit', + '#value' => $this->t('Save'), + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, FormStateInterface $form_state) { + $this->quickFormInstanceManager->createInstance($this->quickFormId)->getPlugin()->validateConfigurationForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $this->quickFormInstanceManager->createInstance($this->quickFormId)->getPlugin()->submitConfigurationForm($form, $form_state); + } + +}