Same filename in other branches
  1. 2.x easy_breadcrumb.module
  2. 7.x-1.x easy_breadcrumb.module
  3. 7.x-2.x easy_breadcrumb.module

The Easy Breadcrumb module improves the core system breadcrumbs.

Fichier

./easy_breadcrumb.module

View source
<?php


/**
 * @file
 * The Easy Breadcrumb module improves the core system breadcrumbs.
 */
use Drupal\Core\Block\BlockPluginInterface;

/**
 * Implements hook_help().
 */
function easy_breadcrumb_help($route_name) {
    switch ($route_name) {
        case 'help.page.easy_breadcrumb':
            $text = file_get_contents(__DIR__ . "/README.md");
            // If the Markdown module is installed...
            if (\Drupal::moduleHandler()->moduleExists('markdown') === TRUE) {
                // Uses the Markdown filter to render the README.
                $filter_manager = \Drupal::service('plugin.manager.filter');
                $settings = \Drupal::configFactory()->get('markdown.settings')
                    ->getRawData();
                $config = [
                    'settings' => $settings,
                ];
                $filter = $filter_manager->createInstance('markdown', $config);
                $output = $filter->process($text, 'en');
            }
            else {
                // Outputs the README in plain text.
                $output = '<pre>' . $text . '</pre>';
            }
            // Adds a link to the Drupal.org documentation pages.
            $output .= t('<p>See the <a href=":documentation">documentation pages</a> on Drupal.org for more information.</p>', [
                ':documentation' => 'https://www.drupal.org/docs/8/improve-the-breadcrumbs',
            ]);
            return $output;
    }
}

/**
 * Implements hook_block_view_BASE_BLOCK_ID_alter().
 */
function easy_breadcrumb_block_view_system_breadcrumb_block_alter(array &$build, BlockPluginInterface $block) {
    // Get JSON-LD.
    if ($json_ld = \Drupal::service('easy_breadcrumb.structured_data_json_ld')->value()) {
        // Prepare script tag.
        $structured_data = [
            '#tag' => 'script',
            '#attributes' => [
                'type' => 'application/ld+json',
            ],
            '#value' => $json_ld,
        ];
        // Add script tag.
        $build['#attached']['html_head'][] = [
            $structured_data,
            'easy_breadcrumb_structured_data_json_ld',
        ];
    }
}

Functions

Titre Deprecated Résumé
easy_breadcrumb_block_view_system_breadcrumb_block_alter Implements hook_block_view_BASE_BLOCK_ID_alter().
easy_breadcrumb_help Implements hook_help().