You are here

public function ReCaptchaV3ActionDeleteForm::buildForm in reCAPTCHA v3 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides EntityDeleteForm::buildForm

File

src/Form/ReCaptchaV3ActionDeleteForm.php, line 18

Class

ReCaptchaV3ActionDeleteForm
Provides a confirmation form for deleting reCAPTCHA v3 action entities.

Namespace

Drupal\recaptcha_v3\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $action = $this->entityTypeManager
    ->getStorage('captcha_point')
    ->getQuery()
    ->condition('captchaType', 'recaptcha_v3/' . $this->entity
    ->id())
    ->execute();
  if (!empty($action)) {
    $caption = '<p>' . $this
      ->formatPlural(count($action), '%label is used by 1 captcha point form on your site. You can not remove %label until you have removed it from %formId captcha points form.', '%label is used by @count captcha point forms on your site. You may not remove %label until you have removed %label from %formId.', [
      '%label' => $this->entity
        ->label(),
      '%formId' => implode(", ", $action),
    ]) . '</p>';
    $form['description'] = [
      '#markup' => $caption,
    ];
    return $form;
  }
  else {
    return parent::buildForm($form, $form_state);
  }

  // @todo needs to do same as above in case of recaptcha v3 action being used in webform.
}