Commit f7a824dc by Manzar Hussain

add breadcrumb

parent feb80430
CONTENTS OF THIS FILE
---------------------
* Introduction
* Requirements
* Installation
* Configuration
* Maintainers
INTRODUCTION
------------
The Easy Breadcrumb module provides configurable breadcrumbs that improve on
core breadcrumbs by including the current page title as an unlinked crumb which
follows breadcrumb best-practices
(URL "https://www.nngroup.com/articles/breadcrumb-navigation-useful/").
Easy Breadcrumb takes advantage of the work you've already done for generating
your path aliases, while it naturally encourages the creation of semantic
and consistent paths. This module is currently available for Drupal 6.x, 7.x,
and 8.x.x.
Easy Breadcrumb uses the current URL (path alias) and the current page's title
to automatically extract the breadcrumb's segments and its respective links.
The module is really a plug and play module because it auto-generates the
breadcrumb by using the current URL and nothing extra is needed.
* For a full description of the module visit:
https://www.drupal.org/project/easy_breadcrumb
or
https://www.drupal.org/docs/8/improve-the-breadcrumbs
* To submit bug reports and feature suggestions, or to track changes visit:
https://www.drupal.org/node/2929013
REQUIREMENTS
------------
This module requires no modules outside of Drupal core.
INSTALLATION
------------
Install the Easy Breadcrumb module as you would normally install a contributed
Drupal module. Visit https://www.drupal.org/node/1897420 for further
information.
CONFIGURATION
-------------
1. Navigate to Administration > Extend and enable the module. The system
breadcrumb block has now been updated.
2. Navigate to Administration > Configuration > User Interface > Easy
Breadcrumb for configurations. Save Configurations.
Configurable parameters:
* Include / Exclude the front page as a segment in the breadcrumb.
* Include / Exclude the current page as the last segment in the breadcrumb.
* Use the real page title when it is available instead of always deducing it
from the URL.
* Print the page's title segment as a link.
* Make the language path prefix a segment on multilingual sites where a path
prefix ("/en") is used.
* Use menu title as fallback instead of raw path component.
* Remove segments of the breadcrumb that are identical.
* Use a custom separator between the breadcrumb's segments. (TODO)
* Choose a transformation mode for the segments' title.
* Make the 'capitalizator' ignore some words.
MAINTAINERS
-----------
* Greg Boggs - https://www.drupal.org/u/greg-boggs
* Neslee Canil Pinto - https://www.drupal.org/u/neslee-canil-pinto
* Jeff Mahoney (loopduplicate) - https://www.drupal.org/u/loopduplicate
Supporting organization:
* Kanopi Studios - https://www.drupal.org/kanopi-studios
{
"name": "drupal/easy_breadcrumb",
"type": "drupal-module",
"description": "Adds configuration to the system breadcrumbs.",
"homepage": "https://www.drupal.org/project/easy_breadcrumb",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "Neslee Canil Pinto",
"homepage": "https://www.drupal.org/u/neslee-canil-pinto",
"role": "Maintainer"
},
{
"name": "Greg Boggs",
"homepage": "https://www.drupal.org/u/greg-boggs",
"role": "Maintainer"
}
],
"support": {
"issues": "https://www.drupal.org/project/issues/easy_breadcrumb",
"source": "https://git.drupalcode.org/project/easy_breadcrumb"
},
"require": {
"drupal/core": "^8 || ^9"
}
}
applies_admin_routes: TRUE
include_home_segment: TRUE
home_segment_title: 'Home'
home_segment_keep: FALSE
include_title_segment: TRUE
language_path_prefix_as_segment: FALSE
use_menu_title_as_fallback: FALSE
use_page_title_as_menu_title_fallback: FALSE
remove_repeated_segments: TRUE
term_hierarchy: FALSE
absolute_paths: FALSE
hide_single_home_item: FALSE
title_from_page_when_available: TRUE
capitalizator_mode: 'ucwords'
capitalizator_ignored_words:
- of
- and
- or
- de
- del
- y
- o
- a
capitalizator_forced_words_first_letter: FALSE
capitalizator_forced_words_case_sensitivity: TRUE
add_structured_data_jsonld: FALSE
use_site_title: FALSE
dependencies:
module:
- easy_breadcrumb
enforced:
module:
- easy_breadcrumb
easy_breadcrumb.settings:
type: config_object
label: 'Easy Breadcrumb'
mapping:
applies_admin_routes:
type: boolean
label: 'Applies to administration pages'
include_invalid_paths:
type: boolean
label: 'Include invalid paths alias as plain-text segments'
excluded_paths:
type: text
label: 'Paths to be excluded while generating segments'
replaced_titles:
type: text
label: 'Titles to be replaced with synonyms'
custom_paths:
type: text
label: 'Paths requiring custom breadcrumbs'
include_home_segment:
type: boolean
label: 'Include the front page as a segment in the breadcrumb'
home_segment_title:
type: label
label: 'Title for the front page segment in the breadcrumb'
translatable: true
home_segment_keep:
type: boolean
label: 'Display the front page segment on the front page'
include_title_segment:
type: boolean
label: 'Include the current page as a segment in the breadcrumb'
title_from_page_when_available:
type: boolean
label: 'Use the real page title when available'
title_segment_as_link:
type: boolean
label: 'Make the page title segment a link'
segments_separator:
type: text
label: 'Segments Separator'
use_menu_title_as_fallback:
type: boolean
label: 'Use menu title as fallback instead of raw path component'
use_page_title_as_menu_title_fallback:
type: boolean
label: 'Use the page title as a fallback if the menu title is not set'
remove_repeated_segments:
type: boolean
label: 'Remove repeated identical segments'
language_path_prefix_as_segment:
type: boolean
label: 'Use language path prefix as segment'
absolute_paths:
type: boolean
label: 'Use absolute path for Breadcrumb links'
hide_single_home_item:
type: boolean
label: 'Hide the breadcrumb when it only links to the home page and nothing more'
term_hierarchy:
type: boolean
label: 'Use term hierarchy'
add_structured_data_jsonld:
type: boolean
label: 'Add current breadcrumb as structured data in JSON-LD to the HTML head'
use_site_title:
type: boolean
label: 'Use site title for the front page segment in the breadcrumb'
easy_breadcrumb.general_settings_form:
title: 'Easy Breadcrumb'
base_route_name: easy_breadcrumb.general_settings_form
names:
- easy_breadcrumb.settings
name: 'Easy Breadcrumb'
type: module
description: 'Provides configurable path based breadcrumbs.'
core: 8.x
core_version_requirement: ^8 || ^9
configure: easy_breadcrumb.general_settings_form
# Information added by Drupal.org packaging script on 2020-07-22
version: '8.x-1.13'
project: 'easy_breadcrumb'
datestamp: 1595377204
<?php
/**
* @file
* Add installation messages to help users get started and update.
*/
use Drupal\easy_breadcrumb\EasyBreadcrumbConstants;
/**
* Implements hook_update().
*
* Force an update because we removed an unused service.
*/
function easy_breadcrumb_update_8001() {
// Do nothing because database updates run cache rebuild.
}
/**
* Implements hook_update().
*
* Update home_segment_keep config from integer to boolean.
*/
function easy_breadcrumb_update_8002() {
$config = \Drupal::configFactory()->getEditable(EasyBreadcrumbConstants::MODULE_SETTINGS);
$home_segment_keep = $config->get(EasyBreadcrumbConstants::HOME_SEGMENT_KEEP);
// If the setting is enabled, store it as TRUE.
if ($home_segment_keep === 1) {
$config->set(EasyBreadcrumbConstants::HOME_SEGMENT_KEEP, TRUE);
}
// Otherwise, store it as FALSE.
else {
$config->set(EasyBreadcrumbConstants::HOME_SEGMENT_KEEP, FALSE);
}
$config->save();
}
/**
* Implements hook_update().
*
* Force an update because we updated the depedency injection which requires a
* cache clear.
*/
function easy_breadcrumb_update_8003() {
// Do nothing because database updates run cache rebuild.
}
/**
* Implements hook_update().
*
* Force a cache update because we changed service dependencies.
*/
function easy_breadcrumb_update_8004() {
// Do nothing because database updates run cache rebuild.
}
/**
* Force cache rebuild for newly added service to be picked up.
*/
function easy_breadcrumb_update_8005() {
drupal_flush_all_caches();
}
/**
* Implements hook_install().
*
* Help users get started with the module.
*/
function easy_breadcrumb_install() {
$messenger = \Drupal::messenger();
$help_url = 'https://www.drupal.org/docs/8/modules/easy-breadcrumb';
$messenger->addMessage("Easy Breadcrumb documentation is found in the help module or at $help_url.");
// Clear the cache so that the breadcrumbs appear after install.
drupal_flush_all_caches();
}
easy_breadcrumb.general_settings_form:
route_name: easy_breadcrumb.general_settings_form
title: 'Easy breadcrumb'
description: 'Controls settings for the module Easy Breadcrumb'
parent: system.admin_config_ui
easy_breadcrumb.general_settings_form_tab:
route_name: easy_breadcrumb.general_settings_form
title: Settings
base_route: easy_breadcrumb.general_settings_form
<?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 the Markdown module is not installed...
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',
];
}
}
administer easy breadcrumb:
title: 'Administer Easy Breadcrumb settings'
easy_breadcrumb.general_settings_form:
path: /admin/config/user-interface/easy-breadcrumb
defaults:
_title: 'Easy Breadcrumb'
_form: \Drupal\easy_breadcrumb\Form\EasyBreadcrumbGeneralSettingsForm
requirements:
_permission: 'administer easy breadcrumb'
services:
easy_breadcrumb.breadcrumb:
class: Drupal\easy_breadcrumb\EasyBreadcrumbBuilder
arguments: ['@router.request_context', '@access_manager', '@router', '@request_stack', '@path_processor_manager', '@config.factory', '@title_resolver', '@current_user', '@path.current', '@plugin.manager.menu.link', '@language_manager', '@entity_type.manager', '@entity.repository', '@logger.factory', '@messenger', '@module_handler']
tags:
- { name: breadcrumb_builder, priority: 1003 }
easy_breadcrumb.structured_data_json_ld:
class: Drupal\easy_breadcrumb\EasyBreadcrumbStructuredDataJsonLd
arguments: ['@easy_breadcrumb.breadcrumb', '@config.factory', '@current_route_match']
<?php
namespace Drupal\easy_breadcrumb;
/**
* EasyBreadcrumb module's contants.
*/
class EasyBreadcrumbConstants {
/**
* Module's name.
*/
const MODULE_NAME = 'easy_breadcrumb';
/**
* Module's settings.
*/
const MODULE_SETTINGS = 'easy_breadcrumb.settings';
/**
* Flag for applying easy breadcrumb to admin routes.
*/
const APPLIES_ADMIN_ROUTES = 'applies_admin_routes';
/**
* Flag for including invalid paths while generating the breadcrumb segments.
*/
const INCLUDE_INVALID_PATHS = 'include_invalid_paths';
/**
* List of paths to be excluded from the generated segments.
*/
const EXCLUDED_PATHS = 'excluded_paths';
/**
* List of titles to replace.
*/
const REPLACED_TITLES = 'replaced_titles';
/**
* List of paths for custom breadcrumbs.
*/
const CUSTOM_PATHS = 'custom_paths';
/**
* Separator between segments.
*/
const SEGMENTS_SEPARATOR = 'segments_separator';
/**
* Flag for including or not the front page as a segment.
*/
const INCLUDE_HOME_SEGMENT = 'include_home_segment';
/**
* Title for the front page segment.
*/
const HOME_SEGMENT_TITLE = 'home_segment_title';
/**
* Flag for keeping the breadcrumb on the front page.
*/
const HOME_SEGMENT_KEEP = 'home_segment_keep';
/**
* Flag for including or not the page's title as a segment.
*/
const INCLUDE_TITLE_SEGMENT = 'include_title_segment';
/**
* Flag for printing the page's title as a link, or printing it as a text.
*/
const TITLE_SEGMENT_AS_LINK = 'title_segment_as_link';
/**
* Use the page's title when it is available.
*/
const TITLE_FROM_PAGE_WHEN_AVAILABLE = 'title_from_page_when_available';
/**
* Transformation mode to apply to the segments.
*/
const CAPITALIZATOR_MODE = 'capitalizator_mode';
/**
* List of words to be ignored by the 'capitalizator'. E.g.: of and.
*/
const CAPITALIZATOR_IGNORED_WORDS = 'capitalizator_ignored_words';
/**
* List of words to be forced by the 'capitalizator'. E.g.: your brand's name.
*/
const CAPITALIZATOR_FORCED_WORDS = 'capitalizator_forced_words';
/**
* List of words to be forced by the 'capitalizator'. E.g.: your brand's name.
*/
const CAPITALIZATOR_FORCED_WORDS_FIRST_LETTER = 'capitalizator_forced_words_first_letter';
/**
* Logical value to 'Make the first letters of each segment capitalized'.
*/
const CAPITALIZATOR_FORCED_WORDS_CASE_SENSITIVITY = 'capitalizator_forced_words_case_sensitivity';
/**
* Flag for showing the language prefix as its own segment.
*/
const LANGUAGE_PATH_PREFIX_AS_SEGMENT = 'language_path_prefix_as_segment';
/**
* Use menu title as fallback.
*/
const USE_MENU_TITLE_AS_FALLBACK = 'use_menu_title_as_fallback';
/**
* Use page title as fallback for menu title.
*/
const USE_PAGE_TITLE_AS_MENU_TITLE_FALLBACK = 'use_page_title_as_menu_title_fallback';
/**
* Use site title as the front page segment.
*/
const USE_SITE_TITLE = 'use_site_title';
/**
* Flag for removing repeated identical segments from the breadcrumb.
*/
const REMOVE_REPEATED_SEGMENTS = 'remove_repeated_segments';
/**
* Flag for storing absolute path settings.
*/
const ABSOLUTE_PATHS = 'absolute_paths';
/**
* Flag for storing single home item settings.
*/
const HIDE_SINGLE_HOME_ITEM = 'hide_single_home_item';
/**
* Flag for using term hierarchy.
*/
const TERM_HIERARCHY = 'term_hierarchy';
/**
* Flag for adding the breadcrumb as structured to the HTML head.
*/
const ADD_STRUCTURED_DATA_JSON_LD = 'add_structured_data_json_ld';
/**
* Default list of excluded paths.
*
* @return array
* Default list of ignored paths.
*/
public static function defaultExcludedPaths() {
static $default_excluded_paths = [
'search',
'search/node',
];
return $default_excluded_paths;
}
/**
* Default list of replaced titles.
*
* @return array
* Default list of replaced titles.
*/
public static function defaultReplacedTitles() {
return [];
}
/**
* Default list of replaced paths.
*
* @return array
* Default list of replaced paths.
*/
public static function defaultCustomPaths() {
return [];
}
}
<?php
namespace Drupal\easy_breadcrumb;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class EasyBreadcrumbStructuredDataJsonLd.
*
* @package Drupal\easy_breadcrumb
*/
class EasyBreadcrumbStructuredDataJsonLd implements ContainerInjectionInterface {
/**
* The Easy Breadcrumb builder.
*
* @var \Drupal\easy_breadcrumb\EasyBreadcrumbBuilder
*/
protected $easyBreadcrumbBuilder;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* EasyBreadcrumbStructuredDataJsonLd constructor.
*
* @param \Drupal\easy_breadcrumb\EasyBreadcrumbBuilder $easy_breadcrumb_builder
* The Easy Breadcrumb builder.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*/
public function __construct(EasyBreadcrumbBuilder $easy_breadcrumb_builder, ConfigFactoryInterface $config_factory, RouteMatchInterface $route_match) {
$this->easyBreadcrumbBuilder = $easy_breadcrumb_builder;
$this->configFactory = $config_factory;
$this->routeMatch = $route_match;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('easy_breadcrumb.breadcrumb'),
$container->get('config.factory'),
$container->get('current_route_match')
);
}
/**
* Build JSON-LD value.
*/
public function value() {
$value = FALSE;
$config = $this->configFactory->get(EasyBreadcrumbConstants::MODULE_SETTINGS);
if ($config->get(EasyBreadcrumbConstants::ADD_STRUCTURED_DATA_JSON_LD)) {
/** @var \Drupal\Core\Breadcrumb\Breadcrumb $breadcrumb */
$breadcrumb = $this->easyBreadcrumbBuilder->build($this->routeMatch);
$links = $breadcrumb->getLinks();
// Only fire if at least one link present.
if (count($links) > 0) {
// Open JSON.
$value = '{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [';
$position = 1;
/** @var \Drupal\Core\Link $link */
foreach ($links as $link) {
$name = $link->getText();
$item = $link->getUrl()->setAbsolute(TRUE)->toString();
// Add a comma before each item except the first.
if ($position > 1) {
$value .= ',';
}
// Only add item if link's not empty.
if (!empty($item)) {
$value .= '{
"@type": "ListItem",
"position": "' . $position . '",
"name": "' . $name . '",
"item": "' . $item . '"
}';
}
else {
$value .= '{
"@type": "ListItem",
"position": "' . $position . '",
"name": "' . $name . '"
}';
}
// Increment position for next run.
$position++;
}
// Close JSON.
$value .= ']}';
}
}
return $value;
}
}
name: 'Easy Breadcrumb Testing'
description: 'Provides routes and controllers for automated testing.'
package: Testing
core: 8.x
core_version_requirement: ^8 || ^9
type: module
# Information added by Drupal.org packaging script on 2020-07-22
version: '8.x-1.13'
project: 'easy_breadcrumb'
datestamp: 1595377204
easy_breadcrumb_test.title_string:
path: /test/easy-breadcrumb
defaults:
_title: 'Easy Breadcrumb'
_controller: '\Drupal\easy_breadcrumb_test\Controller\TestRouteController::page'
easy_breadcrumb_test.title_formattable_markup:
path: /test/easy-breadcrumb-formattable
defaults:
_controller: '\Drupal\easy_breadcrumb_test\Controller\TestRouteController::page'
_title_callback: '\Drupal\easy_breadcrumb_test\Controller\TestRouteController::pageTitleFormattableMarkup'
easy_breadcrumb_test.title_markup:
path: /test/easy-breadcrumb-markup
defaults:
_controller: '\Drupal\easy_breadcrumb_test\Controller\TestRouteController::page'
_title_callback: '\Drupal\easy_breadcrumb_test\Controller\TestRouteController::pageTitleMarkup'
easy_breadcrumb_test.title_translatable_markup:
path: /test/easy-breadcrumb-translatable
defaults:
_controller: '\Drupal\easy_breadcrumb_test\Controller\TestRouteController::page'
_title_callback: '\Drupal\easy_breadcrumb_test\Controller\TestRouteController::pageTitleTranslatableMarkup'
easy_breadcrumb_test.title_render_array:
path: /test/easy-breadcrumb-render-array
defaults:
_controller: '\Drupal\easy_breadcrumb_test\Controller\TestRouteController::page'
_title_callback: '\Drupal\easy_breadcrumb_test\Controller\TestRouteController::pageTitleRender'
<?php
namespace Drupal\easy_breadcrumb_test\Controller;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Render\Markup;
/**
* Provides block routines for search server-specific routes.
*/
class TestRouteController extends ControllerBase {
/**
* Displays page for testing purposes.
*
* @return array
* An array suitable for drupal_render().
*/
public function page() {
return [
'#markup' => 'Test Page',
];
}
/**
* Returns the page title as FormattableMarkup.
*
* Among other places,
* used in Drupal\search_api\Controller\IndexController.php.
*
* @return \Drupal\Component\Render\FormattableMarkup
* The page title.
*/
public function pageTitleFormattableMarkup() {
return new FormattableMarkup('Type: @type', ['@type' => FormattableMarkup::class]);
}
/**
* Returns the page title as Markup.
*
* Used in views page titles.
*
* @return \Drupal\Component\Render\Markup
* The page title.
*/
public function pageTitleMarkup() {
return Markup::create(Xss::filter('Markup'));
}
/**
* Returns the page title as TranslatableMarkup.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup
* The page title.
*/
public function pageTitleTranslatableMarkup() {
return $this->t('TranslatableMarkup');
}
/**
* Returns the page title as FormattableMarkup.
*
* @return array
* The page title.
*/
public function pageTitleRender() {
return [
'#markup' => 'this is a string',
];
}
}
<?php
namespace Drupal\Tests\easy_breadcrumb\Kernel;
use Drupal\Core\Routing\RequestContext;
use Drupal\Core\Routing\RouteMatch;
use Drupal\Core\Url;
use Drupal\easy_breadcrumb\EasyBreadcrumbBuilder;
use Drupal\easy_breadcrumb\EasyBreadcrumbConstants;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
/**
* Tests the easy breadcrumb builder.
*
* @group easy_breadcrumb
*/
class EasyBreadcrumbBuilderTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['easy_breadcrumb', 'system', 'easy_breadcrumb_test'];
/**
* Tests the front page with an invalid path.
*/
public function testFrontpageWithInvalidPaths() {
\Drupal::configFactory()->getEditable(EasyBreadcrumbConstants::MODULE_SETTINGS)
->set('include_invalid_paths', TRUE)
->set('include_title_segment', TRUE)
->save();
\Drupal::configFactory()->getEditable('system.site')
->set('page.front', '/path')
->save();
$request_context = new RequestContext();
$breadcrumb_builder = new EasyBreadcrumbBuilder($request_context,
\Drupal::service('access_manager'),
\Drupal::service('router'),
\Drupal::service('request_stack'),
\Drupal::service('path_processor_manager'),
\Drupal::service('config.factory'),
\Drupal::service('title_resolver'),
\Drupal::service('current_user'),
\Drupal::service('path.current'),
\Drupal::service('plugin.manager.menu.link'),
\Drupal::service('language_manager'),
\Drupal::service('entity_type.manager'),
\Drupal::service('entity.repository'),
\Drupal::service('logger.factory'),
\Drupal::service('messenger'),
\Drupal::service('module_handler')
);
$route_match = new RouteMatch('test_front', new Route('/front'));
$result = $breadcrumb_builder->build($route_match);
$this->assertCount(0, $result->getLinks());
}
/**
* Provides data for the get title string test.
*/
public function providerTestGetTitleString() {
return [
['easy_breadcrumb_test.title_string'],
['easy_breadcrumb_test.title_formattable_markup'],
['easy_breadcrumb_test.title_markup'],
['easy_breadcrumb_test.title_translatable_markup'],
['easy_breadcrumb_test.title_render_array'],
];
}
/**
* Tests getting title string from the various ways route titles can be set.
*
* @param string $route_name
* The route to test.
*
* @dataProvider providerTestGetTitleString
*/
public function testGetTitleString($route_name) {
$url = Url::fromRoute($route_name);
$request_context = new RequestContext();
$breadcrumb_builder = new EasyBreadcrumbBuilder($request_context,
\Drupal::service('access_manager'),
\Drupal::service('router'),
\Drupal::service('request_stack'),
\Drupal::service('path_processor_manager'),
\Drupal::service('config.factory'),
\Drupal::service('title_resolver'),
\Drupal::service('current_user'),
\Drupal::service('path.current'),
\Drupal::service('plugin.manager.menu.link'),
\Drupal::service('language_manager'),
\Drupal::service('entity_type.manager'),
\Drupal::service('entity.repository'),
\Drupal::service('logger.factory'),
\Drupal::service('messenger'),
\Drupal::service('module_handler')
);
$request = Request::create($url->getInternalPath());
$router = \Drupal::service('router.no_access_checks');
$route_match = new RouteMatch($route_name, $router->match($url->getInternalPath())['_route_object']);
$result = $breadcrumb_builder->getTitleString($request, $route_match, []);
$this->assertIsString($result);
}
}
...@@ -53,7 +53,17 @@ ...@@ -53,7 +53,17 @@
</div> </div>
</div> </div>
</div> </div>
<div class="container-fluid">
<div class="row">
<div class="container">
<div class="row">
<div class="col-12">
{{ page.breadcrumb }}
</div>
</div>
</div>
</div>
</div>
<div class="layout-container"> <div class="layout-container">
<div class="layout-content"> <div class="layout-content">
{{ page.content }} {{ page.content }}
......
{#
/**
* @file
* Theme override for a breadcrumb trail.
*
* Available variables:
* - breadcrumb: Breadcrumb trail items.
*/
#}
<!-- breadcurmb start -->
{% if breadcrumb %}
<nav class="border-bottom">
<ol class="cd-breadcrumb custom-separator">
{% for item in breadcrumb %}
{% if item.url %}
<li>
<a href="{{ item.url }}">{{ item.text }}</a> <i class="fa fa-angle-right" aria-hidden="true"></i>
</li>
{% else %}
<li class="breadcrumb_select">{{ item.text }}</li>
{% endif %}
{% endfor %}
</ol>
</nav>
{% endif %}
<!-- breadcurmd end -->
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment