Problem/Motivation

With the current implementation you can get breadcrumbs on hierarchy by using a pathauto pattern to build the alias from the hierarchy and then use core's path based breadcrumbs, but that breaks if you want to give authors the ability to change aliases.

Proposed resolution

Add submodule with a breadcrumb builder.

Remaining tasks

Tests and code

User interface changes

N/A

API changes

N/A

Data model changes

N/A

CommentFileSizeAuthor
#9 interdiff.txt6.32 KBacbramley
#9 2861404-9.patch12.48 KBacbramley
#5 2861404-5.patch13.07 KBacbramley
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

acbramley created an issue. See original summary.

acbramley’s picture

I can work on this next week :)

acbramley’s picture

Title: Provide breadcrumb buidler » Provide breadcrumb submodule
acbramley’s picture

Assigned: Unassigned » acbramley

Working on this today

acbramley’s picture

Status: Active » Needs review
FileSize
13.07 KB

Here's a first cut of it, there's a few assumptions in the builder that I'm not too sure of right now but thought I'd upload to get some feedback.

larowlan’s picture

Looking good

  1. +++ b/entity_hierarchy_breadcrumb/src/HierarchyBasedBreadcrumbBuilder.php
    @@ -0,0 +1,213 @@
    +  /**
    +   * The parent candidate service.
    +   *
    +   * @var \Drupal\entity_hierarchy\Information\ParentCandidateInterface
    +   */
    +  protected $parentCandidate;
    ...
    +   * @param \Drupal\entity_hierarchy\Information\ParentCandidateInterface $parent_candidate
    +   *   The parent candidate service.
    ...
    +    $this->parentCandidate = $parent_candidate;
    

    Not used anymore?

  2. +++ b/entity_hierarchy_breadcrumb/src/HierarchyBasedBreadcrumbBuilder.php
    @@ -0,0 +1,213 @@
    +    // TODO: Should we handle multiple fields??
    ...
    +      // TODO: Config option?
    ...
    +    // TODO: Config option?
    

    If people don't like the defaults, they can implement their own extending from this one.

    Happy to leave it as is.

  3. +++ b/entity_hierarchy_breadcrumb/src/HierarchyBasedBreadcrumbBuilder.php
    @@ -0,0 +1,213 @@
    +  private function getEntityFromRouteMatch(RouteMatchInterface $route_match) {
    ...
    +  private function getHierarchyFieldFromEntity(ContentEntityInterface $entity) {
    

    Lets make these protected in case someone wants to do something about multiple fields that is specific to their use-case - they can then extend

  4. +++ b/entity_hierarchy_breadcrumb/tests/src/Kernel/BreadcrumbTest.php
    @@ -0,0 +1,123 @@
    +    $this->testRoute = new Route('/entity_test/{entity_test}', [], [], ['parameters' => [static::ENTITY_TYPE => ['type' => 'entity:' . static::ENTITY_TYPE]]]);
    

    I think this will break phpcs

larowlan’s picture

acbramley’s picture

acbramley’s picture

FileSize
12.48 KB
6.32 KB

Addresses all feedback from #6, checked PHPCS and it didn't seem to have an issue with the Route object line.

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

  • larowlan committed 5566df6 on 8.x-2.x
    Issue #2861404 by larowlan: breadcrumb PHPCS
    
  • larowlan committed 8fda8ec on 8.x-2.x
    Issue #2861404 by larowlan: Move breadcrumb submodule
    
  • larowlan committed df5e7c0 on 8.x-2.x authored by acbramley
    Issue #2861404 by acbramley: Provide breadcrumb submodule
    
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.