You are here

class OpenReadSpeakerSettingsForm in Open ReadSpeaker 8

Class OpenReadSpeakerSettingsForm.

@package Drupal\open_readspeaker\Form

Hierarchy

Expanded class hierarchy of OpenReadSpeakerSettingsForm

1 string reference to 'OpenReadSpeakerSettingsForm'
open_readspeaker.routing.yml in ./open_readspeaker.routing.yml
open_readspeaker.routing.yml

File

src/Form/OpenReadSpeakerSettingsForm.php, line 14

Namespace

Drupal\open_readspeaker\Form
View source
class OpenReadSpeakerSettingsForm extends ConfigFormBase {

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

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

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config('open_readspeaker.settings');
    $language_options = [
      'none' => $this
        ->t('Select a language'),
      'ar_ar' => $this
        ->t('@arabic - Arabic', [
        '@arabic' => urldecode('%D8%B9%D8%B1%D8%A8%D9%8A'),
      ]),
      'ca_es' => $this
        ->t('Català - Catalan'),
      'da_dk' => $this
        ->t('Dansk - Danish'),
      'de_de' => $this
        ->t('Deutsch - German'),
      'en_in' => $this
        ->t('English (Indian) - English'),
      'en_us' => $this
        ->t('English (US) - English'),
      'en_uk' => $this
        ->t('English (British) - English'),
      'en_au' => $this
        ->t('English (Australia) - English'),
      'es_co' => $this
        ->t('Español (de Colombia) - Spanish'),
      'es_es' => $this
        ->t('Español (de España) - Spanish'),
      'es_mx' => $this
        ->t('Español (de Mexico) - Spanish'),
      'es_eu' => $this
        ->t('Euskara - Basque'),
      'es_us' => $this
        ->t('Español (de US) - Spanish'),
      'el_gr' => $this
        ->t('Ελληνικά - Greek'),
      'fo_fo' => $this
        ->t('Azerbaijani - Faroese'),
      'fi_fi' => $this
        ->t('Suomi - Finnish'),
      'fr_fr' => $this
        ->t('Français - French'),
      'fr_be' => $this
        ->t('Français (Belge) - French (Belgian)'),
      'fy_nl' => $this
        ->t('Frysk - Frisian'),
      'gl_es' => $this
        ->t('Galego - Galician'),
      'hi_in' => $this
        ->t('@hindi - Hindi', [
        '@hindi' => urldecode('%E0%A4%B9%E0%A4%BF%E0%A4%A8%E0%A5%8D%E0%A4%A6%E0%A5%80%20(%E0%A4%AD%E0%A4%BE%E0%A4%B0%E0%A4%A4)'),
      ]),
      'it_it' => $this
        ->t('Italiano - Italian'),
      'is_is' => $this
        ->t('íslenska - Icelandic'),
      'ja_jp' => $this
        ->t('日本語 - Japanese'),
      'ko_kr' => $this
        ->t('한국어 - Korean'),
      'pt_pt' => $this
        ->t('Português (Europeu) - Portuguese'),
      'nl_nl' => $this
        ->t('Nederlands - Dutch'),
      'nl_be' => $this
        ->t('Nederlands (Belgisch) - Dutch (Belgian)'),
      'no_nb' => $this
        ->t('Bokmål - Norwegian'),
      'no_nn' => $this
        ->t('Nynorsk - Norwegian'),
      'ru_ru' => $this
        ->t('Русский - Russian'),
      'sv_se' => $this
        ->t('Svenska - Swedish'),
      'th_th' => $this
        ->t('@thai - Thai', [
        '@thai' => urldecode('%E0%B9%84%E0%B8%97%E0%B8%A2'),
      ]),
      'tr_tr' => $this
        ->t('Türkçe - Turkish'),
      'zh_cn' => $this
        ->t('@mandarin - Mandarin Chinese', [
        '@mandarin' => urldecode('%E4%B8%AD%E6%96%87%20(%E7%AE%80%E4%BD%93)'),
      ]),
      'zh_hk' => $this
        ->t('@traditional - Traditional Chinese', [
        '@traditional' => urldecode('%E4%B8%AD%E5%9C%8B%EF%BC%88%E7%B9%81%E9%AB%94%EF%BC%89'),
      ]),
    ];
    $form['settings'] = [
      '#title' => $this
        ->t('General settings for ReadSpeaker'),
      '#type' => 'fieldset',
    ];
    $form['settings']['open_readspeaker_accountid'] = [
      '#title' => $this
        ->t('Account ID'),
      '#description' => $this
        ->t('Enter your ReadSpeaker account ID'),
      '#type' => 'textfield',
      '#default_value' => $config
        ->get('open_readspeaker_accountid'),
      '#required' => TRUE,
    ];
    $form['settings']['open_readspeaker_i18n'] = [
      '#title' => $this
        ->t('Language'),
      '#description' => $this
        ->t('Select which language your ReadSpeaker account supports.'),
      '#type' => 'select',
      '#options' => $language_options,
      '#default_value' => $config
        ->get('open_readspeaker_i18n'),
      '#required' => TRUE,
    ];
    if (\Drupal::moduleHandler()
      ->moduleExists('token')) {
      $form['settings']['token_browser'] = [
        '#theme' => 'token_tree_link',
        '#token_types' => [
          'open_readspeaker',
        ],
      ];
      $tokenBrowserLink = render($form['settings']['token_browser']);
    }
    $form['settings']['open_readspeaker_url'] = [
      '#title' => $this
        ->t('URL'),
      '#description' => $this
        ->t('The remote URL of the ReadSpeaker JavaScript.') . ($tokenBrowserLink ?? ''),
      '#type' => 'textfield',
      '#default_value' => $config
        ->get('open_readspeaker_url'),
      '#required' => TRUE,
    ];
    $form['settings']['open_readspeaker_post_mode'] = [
      '#title' => $this
        ->t('Use POST mode'),
      '#description' => $this
        ->t('Enabling this option will POST the html/text to the ReadSpeaker service instead of ReadSpeaker accessing your site, which will make the service work behind password protected pages.'),
      '#type' => 'checkbox',
      '#default_value' => $config
        ->get('open_readspeaker_post_mode'),
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);
    $this
      ->config('open_readspeaker.settings')
      ->set('open_readspeaker_accountid', $form_state
      ->getValue('open_readspeaker_accountid'))
      ->set('open_readspeaker_i18n', $form_state
      ->getValue('open_readspeaker_i18n'))
      ->set('open_readspeaker_post_mode', $form_state
      ->getValue('open_readspeaker_post_mode'))
      ->set('open_readspeaker_url', $form_state
      ->getValue('open_readspeaker_url'))
      ->save();
    Cache::invalidateTags([
      'library_info',
    ]);
  }

}

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
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.
OpenReadSpeakerSettingsForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
OpenReadSpeakerSettingsForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
OpenReadSpeakerSettingsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
OpenReadSpeakerSettingsForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
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.