hoppinger/breadcrumb_builder 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hoppinger/breadcrumb_builder

最新稳定版本:v1.3

Composer 安装命令:

composer require hoppinger/breadcrumb_builder

包简介

Drupal module to build breadcrumbs

README 文档

README

Navigation can greatly enhance the way users find their way around. In terms of usability, breadcrumbs reduce the number of actions a website visitor needs to take in order to get to a higher-level page, and they improve the findability of website sections and pages. They are also an effective visual aid that indicates the location of the user within the website’s hierarchy, making it a great source of contextual information for landing pages.

Installation

composer require hoppinger/breadcrumb_builder

Usage

Path Breadcrumb builder automatically recognizes the correct breadcrumb you want based on the URLs of the pages and the items included in the menu. In case of special breadcrumb trail requirement, you can extend the functionality of the Path breadcrumb builder and create your own breadcrumb trail.

Create a custom service and define the service in the modulename.services.yml file. Replace the ExampleBreadcrumbBuilder with your own filename. Add the priority to the custom breadcrumb builder.

  class: Drupal\module_name\ExampleBreadcrumbBuilder
    arguments: ['@plugin.manager.menu.link']
    tags:
      - { name: custom_breadcrumb_builder, priority: x }

Create a file ExampleBreadcrumbBuilder.php inside the <module_name>/src folder and extend the Breadcrumb manager.

namespace Drupal\<module_name>;

use Drupal\breadcrumb_builder\BreadcrumbBuilderInterface;
use Drupal\Core\Menu\MenuLinkInterface;
use Drupal\Core\Menu\MenuLinkManagerInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\breadcrumb_builder\BreadcrumbResult;


class ExampleBreadcrumbBuilder implements BreadcrumbBuilderInterface {
  //Variables

  public function __construct() {
    //Intitialize
  }
  
   /**
   * {@inheritdoc}
   */
  public function applies(RouteMatchInterface $route_match) {
    return TRUE;
  } 

  public function build(RouteMatchInterface $route_match) {
    //Custom logic
  }
}

In some cases we need more menu types than the specified 'main' menu, to contribute to the breadcrumb generation.

Create a .php file in the module directory /src with the following content. Replace the <target_identifier> with the project-specific menu type that needs to be embedded into the API response (for example: footer)

The <target_identifiers> can be Menu types.

The filename must be similar to the module name i.e., ModuleNameServiceProvider.php and must be placed in the src folder.

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
use Symfony\Component\DependencyInjection\Reference;

class AlterServiceProvider extends ServiceProviderBase {
  public function alter(ContainerBuilder $container) {
    if ($container->hasParameter('breadcrumb_builder.target_identifiers')) {
      $target_identifiers = $container->getParameter('breadcrumb_builder.target_identifiers');
      
      $target_identifiers[] = <target_identifier>; #e.g., footer
  
      $container->setParameter('breadcrumb_builder.target_identifiers', $target_identifiers);
  }
}

By default, main menu is already added as the target identifier.

统计信息

  • 总下载量: 9.18k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 4
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2019-09-16