class Addthis in Share Message 8
AddThis plugin.
Plugin annotation
@SharePlugin(
id = "addthis",
label = @Translation("AddThis"),
description = @Translation("AddThis plugin for Share Message module."),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\sharemessage\SharePluginBase implements SharePluginInterface uses StringTranslationTrait
- class \Drupal\sharemessage\Plugin\sharemessage\Addthis implements SharePluginInterface
- class \Drupal\sharemessage\SharePluginBase implements SharePluginInterface uses StringTranslationTrait
Expanded class hierarchy of Addthis
File
- src/
Plugin/ sharemessage/ Addthis.php, line 20
Namespace
Drupal\sharemessage\Plugin\sharemessageView source
class Addthis extends SharePluginBase implements SharePluginInterface {
/**
* {@inheritdoc}
*/
public function build($context, $plugin_attributes) {
$attributes = new Attribute([
'class' => [
'addthis_toolbox',
'addthis_default_style',
$this->shareMessage
->getSetting('icon_style') ?: \Drupal::config('sharemessage.addthis')
->get('icon_style'),
],
]);
if ($plugin_attributes) {
$attributes['addthis:url'] = $this->shareMessage
->getUrl($context);
$attributes['addthis:title'] = $this->shareMessage
->getTokenizedField($this->shareMessage->title, $context);
$attributes['addthis:description'] = $this->shareMessage
->getTokenizedField($this->shareMessage->message_long, $context);
}
// Add AddThis buttons.
$build = [
'#theme' => 'sharemessage_addthis',
'#attributes' => $attributes,
'#services' => $this->shareMessage
->getSetting('services') ?: \Drupal::config('sharemessage.addthis')
->get('services'),
'#additional_services' => $this
->getSetting('additional_services') ?: \Drupal::config('sharemessage.addthis')
->get('additional_services'),
'#counter' => $this
->getSetting('counter') ?: \Drupal::config('sharemessage.addthis')
->get('counter'),
'#twitter_template' => $this->shareMessage
->getTokenizedField($this->shareMessage->message_short, $context),
'#attached' => [
'library' => [
'sharemessage/addthis',
],
'drupalSettings' => [
'addthis_config' => [
'data_track_addressbar' => TRUE,
],
],
],
];
$cacheability_metadata = CacheableMetadata::createFromObject(\Drupal::config('sharemessage.addthis'));
$cacheability_metadata
->applyTo($build);
return $build;
}
/**
* Gets the default AddThis settings.
*
* @param string $key
* The settings key.
*
* @return array
*/
public function getSetting($key) {
$override = $this->shareMessage
->getSetting('override_default_settings');
if (isset($override)) {
return $this->shareMessage
->getSetting($key);
}
}
/**
* {@inheritdoc}
*/
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('Visible services'),
'#type' => 'select',
'#multiple' => TRUE,
'#options' => sharemessage_get_addthis_services(),
'#default_value' => $this
->getSetting('services'),
'#size' => 10,
'#states' => [
'invisible' => [
':input[name="settings[override_default_settings]"]' => [
'checked' => FALSE,
],
],
],
];
$form['additional_services'] = [
'#type' => 'checkbox',
'#title' => t('Show additional services button'),
'#default_value' => $this
->getSetting('additional_services'),
'#states' => [
'invisible' => [
':input[name="settings[override_default_settings]"]' => [
'checked' => FALSE,
],
],
],
];
$form['counter'] = [
'#type' => 'select',
'#title' => t('Show AddThis counter'),
'#empty_option' => t('No'),
'#options' => [
'addthis_pill_style' => t('Pill style'),
'addthis_bubble_style' => t('Bubble style'),
],
'#default_value' => $this
->getSetting('counter'),
'#states' => [
'invisible' => [
':input[name="settings[override_default_settings]"]' => [
'checked' => FALSE,
],
],
],
];
$form['icon_style'] = [
'#title' => t('Default icon style'),
'#type' => 'radios',
'#options' => [
'addthis_16x16_style' => '16x16 pix',
'addthis_32x32_style' => '32x32 pix',
],
'#default_value' => $this
->getSetting('icon_style'),
'#states' => [
'invisible' => [
':input[name="settings[override_default_settings]"]' => [
'checked' => FALSE,
],
],
],
];
return $form;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Addthis:: |
public | function |
Creates the AddThis toolbar. Overrides SharePluginInterface:: |
|
Addthis:: |
public | function |
Form constructor. Overrides SharePluginBase:: |
|
Addthis:: |
public | function |
Gets the default AddThis settings. Overrides SharePluginInterface:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
SharePluginBase:: |
protected | property | Share Message. | |
SharePluginBase:: |
public | function | ||
SharePluginBase:: |
public | function |
Provides the action link plugin's default configuration. Overrides ConfigurableInterface:: |
|
SharePluginBase:: |
public | function |
Provides the action link plugin's current configuration array. Overrides ConfigurableInterface:: |
|
SharePluginBase:: |
public | function |
Updates the plugin's current configuration. Overrides ConfigurableInterface:: |
|
SharePluginBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
SharePluginBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
1 |
SharePluginBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
1 |
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. |