PHP code example of hoppinger / breadcrumb_builder

1. Go to this page and download the library: Download hoppinger/breadcrumb_builder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hoppinger / breadcrumb_builder example snippets



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
  }
}

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);
  }
}