You are here

protected function EasyBreadcrumbBuilder::removeRepeatedSegments in Easy Breadcrumb 8

Same name and namespace in other branches
  1. 2.x src/EasyBreadcrumbBuilder.php \Drupal\easy_breadcrumb\EasyBreadcrumbBuilder::removeRepeatedSegments()

Remove duplicate repeated segments.

Parameters

\Drupal\Core\Link[] $links: The links.

Return value

\Drupal\Core\Link[] The new links.

1 call to EasyBreadcrumbBuilder::removeRepeatedSegments()
EasyBreadcrumbBuilder::build in src/EasyBreadcrumbBuilder.php
Builds the breadcrumb.

File

src/EasyBreadcrumbBuilder.php, line 755

Class

EasyBreadcrumbBuilder
Primary implementation for the Easy Breadcrumb builder.

Namespace

Drupal\easy_breadcrumb

Code

protected function removeRepeatedSegments(array $links) {
  $newLinks = [];

  /** @var \Drupal\Core\Link $last */
  $last = NULL;
  foreach ($links as $link) {
    if (empty($last) || !$this
      ->linksAreEqual($last, $link)) {
      $newLinks[] = $link;
    }
    $last = $link;
  }
  return $newLinks;
}