Class Drupal\Core\Breadcrumb\BreadcrumbPreprocess - Source Code

Primary tabs

API docs: https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Breadcrumb!BreadcrumbPreprocess.php/11.3.x

GitLab: https://git.drupalcode.org/project/drupal/-/blob/11.3.x/core/lib/Drupal/Core/Breadcrumb/BreadcrumbPreprocess.php

Location: /core/lib/Drupal/Core/Breadcrumb/BreadcrumbPreprocess.php

    
        
namespace Drupal\Core\Breadcrumb;

/**
 * Breadcrumb theme preprocess.
 *
 * @internal
 */
class BreadcrumbPreprocess {

  /**
   * Prepares variables for breadcrumb templates.
   *
   * Default template: breadcrumb.html.twig.
   *
   * @param array $variables
   *   An associative array containing:
   *   - links: A list of \Drupal\Core\Link objects which should be rendered.
   */
  public function preprocessBreadcrumb(array &$variables): void {
    $variables['breadcrumb'] = [];
    /** @var \Drupal\Core\Link $link */
    foreach ($variables['links'] as $key => $link) {
      $variables['breadcrumb'][$key] = [
        'text' => $link->getText(),
        'url' => $link->getUrl()->toString(),
      ];
    }
  }

}