Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions modules/tide_breadcrumbs/css/breadcrumb.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Styles for the computed breadcrumb trail.
*/
.custom-breadcrumb-container {
margin-bottom: 1.5rem;
padding: 0.5rem 0;
border-bottom: 1px solid #eee;
}

.custom-breadcrumb-container strong {
margin-right: 10px;
color: #333;
}

.custom-breadcrumb {
display: inline;
}

.custom-breadcrumb a {
text-decoration: none;
font-weight: 500;
color: #0056b3;
}

.custom-breadcrumb a:hover {
text-decoration: underline;
}

.custom-breadcrumb .divider {
color: #888;
padding: 0 8px;
font-size: 0.9em;
vertical-align: middle;
}
63 changes: 63 additions & 0 deletions modules/tide_breadcrumbs/src/BreadcrumbComputedField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Drupal\tide_breadcrumbs;

use Drupal\Core\Field\FieldItemList;
use Drupal\Core\TypedData\ComputedItemListTrait;
use Drupal\node\NodeInterface;

/**
* Represents the computed breadcrumb trail field for nodes.
*
* This field dynamically generates a breadcrumb trail based on the node's
* primary site and section site taxonomy terms, bridging multiple menu
* structures into a single unified trail.
*/
class BreadcrumbComputedField extends FieldItemList {
use ComputedItemListTrait;

/**
* Computes the breadcrumb trail value.
*
* Fetches the trail from the tide_breadcrumbs.breadcrumb_builder service
* and populates the field items with 'title' and
* 'url' properties for each crumb.
*/
protected function computeValue() {
$node = $this->getEntity();
// Ensure we are working with a node entity.
if (!$node instanceof NodeInterface) {
return;
}

/** @var \Drupal\tide_breadcrumbs\TideBreadcrumbBuilder $breadcrumb_service */
$breadcrumb_service = \Drupal::service('tide_breadcrumbs.breadcrumb_builder');
$trail = $breadcrumb_service->buildFullTrail($node);

if (!empty($trail) && is_array($trail)) {
// Reset the list to ensure no stale data exists during computation.
$this->list = [];

foreach ($trail as $delta => $item) {
// Create an item for each crumb in the trail.
$this->list[$delta] = $this->createItem($delta, [
'title' => $item['title'],
'url' => $item['url'],
]);
}
}
}

/**
* {@inheritdoc}
*
* Overridden to ensure the value is computed before being returned.
*/
public function getValue() {
if (!$this->valueComputed) {
$this->computeValue();
}
return parent::getValue();
}

}
Loading
Loading