You are here

public function ShareMessageSettingsForm::buildForm in Share Message 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/ShareMessageSettingsForm.php, line 33

Class

ShareMessageSettingsForm
Defines a form that configures Share Message global settings.

Namespace

Drupal\sharemessage\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
  $config = $this
    ->config('sharemessage.settings');

  // Global setting.
  $form['message_enforcement'] = [
    '#type' => 'checkbox',
    '#title' => t('Allow to enforce Share Messages'),
    '#description' => t('This will enforce loading of a Share Message if the ?smid argument is present in an URL. If something else on your site is using this argument, disable this option.'),
    '#default_value' => $config
      ->get('message_enforcement'),
  ];
  $form['add_twitter_card'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t("Add meta tags for twitter's summary card with large image"),
    '#description' => $this
      ->t('Enables sharing of images on twitter, check <a href="@url">this</a> for more information.', [
      '@url' => 'https://dev.twitter.com/cards/types/summary-large-image',
    ]),
    '#default_value' => $config
      ->get('add_twitter_card'),
  ];
  $form['twitter_user'] = [
    '#title' => t('Twitter account username'),
    '#description' => t('This is required when enabling the meta tags for twitter cards above.'),
    '#type' => 'textfield',
    '#default_value' => $config
      ->get('twitter_user'),
    '#states' => [
      'visible' => [
        ':input[name="add_twitter_card"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  return parent::buildForm($form, $form_state);
}