public function Sharrre::build in Share Message 8
Creates the AddThis toolbar.
Parameters
array $context: The form structure.
$plugin_attributes: Custom plugin attributes.
Return value
array $build Returns the modified configuration form structure.
Overrides SharePluginInterface::build
File
- src/
Plugin/ sharemessage/ Sharrre.php, line 71
Class
- Sharrre
- Sharrre plugin.
Namespace
Drupal\sharemessage\Plugin\sharemessageCode
public function build($context, $plugin_attributes) {
$attributes = new Attribute([
'id' => [
'sharemessage',
],
]);
if ($plugin_attributes) {
$attributes['sharrre:url'] = $this->shareMessage
->getUrl($context);
$attributes['sharrre:title'] = $this->shareMessage
->getTokenizedField($this->shareMessage->title, $context);
$attributes['sharrre:description'] = $this->shareMessage
->getTokenizedField($this->shareMessage->message_long, $context);
}
// Add Sharrre buttons.
$build = [
'#theme' => 'sharemessage_sharrre',
'#attributes' => $attributes,
'#attached' => [
'library' => [
'sharemessage/sharrre',
],
'drupalSettings' => [
'sharrre_config' => [
'services' => $this->shareMessage
->getSetting('services') ?: \Drupal::config('sharemessage.sharrre')
->get('services'),
'library_url' => $this->shareMessage
->getSetting('library_url') ?: \Drupal::config('sharemessage.sharrre')
->get('library_url'),
'shorter_total' => $this->shareMessage
->getSetting('shorter_total') ?: \Drupal::config('sharemessage.sharrre')
->get('shorter_total'),
'enable_hover' => $this->shareMessage
->getSetting('enable_hover') ?: \Drupal::config('sharemessage.sharrre')
->get('enable_hover'),
'enable_counter' => $this->shareMessage
->getSetting('enable_counter') ?: \Drupal::config('sharemessage.sharrre')
->get('enable_counter'),
'enable_tracking' => $this->shareMessage
->getSetting('enable_tracking') ?: \Drupal::config('sharemessage.sharrre')
->get('enable_tracking'),
'url_curl' => Url::fromRoute('sharemessage.sharrre.counter')
->toString(),
'url' => $this->shareMessage->share_url,
],
],
],
];
$cacheability_metadata = CacheableMetadata::createFromObject(\Drupal::config('sharemessage.sharrre'));
$cacheability_metadata
->applyTo($build);
return $build;
}