' . t('About') . ''; $output .= '

' . t('Share Buttons by AddToAny provides a nice suite of share buttons for Drupal. These include the AddToAny universal share button, Facebook, Twitter, Mastodon, Pinterest, WhatsApp and many more.') . '

'; $output .= '

' . t('AddToAny is a universal sharing platform that can be integrated into many parts of the website with the use of a web widget. Once installed, visitors to the website can share or save an item using a variety of services, such as Facebook, Twitter, Pinterest, email, and over 100 other services.'); $output .= '

' . t('AddToAny icons are Scalable Vector Graphics, meaning they load fast, are mathematically precise, scalable to any size, and are stunning on High-PPI screens such as Retina and Retina HD displays.'); $output .= '

' . t('AddToAny\'s lightweight code follows best practices, and is optimized to load efficiently from locations all around the world. Accessibility, cross-browser fallbacks, graceful degradation are a few AddToAny staples.'); $output .= '

' . t('More documentation about AddToAny in Drupal 8 can be found in Drupal\'s Community Documentation .') . '

'; $output .= '

' . t('Uses') . '

'; $output .= '

' . t('AddToAny integrates with Google Analytics\' Social Plugin Analytics to provide sharing statistics within your analytics dashboard. ') . '

'; $output .= '

' . t('AddToAny just works. No registration, and no user accounts to manage.') . '

'; $output .= '

' . t('Official counts alongside your share buttons. AddToAny counters in the same style show numbers directly from major services.') . '

'; $output .= '

' . t('Encourage visitors to share your content with a special share buttons bar that stays in place as you scroll.') . '

'; return $output; } } /** * Implements hook_theme(). */ function addtoany_theme() { return [ 'addtoany_standard' => [ 'variables' => [ 'addtoany_html' => FALSE, 'link_url' => FALSE, 'link_title' => FALSE, 'buttons_size' => FALSE, 'button_setting' => FALSE, 'button_image' => FALSE, 'universal_button_placement' => FALSE, 'entity_type' => '', 'bundle' => '', ], ], 'addtoany_follow' => [ 'variables' => [ 'addtoany_html' => FALSE, 'buttons_size' => FALSE, 'entity_type' => '', 'bundle' => '', ], ], ]; } /** * Implements hook_theme_suggestions_HOOK(). */ function addtoany_theme_suggestions_addtoany_standard(array $variables) { $suggestion = 'addtoany_standard__'; $suggestions = []; if (!empty($variables['entity_type'])) { $suggestion .= $variables['entity_type']; $suggestions[] = $suggestion; } if (!empty($variables['entity_type']) && !empty($variables['bundle'])) { $suggestion .= '__' . $variables['bundle']; $suggestions[] = $suggestion; } return $suggestions; } /** * Implements hook_theme_suggestions_HOOK(). */ function addtoany_theme_suggestions_addtoany_follow(array $variables) { $suggestion = 'addtoany_follow__'; $suggestions = []; if (!empty($variables['entity_type'])) { $suggestion .= $variables['entity_type']; $suggestions[] = $suggestion; } if (!empty($variables['entity_type']) && !empty($variables['bundle'])) { $suggestion .= '__' . $variables['bundle']; $suggestions[] = $suggestion; } return $suggestions; } /** * Implements hook_entity_extra_field_info(). */ function addtoany_entity_extra_field_info() { $extra = []; $entityTypes = AddToAnySettingsForm::getContentEntities(); $config = Drupal::config('addtoany.settings'); // Allow modules to alter the entity types. \Drupal::moduleHandler()->alter('addtoany_entity_types', $entityTypes); foreach ($entityTypes as $type) { $entityTypeId = $type->id(); $isAllowed = $config->get("entities.{$entityTypeId}"); if ($isAllowed) { $bundles = Drupal::service('entity_type.bundle.info')->getBundleInfo($entityTypeId); foreach ($bundles as $bundle => $bundle_data) { $extra[$entityTypeId][$bundle]['display']['addtoany'] = [ 'label' => t('AddToAny'), 'description' => t('Share buttons by AddToAny'), 'weight' => 5, 'visible' => FALSE, ]; } } } return $extra; } /** * Implements hook_ENTITY_TYPE_view(). */ function addtoany_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) { // Prevent error on preview of an unpublished node. if ($entity->id() === NULL) { return; } if ($display->getComponent('addtoany')) { $config = Drupal::config('addtoany.settings'); $isAllowed = $config->get("entities.{$entity->getEntityTypeId()}"); if ($isAllowed) { $data = addtoany_create_entity_data($entity); $build['addtoany'] = [ '#addtoany_html' => \Drupal::token()->replace($data['addtoany_html'], ['node' => $entity]), '#link_url' => $data['link_url'], '#link_title' => $data['link_title'], '#button_setting' => $data['button_setting'], '#button_image' => $data['button_image'], '#universal_button_placement' => $data['universal_button_placement'], '#buttons_size' => $data['buttons_size'], '#entity_type' => $entity->getEntityType()->id(), '#bundle' => $entity->bundle(), '#theme' => 'addtoany_standard', ]; } } } /** * Implements hook_page_attachments(). */ function addtoany_page_attachments(&$page) { $config = \Drupal::config('addtoany.settings'); // Initial JavaScript. $additional_js = $config->get('additional_js'); if (\Drupal::moduleHandler()->moduleExists('token')) { $node = \Drupal::routeMatch()->getParameter('node'); $data = []; if ($node) { if (is_numeric($node)) { $node = Node::load($node); } $data = ['node' => $node]; $additional_js = \Drupal::token()->replace($additional_js, $data); } } $javascript_header = 'window.a2a_config=window.a2a_config||{};' . 'a2a_config.callbacks=[];a2a_config.overlays=[];' . 'a2a_config.templates={};' . $additional_js; // Add AddToAny initial JS config. $page['#attached']['html_head'][] = [ // The data. [ // Add a