You are here

class AddthisSettingsForm in Share Message 8

Defines a form that configures Share Message settings.

Hierarchy

Expanded class hierarchy of AddthisSettingsForm

1 string reference to 'AddthisSettingsForm'
sharemessage.routing.yml in ./sharemessage.routing.yml
sharemessage.routing.yml

File

src/Form/AddthisSettingsForm.php, line 13

Namespace

Drupal\sharemessage\Form
View source
class AddthisSettingsForm extends ConfigFormBase {

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

  /**
   * {@inheritdoc}
   */
  public function getFormID() {
    return 'sharemessage_addthis_settings';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
    $config = $this
      ->config('sharemessage.addthis');

    // AddThis specific settings.
    $form['addthis_profile_id'] = [
      '#title' => t('AddThis Profile ID'),
      '#type' => 'textfield',
      '#default_value' => $config
        ->get('addthis_profile_id'),
    ];
    $form['default_services'] = [
      '#title' => t('Default visible services'),
      '#type' => 'select',
      '#multiple' => TRUE,
      '#options' => sharemessage_get_addthis_services(),
      '#default_value' => $config
        ->get('services'),
      '#size' => 10,
    ];
    $form['default_additional_services'] = [
      '#type' => 'checkbox',
      '#title' => t('Show additional services button'),
      '#default_value' => $config
        ->get('additional_services'),
    ];
    $form['default_counter'] = [
      '#type' => 'select',
      '#title' => t('Show AddThis counter'),
      '#empty_option' => t('No'),
      '#options' => [
        'addthis_pill_style' => t('Pill style'),
        'addthis_bubble_style' => t('Bubble style'),
      ],
      '#default_value' => $config
        ->get('counter'),
    ];
    $form['default_icon_style'] = [
      '#title' => t('Default icon style'),
      '#type' => 'radios',
      '#options' => [
        'addthis_16x16_style' => '16x16 pix',
        'addthis_32x32_style' => '32x32 pix',
      ],
      '#default_value' => $config
        ->get('icon_style'),
    ];
    $form['local_services_definition'] = [
      '#type' => 'checkbox',
      '#title' => t('Use local service definitions file'),
      '#description' => t('Check this if you are behind a firewall and the module cannot access the services definition at http://cache.addthiscdn.com/services/v1/sharing.en.json.'),
      '#default_value' => $config
        ->get('local_services_definition'),
    ];
    $form['shared_video_width'] = [
      '#title' => t('Video height'),
      '#description' => t('The width of the player when sharing a video.'),
      '#type' => 'textfield',
      '#default_value' => $config
        ->get('shared_video_width'),
    ];
    $form['shared_video_height'] = [
      '#title' => t('Video height'),
      '#description' => t('The height of the player when sharing a video.'),
      '#type' => 'textfield',
      '#default_value' => $config
        ->get('shared_video_height'),
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);

    // If the profile id changes then we need to rebuild the library cache.
    Cache::invalidateTags([
      'library_info',
    ]);
    $this
      ->config('sharemessage.addthis')
      ->set('addthis_profile_id', $form_state
      ->getValue('addthis_profile_id'))
      ->set('services', $form_state
      ->getValue('default_services'))
      ->set('additional_services', $form_state
      ->getValue('default_additional_services'))
      ->set('counter', $form_state
      ->getValue('default_counter'))
      ->set('icon_style', $form_state
      ->getValue('default_icon_style'))
      ->set('local_services_definition', $form_state
      ->getValue('local_services_definition'))
      ->set('shared_video_width', $form_state
      ->getValue('shared_video_width'))
      ->set('shared_video_height', $form_state
      ->getValue('shared_video_height'))
      ->save();
  }

}

Members

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