Commit 49b63afa authored by micropat's avatar micropat
Browse files

Revert commits back to stable c0d33537



Revert 85ad0748 Issue #3350785.
Revert 3281e4aa Issue #3273208.
Revert af20f592 Issue #3212302.

Signed-off-by: default avatarPat <27246-micropat@users.noreply.drupalcode.org>
parent 85ad0748
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@
 * @param array $types
 *   The entity types.
 */
function hook_addtoany_entity_types_alter(array &$types) {
function hook_addtoany_entity_types_alter(&$types) {
  // Add the "taxonomy_term" entity type.
  $types[] = 'taxonomy_term';
}
+38 −87
Original line number Diff line number Diff line
@@ -5,14 +5,14 @@
 * Handle AddToAny integration.
 */

use Drupal\addtoany\Form\AddToAnySettingsForm;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Render\Markup;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Render\Markup;
use Drupal\Core\Url;
use Drupal\Component\Utility\UrlHelper;
use Drupal\node\Entity\Node;
use Drupal\addtoany\Form\AddToAnySettingsForm;

/**
 *  Implements hook_help().
@@ -26,10 +26,10 @@ function addtoany_help($route_name, RouteMatchInterface $route_match) {

        $output .= '<p>' . t('AddToAny is a social bookmarking 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 .= '<p>' . 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 .= '<p>' . 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 .= '<p>' . 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 .= '<p>' . t('More documentation about AddToAny in Drupal 8 can be found in Drupal\'s <a href="proxy.php?url=https%3A%2F%2Fwww.drupal.org%2Fnode%2F2719155">Community Documentation </a>.') . '</p>';
        $output .= '<h3>' . t('Uses') . '</h3>';
      $output .= '<p>' . t("AddToAny automatically integrates with Google Analytics' Social Plugin Analytics to provide sharing statistics within your analytics dashboard.") . '</p>';
        $output .= '<p>' . t('AddToAny automatically integrates with Google Analytics\' Social Plugin Analytics to provide sharing statistics within your analytics dashboard. ')  . '</p>';
        $output .= '<p>' . t('AddToAny just works. No registration, and no user accounts to manage.') . '</p>';
        $output .= '<p>' . t('Official counts alongside your share buttons. AddToAny counters in the same style show numbers directly from major services.') . '</p>';
        $output .= '<p>' . t('Encourage visitors to share your content with a special share buttons bar that stays in place as you scroll.') . '</p>';
@@ -37,6 +37,7 @@ function addtoany_help($route_name, RouteMatchInterface $route_match) {
    }
 }


/**
 * Implements hook_theme().
 */
@@ -121,8 +122,7 @@ function addtoany_entity_extra_field_info() {
    $entityTypeId = $type->id();
    $isAllowed = $config->get("entities.{$entityTypeId}");
    if ($isAllowed) {
      $bundles = Drupal::service('entity_type.bundle.info')
        ->getBundleInfo($entityTypeId);
      $bundles = Drupal::service('entity_type.bundle.info')->getBundleInfo($entityTypeId);
      foreach ($bundles as $bundle => $bundle_data) {
        $extra[$entityTypeId][$bundle]['display']['addtoany'] = [
          'label' => t('AddToAny'),
@@ -152,8 +152,7 @@ function addtoany_entity_view(array &$build, EntityInterface $entity, EntityView
    if ($isAllowed) {
      $data = addtoany_create_entity_data($entity);
      $build['addtoany'] = [
        '#addtoany_html' => \Drupal::token()
          ->replace($data['addtoany_html'], ['node' => $entity]),
        '#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'],
@@ -189,12 +188,9 @@ function addtoany_page_attachments(&$page) {
    }
  }

  // @todo Make path configurable.
  $version = \Drupal::state()->get('addtoany.scripts_version');
  $addtoany_lib_path = \Drupal::service('file_url_generator')
    ->generateAbsoluteString('public://js/addtoany/menu/' . $version);
  $javascript_header = 'window.a2a_config=window.a2a_config||{};a2a_config.callbacks=[];a2a_config.overlays=[];a2a_config.templates={};a2a_config.static_server= '
    . json_encode($addtoany_lib_path, JSON_UNESCAPED_SLASHES) . ';'
  $javascript_header = 'window.a2a_config=window.a2a_config||{};'
    . 'a2a_config.callbacks=[];a2a_config.overlays=[];'
    . 'a2a_config.templates={};'
    . $additional_js;

  // Add AddToAny initial JS config.
@@ -253,8 +249,7 @@ function addtoany_page_attachments(&$page) {
 *   The array with url, title, additional_html that will be send to Twig.
 */
function addtoany_create_entity_data($node, $config = NULL) {
  $url = isset($node) ? $node->toUrl('canonical', ['absolute' => TRUE])
    ->toString() : NULL;
  $url = isset($node) ? $node->toUrl('canonical', ['absolute' => TRUE])->toString() : NULL;
  $title = isset($node) ? $node->label() : NULL;
  return addtoany_create_data($url, $title, $config);
}
@@ -292,9 +287,7 @@ function addtoany_create_data($url = NULL, $title = NULL, $config = NULL) {
      $url = (is_null($url) || $url === $front_url . '/node') ? $front_url : $url;
    }
    // Use the current path if the URL is still NULL.
    $url = (is_null($url)) ? Url::fromRoute('<current>')
      ->setAbsolute()
      ->toString() : $url;
    $url = (is_null($url)) ? Url::fromRoute('<current>')->setAbsolute()->toString() : $url;
  }
  else {
    // Sanitize and encode URL for HTML output.
@@ -346,52 +339,10 @@ function addtoany_create_data($url = NULL, $title = NULL, $config = NULL) {
    'link_title'                 => $title,
    'buttons_size'               => $buttons_size,
    'button_setting'             => $button_setting,
    'button_image' => $button_image ?? '',
    'button_image'               => isset($button_image) ? $button_image : '',
    'universal_button_placement' => $universal_button_placement,
    'addtoany_html'              => $additional_html,
  ];

  return $info;
}

/**
 * Implements hook_library_info_alter().
 */
function addtoany_library_info_alter(&$libraries, $extension) {
  // Get the remote addtoany library and download it locally to the website.
  if ($extension == 'addtoany' && isset($libraries['addtoany']['js']['https://static.addtoany.com/menu/page.js'])) {
    if (\Drupal::config('addtoany.settings')
      ->get('library_location') == 'local') {
      $version = \Drupal::state()->get('addtoany.scripts_version');
      $file = 'public://js/addtoany/menu/' . $version . 'page.js';
      if (is_file($file)) {
        $fileUrl = \Drupal::service('file_url_generator')
          ->generateString($file);
        unset($libraries['addtoany']['js']['https://static.addtoany.com/menu/page.js']);
        $libraries['addtoany']['js'][$fileUrl] = [];
      }

    }
  }
}

/**
 * Implements hook_cache_flush().
 */
function addtoany_cache_flush() {
  // Delete all the old versions of the scripts.
  \Drupal::service('addtoany.update')->cleanup();
}

/**
 * Implements hook_cron().
 */
function addtoany_cron() {
  $version = \Drupal::state()->get('addtoany.scripts_version');
  $latest_version = \Drupal::service('addtoany.update')->getScripts();
  // Do not update if latest version is already there.
  if ($latest_version['version'] !== $version) {
    // Update addtoany scripts locally.
    \Drupal::service('addtoany.update')->updateLatestScripts();
  }
}

addtoany.services.yml

deleted100644 → 0
+0 −4
Original line number Diff line number Diff line
services:
  addtoany.update:
    class: Drupal\addtoany\UpdateScripts
    arguments: [ '@file_system', '@file_url_generator', '@logger.factory', '@state' ]
+73 −99
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Drupal\addtoany\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\ContentEntityType;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Extension\ExtensionList;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\ConfigFormBase;
@@ -17,7 +18,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 * Configure AddToAny settings for this site.
 */
class AddToAnySettingsForm extends ConfigFormBase {

  /**
   * Drupal\Core\Extension\ModuleHandler definition.
   *
@@ -77,6 +77,15 @@ class AddToAnySettingsForm extends ConfigFormBase {
    return 'addtoany_settings_form';
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'addtoany.settings',
    ];
  }

  /**
   * {@inheritdoc}
   */
@@ -91,11 +100,6 @@ class AddToAnySettingsForm extends ConfigFormBase {

    $button_img = '<img src="' . $base_path . $this->moduleExtensionList->getPath('addtoany') . '/images/%s" width="%d" height="%d"%s />';

    $library_options = [
      'remote' => $this->t('Remote'),
      'local' => $this->t('Local'),
    ];

    $button_options = [
      'default' => sprintf($button_img, 'a2a_32_32.svg', 32, 32, ' class="addtoany-round-icon"'),
      'custom' => $this->t('Custom button'),
@@ -187,15 +191,6 @@ class AddToAnySettingsForm extends ConfigFormBase {
      '#title' => $this->t('Additional options'),
      '#open'  => ($js_value !== '' || $css_value !== '') ? TRUE : FALSE,
    ];

    $form['addtoany_additional_settings']['addtoany_library_location'] = [
      '#type' => 'radios',
      '#title' => $this->t('Location of the library'),
      '#description' => $this->t('The way the library is stored, if local than refreshed on cache clear'),
      '#default_value' => $addtoany_settings->get('library_location') ?? 'remote',
      '#options' => $library_options,
    ];

    $form['addtoany_additional_settings']['addtoany_additional_js'] = [
      '#type'          => 'textarea',
      '#title'         => $this->t('Additional JavaScript'),
@@ -240,17 +235,10 @@ class AddToAnySettingsForm extends ConfigFormBase {
    // Allow modules to alter the entity types.
    $this->moduleHandler->alter('addtoany_entity_types', $entities);

    // Whitelist the entity IDs that let us link to each bundle's Manage
    // Display page.
    // Whitelist the entity IDs that let us link to each bundle's Manage Display page.
    $linkableEntities = [
      'block_content',
      'comment',
      'commerce_product',
      'commerce_store',
      'contact_message',
      'media',
      'node',
      'paragraph',
      'block_content', 'comment', 'commerce_product', 'commerce_store',
      'contact_message', 'media', 'node', 'paragraph',
    ];

    foreach ($entities as $entity) {
@@ -270,10 +258,9 @@ class AddToAnySettingsForm extends ConfigFormBase {

        // Check if Field UI module enabled.
        if ($this->moduleHandler->moduleExists('field_ui')) {
          // Link to the bundle's Manage Display page if the entity ID supports
          // the route pattern.
          // Link to the bundle's Manage Display page if the entity ID supports the route pattern.
          if (in_array($entityId, $linkableEntities) && $entityType) {
            $links[] = Link::createFromRoute($this->t('%label', ['%label' => $label]), "entity.entity_view_display.{$entityId}.default", [
            $links[] = Link::createFromRoute(t($label), "entity.entity_view_display.{$entityId}.default", [
              $entityType => $machine_name,
            ])->toString();
          }
@@ -287,7 +274,7 @@ class AddToAnySettingsForm extends ConfigFormBase {
        '#title' => $this->t('@entity', ['@entity' => $entity->getLabel()]),
        '#default_value' => $addtoany_settings->get("entities.{$entityId}"),
        '#description' => $description,
        '#attributes' => ['class' => ['addtoany-entity-checkbox']],
        '#attributes' => ['class' => ['addtoany-entity-checkbox']]
      ];
    }

@@ -300,25 +287,6 @@ class AddToAnySettingsForm extends ConfigFormBase {
    return parent::buildForm($form, $form_state);
  }

  /**
   * Get all available content entities in the environment.
   *
   * @return array
   *   List of content entity types.
   */
  public static function getContentEntities() {
    $content_entity_types = [];
    $entity_type_definitions = Drupal::entityTypeManager()->getDefinitions();
    /** @var EntityTypeInterface $definition */
    foreach ($entity_type_definitions as $definition) {
      if ($definition instanceof ContentEntityType) {
        $content_entity_types[] = $definition;
      }
    }

    return $content_entity_types;
  }

  /**
   * {@inheritdoc}
   */
@@ -331,8 +299,7 @@ class AddToAnySettingsForm extends ConfigFormBase {
      ->set('buttons_size', $values['addtoany_buttons_size'])
      ->set('custom_universal_button', $values['addtoany_custom_universal_button'])
      ->set('universal_button', $values['addtoany_universal_button'])
      ->set('universal_button_placement', $values['addtoany_universal_button_placement'])
      ->set('library_location', $values['addtoany_library_location']);
      ->set('universal_button_placement', $values['addtoany_universal_button_placement']);

    foreach(self::getContentEntities() as $entity) {
      $entityId = $entity->id();
@@ -346,12 +313,19 @@ class AddToAnySettingsForm extends ConfigFormBase {
  }

  /**
   * {@inheritdoc}
   * Get all available content entities in the environment.
   * @return array
   */
  protected function getEditableConfigNames() {
    return [
      'addtoany.settings',
    ];
  public static function getContentEntities() {
    $content_entity_types = [];
    $entity_type_definitions = \Drupal::entityTypeManager()->getDefinitions();
    /* @var $definition EntityTypeInterface */
    foreach ($entity_type_definitions as $definition) {
      if ($definition instanceof ContentEntityType) {
        $content_entity_types[] = $definition;
      }
    }

    return $content_entity_types;
  }
}
+31 −96
Original line number Diff line number Diff line
@@ -3,14 +3,10 @@
namespace Drupal\addtoany\Plugin\Block;

use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Utility\Token;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Cache\Cache;

/**
 * Provides an 'AddToAny share' block.
@@ -20,89 +16,29 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 *   admin_label = @Translation("AddToAny share buttons"),
 * )
 */
class AddToAnyBlock extends BlockBase implements ContainerFactoryPluginInterface {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The current user.
   *
   * @var \Drupal\Core\Utility\Token
   */
  protected $token;

  /**
   * The route match.
   *
   * @var \Drupal\Core\Routing\RouteMatchInterface
   */
  protected $routeMatch;
class AddToAnyBlock extends BlockBase {

  /**
   * The AddToAny option keys used in this block.
   *
   * @var array
   */
  private $addtoanyOptionKeys = [
  private $addtoany_option_keys = [
    'link_url',
    'link_title',
    'buttons_size',
    'addtoany_html',
  ];

  /**
   * Creates a LocalActionsBlock instance.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   Entity type manager.
   * @param \Drupal\Core\Utility\Token $token
   *   Token manager.
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The route match.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, Token $token, RouteMatchInterface $route_match) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->entityTypeManager = $entity_type_manager;
    $this->token = $token;
    $this->routeMatch = $route_match;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('entity_type.manager'),
      $container->get('token'),
      $container->get('current_route_match')
    );
  }

  /**
   * {@inheritdoc}
   */
  public function build() {
    $build = [];
    $node_id = $this->routeMatch->getParameter('node');
    $node_id = \Drupal::routeMatch()->getParameter('node');
    if (is_numeric($node_id)) {
      $node = $this->entityTypeManager->getStorage('node')->load($node_id);
      $node = Node::load($node_id);
    }

    $is_node = isset($node) && $node instanceof NodeInterface ? TRUE : FALSE;
    $is_node = isset($node) && $node instanceof NodeInterface ? true : false;
    $data = $is_node ? addtoany_create_entity_data($node) : addtoany_create_data();

    $block_options = [];
@@ -122,8 +58,7 @@ class AddToAnyBlock extends BlockBase implements ContainerFactoryPluginInterface
    ];

    if ($is_node) {
      $build['#addtoany_html'] = $this->token
        ->replace($data['addtoany_html'], ['node' => $node]);
      $build['#addtoany_html'] = \Drupal::token()->replace($data['addtoany_html'], ['node' => $node]);
    }

    return $build;
Loading