You are here

class TfaSetup in Two-factor Authentication (TFA) 8

Same name in this branch
  1. 8 src/TfaSetup.php \Drupal\tfa\TfaSetup
  2. 8 src/Annotation/TfaSetup.php \Drupal\tfa\Annotation\TfaSetup

TFA Setup.

Hierarchy

Expanded class hierarchy of TfaSetup

1 file declares its use of TfaSetup
BasicSetup.php in src/Form/BasicSetup.php

File

src/TfaSetup.php, line 11

Namespace

Drupal\tfa
View source
class TfaSetup {

  /**
   * Current setup plugin.
   *
   * @var \Drupal\tfa\Plugin\TfaSetupInterface
   */
  protected $setupPlugin;

  /**
   * TFA Setup constructor.
   *
   * @param \Drupal\tfa\Plugin\TfaSetupInterface $plugin
   *   Plugins to instantiate.
   */
  public function __construct(TfaSetupInterface $plugin) {
    $this->setupPlugin = $plugin;
  }

  /**
   * Run any begin setup processes.
   */
  public function begin() {

    // Invoke begin method on setup plugin.
    if (method_exists($this->setupPlugin, 'begin')) {
      $this->setupPlugin
        ->begin();
    }
  }

  /**
   * Get plugin form.
   *
   * @param array $form
   *   An associative array containing the structure of the form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   * @param int $reset
   *   Reset the data or not.
   *
   * @return array
   *   Form API array.
   */
  public function getForm(array $form, FormStateInterface &$form_state, $reset = 0) {
    return $this->setupPlugin
      ->getSetupForm($form, $form_state, $reset);
  }

  /**
   * Validate form.
   *
   * @param array $form
   *   An associative array containing the structure of the form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   *
   * @return bool
   *   TRUE if setup completed otherwise FALSE.
   */
  public function validateForm(array $form, FormStateInterface &$form_state) {
    return $this->setupPlugin
      ->validateSetupForm($form, $form_state);
  }

  /**
   * Return process error messages.
   *
   * @return string[]
   *   An array containing the setup errors.
   */
  public function getErrorMessages() {
    return $this->setupPlugin
      ->getErrorMessages();
  }

  /**
   * Submit the setup form.
   *
   * @param array $form
   *   An associative array containing the structure of the form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   *
   * @return bool
   *   TRUE if no errors occur when saving the data.
   */
  public function submitForm(array $form, FormStateInterface &$form_state) {
    return $this->setupPlugin
      ->submitSetupForm($form, $form_state);
  }

  /**
   * Returns a list of messages for plugin step.
   *
   * @return string[]
   *   An array containing messages to be used during plugin setup.
   */
  public function getSetupMessages() {
    return $this->setupPlugin
      ->getSetupMessages();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TfaSetup::$setupPlugin protected property Current setup plugin.
TfaSetup::begin public function Run any begin setup processes.
TfaSetup::getErrorMessages public function Return process error messages.
TfaSetup::getForm public function Get plugin form.
TfaSetup::getSetupMessages public function Returns a list of messages for plugin step.
TfaSetup::submitForm public function Submit the setup form.
TfaSetup::validateForm public function Validate form.
TfaSetup::__construct public function TFA Setup constructor.