Commit 54d39dac authored by Ryan Hartman's avatar Ryan Hartman Committed by micropat
Browse files

Issue #3212302 by devkinetic, kachinsky, netsliver, Damien Laguerre,...

Issue #3212302 by devkinetic, kachinsky, netsliver, Damien Laguerre, VladimirAus: Block Display is random for anonymous

Revert af20f592 for real this time.
parent 3f44067f
Loading
Loading
Loading
Loading
+8 −13
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@ use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
use Drupal\Core\Cache\Cache;

/**
 * Provides an 'AddToAny share' block.
@@ -14,6 +13,9 @@ use Drupal\Core\Cache\Cache;
 * @Block(
 *   id = "addtoany_block",
 *   admin_label = @Translation("AddToAny share buttons"),
 *   context_definitions = {
 *     "node" = @ContextDefinition("entity:node", required = FALSE, label = @Translation("Node"))
 *   }
 * )
 */
class AddToAnyBlock extends BlockBase {
@@ -33,12 +35,9 @@ class AddToAnyBlock extends BlockBase {
   */
  public function build() {
    $build = [];
    $node_id = \Drupal::routeMatch()->getParameter('node');
    if (is_numeric($node_id)) {
      $node = Node::load($node_id);
    }
    $node = $this->getContextValue('node');

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

    $block_options = [];
@@ -55,6 +54,9 @@ class AddToAnyBlock extends BlockBase {
      '#universal_button_placement' => $data['universal_button_placement'],
      '#buttons_size'               => $block_options['buttons_size'],
      '#theme'                      => 'addtoany_standard',
      '#cache'                      => [
        'contexts' => ['url'],
      ],
    ];

    if ($is_node) {
@@ -152,11 +154,4 @@ class AddToAnyBlock extends BlockBase {
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheContexts() {
    return Cache::mergeContexts(parent::getCacheContexts(), ['url']);
  }

}