easy_social-8.x-3.x-dev/src/Form/PinterestSettingsForm.php
src/Form/PinterestSettingsForm.php
<?php
namespace Drupal\easy_social\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Configure user settings for this site.
*/
final class PinterestSettingsForm extends ConfigFormBase {
/**
* Config settings.
*
* @var string
*/
private const SETTINGS = 'easy_social.pinterest';
/**
* Implements \Drupal\Core\Form\FormInterface::getFormId().
*/
public function getFormId(): string {
return 'easy_social_pinterest';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames(): array {
return [self::SETTINGS];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $type = 'new'): array {
$config = $this->config('easy_social.pinterest');
$form['help'] = [
'#markup' => t('For more information, please check out the official @pinterest share widget <a href="@url" target="_blank">documentation</a>', [
'@pinterest' => t('Pinterest'),
'@url' => 'http://business.pinterest.com/widget-builder/#do_pin_it_button',
]),
'#weight' => -99,
];
$form['config'] = [
'#type' => 'select',
'#title' => t('Pin Count'),
'#options' => [
'above' => t('Above the Button'),
'beside' => t('Beside the Button'),
'none' => t('Not Shown'),
],
'#default_value' => $config->get('config'),
];
// Provide a list of images?
$form['image'] = [
'#type' => 'textfield',
'#title' => t('Image'),
'#default_value' => $config->get('image'),
];
$form['description'] = [
'#type' => 'textfield',
'#title' => t('Description'),
'#default_value' => $config->get('description'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state): void {
parent::submitForm($form, $form_state);
$config = $this->config(self::SETTINGS);
$config
->set('config', $form_state->getValue('config'))
->set('image', $form_state->getValue('image'))
->set('description', $form_state->getValue('description'))
->save();
}
}
