Commit 3e04670b authored by micropat's avatar micropat
Browse files

Refactor the last commit 94143374 to prevent error

parent 94143374
Loading
Loading
Loading
Loading
+7 −11
Original line number Diff line number Diff line
@@ -21,18 +21,14 @@ class AddToAnyBlock extends BlockBase {
   */
  public function build() {
    $build = [];
    $node = \Drupal::routeMatch()->getParameter('node');
    if (is_numeric($node)) {
      $node = Node::load($node);

      if ($node instanceof NodeInterface) {
        $data = addtoany_create_entity_data($node);
      }
    }
    else {
      $data = addtoany_create_data();
    $node_id = \Drupal::routeMatch()->getParameter('node');
    if (is_numeric($node_id)) {
      $node = Node::load($node_id);
    }

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

    $build = [
      '#addtoany_html'              => $data['addtoany_html'],
      '#link_url'                   => $data['link_url'],
@@ -47,7 +43,7 @@ class AddToAnyBlock extends BlockBase {
      ],
    ];

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