You are here

public function SocialSharePrivacy::buildConfigurationForm in Share Message 8

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides SharePluginBase::buildConfigurationForm

File

src/Plugin/sharemessage/SocialSharePrivacy.php, line 105

Class

SocialSharePrivacy
SocialSharePrivacy plugin.

Namespace

Drupal\sharemessage\Plugin\sharemessage

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {

  // Settings fieldset.
  $form['override_default_settings'] = [
    '#type' => 'checkbox',
    '#title' => t('Override default settings'),
    '#default_value' => $this
      ->getSetting('override_default_settings'),
  ];
  $form['services'] = [
    '#title' => t('Default visible services'),
    '#type' => 'select',
    '#multiple' => TRUE,
    '#options' => static::allServices(),
    '#default_value' => $this
      ->getSetting('services'),
    '#size' => 11,
    '#states' => [
      'visible' => [
        ':input[name="settings[override_default_settings]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['facebook_action'] = [
    '#title' => $this
      ->t('Choose facebook action'),
    '#type' => 'radios',
    '#default_value' => $this
      ->getSetting('facebook_action') ?: 'like',
    '#options' => [
      'like' => $this
        ->t('Like'),
      'recommend' => $this
        ->t('Recommend'),
    ],
    '#states' => [
      'visible' => [
        ':input[name="settings[override_default_settings]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['disqus_shortname'] = [
    '#title' => $this
      ->t('Disqus shortname'),
    '#type' => 'textfield',
    '#description' => $this
      ->t('You can get shortname from <a href=":url">Disqus</a>.', [
      ':url' => 'https://disqus.com/',
    ]),
    '#default_value' => $this
      ->getSetting('disqus_shortname'),
    '#states' => [
      'visible' => [
        ':input[name="settings[override_default_settings]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['flattr_uid'] = [
    '#title' => $this
      ->t('Flattr user id'),
    '#type' => 'textfield',
    '#description' => $this
      ->t('You can get user id from <a href=":url">Flattr</a>.', [
      ':url' => 'https://flattr.com/',
    ]),
    '#default_value' => $this
      ->getSetting('flattr_uid'),
    '#states' => [
      'visible' => [
        ':input[name="settings[override_default_settings]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  return $form;
}