"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/lib/Drupal/Core/Form/ConfirmFormBase.php" (26 Nov 2020, 1420 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ConfirmFormBase.php" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 9.0.8_vs_9.1.0-rc1.

    1 <?php
    2 
    3 namespace Drupal\Core\Form;
    4 
    5 /**
    6  * Provides an generic base class for a confirmation form.
    7  */
    8 abstract class ConfirmFormBase extends FormBase implements ConfirmFormInterface {
    9 
   10   /**
   11    * {@inheritdoc}
   12    */
   13   public function getDescription() {
   14     return $this->t('This action cannot be undone.');
   15   }
   16 
   17   /**
   18    * {@inheritdoc}
   19    */
   20   public function getConfirmText() {
   21     return $this->t('Confirm');
   22   }
   23 
   24   /**
   25    * {@inheritdoc}
   26    */
   27   public function getCancelText() {
   28     return $this->t('Cancel');
   29   }
   30 
   31   /**
   32    * {@inheritdoc}
   33    */
   34   public function getFormName() {
   35     return 'confirm';
   36   }
   37 
   38   /**
   39    * {@inheritdoc}
   40    */
   41   public function buildForm(array $form, FormStateInterface $form_state) {
   42     $form['#title'] = $this->getQuestion();
   43 
   44     $form['#attributes']['class'][] = 'confirmation';
   45     $form['description'] = ['#markup' => $this->getDescription()];
   46     $form[$this->getFormName()] = ['#type' => 'hidden', '#value' => 1];
   47 
   48     $form['actions'] = ['#type' => 'actions'];
   49     $form['actions']['submit'] = [
   50       '#type' => 'submit',
   51       '#value' => $this->getConfirmText(),
   52       '#button_type' => 'primary',
   53     ];
   54 
   55     $form['actions']['cancel'] = ConfirmFormHelper::buildCancelLink($this, $this->getRequest());
   56 
   57     // By default, render the form using theme_confirm_form().
   58     if (!isset($form['#theme'])) {
   59       $form['#theme'] = 'confirm_form';
   60     }
   61     return $form;
   62   }
   63 
   64 }