public function AmpSocialPostFormatter::settingsForm in Accelerated Mobile Pages (AMP) 8.3
Returns a form to configure settings for the formatter.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form elements for the formatter settings.
Overrides FormatterBase::settingsForm
File
- src/
Plugin/ Field/ FieldFormatter/ AmpSocialPostFormatter.php, line 74
Class
- AmpSocialPostFormatter
- Plugin implementation of the 'amp_social_post' formatter.
Namespace
Drupal\amp\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$provider_selector = str_replace('[layout]', '[provider]', $this
->layoutSelector());
$form['provider'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Provider'),
'#options' => AmpSocialPost::getProviders(),
'#default_value' => $this
->getSetting('provider'),
'#description' => $this
->t('Select the allowed social providers for the post url in this field. Posts from other providers will not display.'),
'#multiple' => TRUE,
];
$form['data-embed-as'] = [
'#type' => 'select',
'#options' => [
'post' => $this
->t('Post'),
'video' => $this
->t('Video'),
],
'#title' => $this
->t('Facebook: Embed as'),
'#default_value' => $this
->getSetting('data-embed-as'),
'#states' => [
'visible' => [
[
$provider_selector => [
'value' => 'facebook',
],
],
],
],
];
$form['data-align-center'] = [
'#type' => 'select',
'#options' => [
'' => $this
->t('False'),
'true' => $this
->t('True'),
],
'#title' => $this
->t('Facebook: Center'),
'#default_value' => $this
->getSetting('data-align-center'),
'#states' => [
'visible' => [
[
$provider_selector => [
'value' => 'facebook',
],
],
],
],
];
$form['placeholder'] = [
'#type' => 'textarea',
'#title' => $this
->t('Twitter: Placeholder'),
'#default_value' => $this
->getSetting('placeholder'),
'#description' => $this
->t('Placeholder text to appear until the Tweet is retrieved.'),
'#states' => [
'visible' => [
[
$provider_selector => [
'value' => 'facebook',
],
],
],
],
];
$form['layout'] = $this
->layoutElement();
$form['width'] = $this
->widthElement();
$form['height'] = $this
->heightElement();
$form['#prefix'] = '<div class="description">' . $this
->libraryDescription() . '</div>';
return $form;
}