You are here

class DeveloperSettingsForm in Apigee Edge 8

Provides a form for changing Developer related settings.

Hierarchy

Expanded class hierarchy of DeveloperSettingsForm

3 files declare their use of DeveloperSettingsForm
apigee_edge.module in ./apigee_edge.module
Copyright 2018 Google Inc.
DeveloperEmailUnique.php in src/Plugin/Validation/Constraint/DeveloperEmailUnique.php
EmailTest.php in tests/src/Functional/EmailTest.php
1 string reference to 'DeveloperSettingsForm'
apigee_edge.routing.yml in ./apigee_edge.routing.yml
apigee_edge.routing.yml

File

src/Form/DeveloperSettingsForm.php, line 28

Namespace

Drupal\apigee_edge\Form
View source
class DeveloperSettingsForm extends ConfigFormBase {

  /**
   * Allow to confirm email address with a verification email.
   *
   * @var string
   */
  public const VERIFICATION_ACTION_VERIFY_EMAIL = 'verify_email';

  /**
   * Abort registration, display an error.
   *
   * @var string
   */
  public const VERIFICATION_ACTION_DISPLAY_ERROR_ONLY = 'display_error_only';

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'apigee_edge.developer_settings',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'apigee_edge_developer_settings_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config('apigee_edge.developer_settings');
    $form['email_verification_on_registration'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('When a new user registers and the developer email address is already taken on Apigee Edge but not in Drupal'),
      '#collapsible' => FALSE,
    ];
    $form['email_verification_on_registration']['verification_action'] = [
      '#type' => 'radios',
      '#options' => [
        self::VERIFICATION_ACTION_VERIFY_EMAIL => $this
          ->t('Display an error message and send a verification email with a link that allows user to register'),
        self::VERIFICATION_ACTION_DISPLAY_ERROR_ONLY => $this
          ->t('Display only an error message to the user'),
      ],
      '#default_value' => $config
        ->get('verification_action') ?: self::VERIFICATION_ACTION_DISPLAY_ERROR_ONLY,
    ];
    $form['email_verification_on_registration']['verification_email_subject'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Verification email subject'),
      '#default_value' => $config
        ->get('verification_email.subject'),
      '#states' => [
        'visible' => [
          [
            ':input[name="verification_action"]' => [
              'value' => self::VERIFICATION_ACTION_VERIFY_EMAIL,
            ],
          ],
        ],
        'required' => [
          [
            ':input[name="verification_action"]' => [
              'value' => self::VERIFICATION_ACTION_VERIFY_EMAIL,
            ],
          ],
        ],
      ],
    ];
    $form['email_verification_on_registration']['verification_email_body'] = [
      // By default Drupal does not support HTML mails therefore this is
      // just a simple textarea.
      '#type' => 'textarea',
      '#title' => $this
        ->t('Verification email content'),
      '#description' => $this
        ->t('Available tokens: [site:name], [site:url], [user:display-name], [user:account-name], [user:mail], [site:login-url], [site:url-brief], [user:developer-email-verification-url]'),
      '#default_value' => $config
        ->get('verification_email.body'),
      '#rows' => 10,
      '#states' => [
        'visible' => [
          [
            ':input[name="verification_action"]' => [
              'value' => self::VERIFICATION_ACTION_VERIFY_EMAIL,
            ],
          ],
        ],
        'required' => [
          [
            ':input[name="verification_action"]' => [
              'value' => self::VERIFICATION_ACTION_VERIFY_EMAIL,
            ],
          ],
        ],
      ],
      '#after_build' => [
        'apigee_edge_developer_settings_form_verification_email_body_after_build',
      ],
    ];
    $form['email_verification_on_registration']['verification_token'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Verification token'),
      '#description' => $this
        ->t('Query parameter in registration url that contains the verification token. Ex.: user/register?%token=1234567', [
        '%token' => $config
          ->get('verification_token'),
      ]),
      '#default_value' => $config
        ->get('verification_token'),
      '#states' => [
        'visible' => [
          [
            ':input[name="verification_action"]' => [
              'value' => self::VERIFICATION_ACTION_VERIFY_EMAIL,
            ],
          ],
        ],
        'required' => [
          [
            ':input[name="verification_action"]' => [
              'value' => self::VERIFICATION_ACTION_VERIFY_EMAIL,
            ],
          ],
        ],
      ],
    ];
    $form['email_verification_on_registration']['verification_token_expires'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Verification token expires'),
      '#description' => $this
        ->t('Number of seconds after the verification token expires. Initially provided registration data by a user is cached until the same time.'),
      '#default_value' => $config
        ->get('verification_token_expires'),
      '#min' => 60,
      '#states' => [
        'visible' => [
          [
            ':input[name="verification_action"]' => [
              'value' => self::VERIFICATION_ACTION_VERIFY_EMAIL,
            ],
          ],
        ],
        'required' => [
          [
            ':input[name="verification_action"]' => [
              'value' => self::VERIFICATION_ACTION_VERIFY_EMAIL,
            ],
          ],
        ],
      ],
    ];
    $form['email_verification_on_registration']['verify_email_error_message'] = [
      '#type' => 'text_format',
      '#title' => $this
        ->t('Error message'),
      '#description' => $this
        ->t('The error message on the form. Use <em>%email</em> token in message to display the email address.'),
      '#format' => $config
        ->get('verify_email_error_message.format'),
      '#default_value' => $config
        ->get('verify_email_error_message.value'),
      '#states' => [
        'visible' => [
          [
            ':input[name="verification_action"]' => [
              'value' => self::VERIFICATION_ACTION_VERIFY_EMAIL,
            ],
          ],
        ],
        'required' => [
          [
            ':input[name="verification_action"]' => [
              'value' => self::VERIFICATION_ACTION_VERIFY_EMAIL,
            ],
          ],
        ],
      ],
    ];
    $form['email_verification_on_registration']['display_only_error_message_content'] = [
      '#type' => 'text_format',
      '#title' => $this
        ->t('Error message'),
      '#description' => $this
        ->t('The error message on the form. Use <em>%email</em> token in message to display the email address.'),
      '#format' => $config
        ->get('display_only_error_message_content.format'),
      '#default_value' => $config
        ->get('display_only_error_message_content.value'),
      '#states' => [
        'visible' => [
          [
            ':input[name="verification_action"]' => [
              'value' => self::VERIFICATION_ACTION_DISPLAY_ERROR_ONLY,
            ],
          ],
        ],
        'required' => [
          [
            ':input[name="verification_action"]' => [
              'value' => self::VERIFICATION_ACTION_DISPLAY_ERROR_ONLY,
            ],
          ],
        ],
      ],
    ];
    $form['email_verification_on_edit'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('When a Drupal user changes its email address and the email address is already taken on Apigee Edge but not in Drupal'),
      '#collapsible' => FALSE,
    ];
    $form['email_verification_on_edit']['user_edit_error_message'] = [
      '#type' => 'text_format',
      '#title' => $this
        ->t('Error message'),
      '#description' => $this
        ->t('The error message on the form.'),
      '#format' => $config
        ->get('user_edit_error_message.format'),
      '#default_value' => $config
        ->get('user_edit_error_message.value'),
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->configFactory
      ->getEditable('apigee_edge.developer_settings')
      ->set('verification_action', $form_state
      ->getValue('verification_action'))
      ->set('display_only_error_message_content.value', $form_state
      ->getValue([
      'display_only_error_message_content',
      'value',
    ]))
      ->set('display_only_error_message_content.format', $form_state
      ->getValue([
      'display_only_error_message_content',
      'format',
    ]))
      ->set('verify_email_error_message.value', $form_state
      ->getValue([
      'verify_email_error_message',
      'value',
    ]))
      ->set('verify_email_error_message.format', $form_state
      ->getValue([
      'verify_email_error_message',
      'format',
    ]))
      ->set('verification_email.subject', $form_state
      ->getValue([
      'verification_email_subject',
    ]))
      ->set('verification_email.body', $form_state
      ->getValue([
      'verification_email_body',
    ]))
      ->set('verification_token', $form_state
      ->getValue([
      'verification_token',
    ]))
      ->set('verification_token_expires', $form_state
      ->getValue([
      'verification_token_expires',
    ]))
      ->set('user_edit_error_message.value', $form_state
      ->getValue([
      'user_edit_error_message',
      'value',
    ]))
      ->set('user_edit_error_message.format', $form_state
      ->getValue([
      'user_edit_error_message',
      'format',
    ]))
      ->save();
    parent::submitForm($form, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create 13
ConfigFormBase::__construct public function Constructs a \Drupal\system\ConfigFormBase object. 11
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
DeveloperSettingsForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
DeveloperSettingsForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
DeveloperSettingsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
DeveloperSettingsForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
DeveloperSettingsForm::VERIFICATION_ACTION_DISPLAY_ERROR_ONLY public constant Abort registration, display an error.
DeveloperSettingsForm::VERIFICATION_ACTION_VERIFY_EMAIL public constant Allow to confirm email address with a verification email.
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.