class ShariffSettingsForm in Shariff Social Media Buttons 8
Provides a settings form for the Shariff sharing buttons.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\shariff\Form\ShariffSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of ShariffSettingsForm
1 string reference to 'ShariffSettingsForm'
File
- src/
Form/ ShariffSettingsForm.php, line 13
Namespace
Drupal\shariff\FormView source
class ShariffSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'shariff_settings_form';
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('shariff.settings');
$ignoreArray = [
'actions',
'form_build_id',
'form_token',
'form_id',
];
foreach (Element::children($form) as $variable) {
$value = $form_state
->getValue($form[$variable]['#parents']);
if ($variable == 'shariff_services') {
$value = array_filter($value);
}
if (!in_array($variable, $ignoreArray)) {
$config
->set($variable, $value);
}
}
$config
->save();
if (method_exists($this, '_submitForm')) {
$this
->_submitForm($form, $form_state);
}
parent::submitForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$backend_url = $form_state
->getValue('shariff_backend_url');
if ($backend_url && !UrlHelper::isValid($backend_url, TRUE)) {
$form_state
->setErrorByName('shariff_backend_url', $this
->t('Please enter a valid URL.'));
}
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'shariff.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$settings = _shariff_get_settings();
$form['shariff_services'] = [
'#title' => $this
->t('Activated services'),
'#description' => $this
->t('Please define for which services a sharing button should be included.'),
'#type' => 'checkboxes',
'#options' => [
'twitter' => $this
->t('Twitter'),
'facebook' => $this
->t('Facebook'),
'linkedin' => $this
->t('LinkedIn'),
'pinterest' => $this
->t('Pinterest'),
'vk' => $this
->t('VK'),
'xing' => $this
->t('Xing'),
'whatsapp' => $this
->t('WhatsApp'),
'addthis' => $this
->t('AddThis'),
'telegram' => $this
->t('Telegram'),
'tumblr' => $this
->t('Tumblr'),
'flattr' => $this
->t('Flattr'),
'diaspora' => $this
->t('Diaspora'),
'reddit' => $this
->t('reddit'),
'stumbleupon' => $this
->t('StumbleUpon'),
'weibo' => $this
->t('Weibo'),
'flipboard' => $this
->t('Flipboard'),
'pocket' => $this
->t('Pocket'),
'print' => $this
->t('Print'),
'tencent-weibo' => $this
->t('Tencent-Weibo'),
'qzone' => $this
->t('Qzone'),
'threema' => $this
->t('Threema'),
'mail' => $this
->t('E-Mail'),
'info' => $this
->t('Info Button'),
'buffer' => $this
->t('Buffer'),
],
'#default_value' => $settings['services'],
];
$form['shariff_theme'] = [
'#title' => $this
->t('Theme'),
'#description' => $this
->t('Please choose a layout option.'),
'#type' => 'radios',
'#options' => [
'colored' => $this
->t('Colored'),
'grey' => $this
->t('Grey'),
'white' => $this
->t('White'),
],
'#default_value' => $settings['shariff_theme'],
];
$form['shariff_css'] = [
'#title' => $this
->t('CSS'),
'#description' => $this
->t('Please choose a CSS variant. Font Awesome is used to display the services icons.'),
'#type' => 'radios',
'#options' => [
'complete' => $this
->t('Complete (Contains also Font Awesome)'),
'min' => $this
->t('Minimal (If Font Awesome is already included in your site)'),
'naked' => $this
->t('None (Without any CSS)'),
],
'#default_value' => \Drupal::config('shariff.settings')
->get('shariff_css'),
];
$form['shariff_button_style'] = [
'#title' => $this
->t('Button Style'),
'#description' => $this
->t('Please choose a button style.
With "icon only" the icon is shown, with "icon-count" icon and counter and with "standard icon", text and counter are shown, depending on the display size.
Please note: For showing counters you have to provide a working Shariff backend URL.'),
'#type' => 'radios',
'#options' => [
'standard' => $this
->t('Standard'),
'icon' => $this
->t('Icon'),
'icon-count' => $this
->t('Icon Count'),
],
'#default_value' => $settings['button_style'],
];
$form['shariff_orientation'] = [
'#title' => $this
->t('Orientation'),
'#description' => $this
->t('Vertical will stack the buttons vertically. Default is horizontally.'),
'#type' => 'radios',
'#options' => [
'vertical' => $this
->t('Vertical'),
'horizontal' => $this
->t('Horizontal'),
],
'#default_value' => $settings['orientation'],
];
$form['shariff_twitter_via'] = [
'#title' => $this
->t('Twitter Via User'),
'#description' => $this
->t('Screen name of the Twitter user to attribute the Tweets to.'),
'#type' => 'textfield',
'#default_value' => $settings['twitter_via'],
];
$form['shariff_mail_url'] = [
'#title' => $this
->t('Mail link'),
'#description' => $this
->t('The url target used for the mail service button. Leave it as "mailto:" to let the user
choose an email address.'),
'#type' => 'textfield',
'#default_value' => $settings['mail_url'] ? $settings['mail_url'] : 'mailto:',
];
$form['shariff_mail_subject'] = [
'#title' => $this
->t('Mail subject'),
'#description' => $this
->t("If a mailto: link is provided in Mail link above, then this value is used as the mail subject.\n Left empty the page's current (canonical) URL or og:url is used."),
'#type' => 'textfield',
'#default_value' => $settings['mail_subject'],
];
$form['shariff_mail_body'] = [
'#title' => $this
->t('Mail body'),
'#description' => $this
->t("If a mailto: link is provided in Mail link above, then this value is used as the mail body.\n Left empty the page title is used."),
'#type' => 'textarea',
'#default_value' => $settings['mail_body'],
];
$form['shariff_referrer_track'] = [
'#title' => $this
->t('Referrer track code'),
'#description' => $this
->t('A string that will be appended to the share url. Disabled when empty.'),
'#type' => 'textfield',
'#default_value' => $settings['referrer_track'],
];
$form['shariff_backend_url'] = [
'#title' => $this
->t('Backend URL'),
'#description' => $this
->t('The path to your Shariff backend. Leaving the value blank disables the backend feature and no counts will occur.'),
'#type' => 'textfield',
'#default_value' => $settings['backend_url'],
];
$form['shariff_flattr_category'] = [
'#title' => $this
->t('Flattr category'),
'#description' => $this
->t('Category to be used for Flattr.'),
'#type' => 'textfield',
'#default_value' => $settings['flattr_category'],
];
$form['shariff_flattr_user'] = [
'#title' => $this
->t('Flattr user'),
'#description' => $this
->t('User that receives Flattr donation.'),
'#type' => 'textfield',
'#default_value' => $settings['flattr_user'],
];
$form['shariff_media_url'] = [
'#title' => $this
->t('Media url'),
'#description' => $this
->t('Media url to be shared (Pinterest).'),
'#type' => 'textfield',
'#default_value' => $settings['media_url'],
];
$form['shariff_info_url'] = [
'#title' => $this
->t('Shariff Information URL'),
'#description' => $this
->t('The url for information about Shariff. Used by the Info Button.'),
'#type' => 'url',
'#default_value' => $settings['info_url'],
];
$form['shariff_info_display'] = [
'#title' => $this
->t('Shariff Information Page Display'),
'#description' => $this
->t('How the above URL should be opened. Please choose a display option.'),
'#type' => 'radios',
'#options' => [
'blank' => $this
->t('Blank'),
'popup' => $this
->t('Popup'),
'self' => $this
->t('Self'),
],
'#default_value' => $settings['info_display'],
];
$form['shariff_title'] = [
'#title' => $this
->t('WhatsApp/Twitter Share Title'),
'#description' => $this
->t('Fixed title to be used as share text in Twitter/Whatsapp.
Normally you want to leave it as it is, then page\'s DC.title/DC.creator or page title is used.'),
'#type' => 'textfield',
'#default_value' => $settings['title'],
];
$form['shariff_url'] = [
'#title' => $this
->t('Canonical URL'),
'#description' => $this
->t('You can fix the canonical URL of the page to check here.
Normally you want to leave it as it is, then the page\'s canonical URL or og:url or current URL is used.'),
'#type' => 'textfield',
'#default_value' => $settings['url'],
];
return parent::buildForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
13 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 11 |
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
ShariffSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
ShariffSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
ShariffSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ShariffSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
ShariffSettingsForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |