You are here

class TfaSetup in Two-factor Authentication (TFA) 7.2

Class TfaSetup.

Hierarchy

Expanded class hierarchy of TfaSetup

File

./tfa.inc, line 310
TFA module classes.

View source
class TfaSetup {

  /**
   * Plugin being set up.
   *
   * @var TfaBasePlugin
   */
  protected $setupPlugin;

  /**
   * Context of current TFA process.
   *
   * @var array
   */
  protected $context;

  /**
   * TFA Setup constructor.
   *
   * @param TfaBasePlugin $setup_plugin
   *   Plugin being set up.
   * @param array $context
   *   Context of TFA process.
   *   Must include key:
   *     - 'uid'
   *       Account uid of user in TFA process.
   */
  public function __construct(TfaBasePlugin $setup_plugin, array $context) {
    $this->setupPlugin = $setup_plugin;
    $this->context = $context;
  }

  /**
   * 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
   *   The form array structure.
   * @param array $form_state
   *   The current form state array.
   *
   * @return array
   *   Form array structure.
   */
  public function getForm(array $form, array &$form_state) {
    return $this->setupPlugin
      ->getSetupForm($form, $form_state);
  }

  /**
   * Validate form.
   *
   * @param array $form
   *   The form array structure.
   * @param array $form_state
   *   The current form state array.
   *
   * @return bool
   *   Whether form passes validation or not.
   */
  public function validateForm(array $form, array &$form_state) {
    return $this->setupPlugin
      ->validateSetupForm($form, $form_state);
  }

  /**
   * Return process error messages.
   *
   * @return array
   *   Error messages.
   */
  public function getErrorMessages() {
    return $this->setupPlugin
      ->getErrorMessages();
  }

  /**
   * Form submission handler.
   *
   * @param array $form
   *   The form array structure.
   * @param array $form_state
   *   The current form state array.
   *
   * @return bool
   *   Whether the form submission succeeded.
   */
  public function submitForm(array $form, array &$form_state) {
    return $this->setupPlugin
      ->submitSetupForm($form, $form_state);
  }

  /**
   * Return TFA context.
   *
   * @return array
   *   TFA context.
   */
  public function getContext() {
    if (method_exists($this->setupPlugin, 'getPluginContext')) {
      $plugin_context = $this->setupPlugin
        ->getPluginContext();
      $this->context['setup_context'] = $plugin_context;
    }
    return $this->context;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TfaSetup::$context protected property Context of current TFA process.
TfaSetup::$setupPlugin protected property Plugin being set up.
TfaSetup::begin public function Run any begin setup processes.
TfaSetup::getContext public function Return TFA context.
TfaSetup::getErrorMessages public function Return process error messages.
TfaSetup::getForm public function Get plugin form.
TfaSetup::submitForm public function Form submission handler.
TfaSetup::validateForm public function Validate form.
TfaSetup::__construct public function TFA Setup constructor.