Commit b09a9d23 authored by Rico Van de Vin's avatar Rico Van de Vin Committed by Kyrylo Loboda
Browse files

Issue #3250483 by ricovandevin: Use the entity comparison link template when...

Issue #3250483 by ricovandevin: Use the entity comparison link template when replacing the link with ajax
parent 8f1763a3
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -165,8 +165,15 @@ class EntityComparisonController extends ControllerBase implements ContainerInje
      // Create a new AJAX response.
      $response = new AjaxResponse();
      // Generate the link render array.
      $link = $entity_comparison->getLink($entity_id, TRUE);
      $link = $link->toRenderable();
      $link = [
        '#theme' => 'entity_comparison_link',
        '#id' => $entity_id,
        '#entity_comparison' => $entity_comparison_id,
        '#cache' => [
          'max-age' => 0,
        ],
        '#access' => $this->currentUser()->hasPermission("use {$entity_comparison_id} entity comparison"),
      ];
      // Generate a CSS selector to use in a JQuery Replace command.
      $selector = '[data-entity-comparison=' . $entity_comparison->id() . '-' . $entity_id . ']';

@@ -376,7 +383,16 @@ class EntityComparisonController extends ControllerBase implements ContainerInje
        // Add the first row, where the user can remove the selected content.
        $row = [$this->t('Remove from the list')];
        foreach (Element::children($comparison_fields) as $key) {
          $row[] = $entity_comparison->getLink($key, TRUE)->toString();
          $link = [
            '#theme' => 'entity_comparison_link',
            '#id' => $key,
            '#entity_comparison' => $entity_comparison_id,
            '#cache' => [
              'max-age' => 0,
            ],
            '#access' => $this->currentUser()->hasPermission("use {$entity_comparison_id} entity comparison"),
          ];
          $row[] = $this->renderer->render($link);
        }
        $rows[] = $row;

+10 −6
Original line number Diff line number Diff line
@@ -115,15 +115,19 @@ class EntityComparisonLinkBlock extends BlockBase implements ContainerFactoryPlu
    $node = \Drupal::routeMatch()->getParameter('node');
    if ($node instanceof NodeInterface) {
      // You can get nid and anything else you need from the node object.
      $nid = $node->id();
      /**
       * @var \Drupal\Core\Link $link
       */
      $link = $entity_comparison->getLink($nid, TRUE);
      return [
        '#theme' => 'entity_comparison_link',
        '#id' => $node->id(),
        '#entity_comparison' => $entity_comparison_id,
        '#cache' => [
          'max-age' => 0,
        ],
        '#access' => \Drupal::currentUser()->hasPermission("use {$entity_comparison_id} entity comparison"),
      ];
    }

    return [
      '#markup' => (isset($link)) ? $link->toString() : $entity_comparison->getAddLinkText(),
      '#markup' => $entity_comparison->getAddLinkText(),
      '#cache' => [
        'max-age' => 0,
      ],