Skip to content

Commit d8d82dd

Browse files
authored
Merge pull request #8146 from cakephp/breadcrumbs-addmany-docs
Add docs for BreadcrumbsHelper::addMany() and prependMany()
2 parents ee0f423 + 2f2dbe1 commit d8d82dd

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

en/appendices/5-3-migration-guide.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ Plugin
8282
which don't have one, you can use the ``bin/cake bake plugin MyPlugin --class-only``
8383
command, which will create the file ``plugins/MyPlugin/src/MyPlugin.php``.
8484

85+
View
86+
----
87+
88+
- Passing an array as the first argument to ``BreadcrumbsHelper::add()`` and
89+
``BreadcrumbsHelper::prepend()`` is deprecated. Use ``addMany()`` and
90+
``prependMany()`` instead.
91+
8592
New Features
8693
============
8794

@@ -257,3 +264,7 @@ View
257264
that exceed it. A new ``steps`` option was added to automatically generate limit
258265
options in multiples of a specific value (e.g., ``['steps' => 10]`` generates
259266
10, 20, 30... up to maxLimit).
267+
268+
- :php:meth:`BreadcrumbsHelper::addMany()` and :php:meth:`BreadcrumbsHelper::prependMany()`
269+
were added. These methods allow adding multiple breadcrumbs at once with support
270+
for shared options that apply to all crumbs.

en/views/helpers/breadcrumbs.rst

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,12 @@ In addition to adding to the end of the trail, you can do a variety of operation
2929
['controller' => 'products', 'action' => 'index']
3030
);
3131

32-
// Add multiple crumbs at the end of the trail
33-
$this->Breadcrumbs->add([
34-
['title' => 'Products', 'url' => ['controller' => 'products', 'action' => 'index']],
35-
['title' => 'Product name', 'url' => ['controller' => 'products', 'action' => 'view', 1234]],
36-
]);
37-
3832
// Prepended crumbs will be put at the top of the list
3933
$this->Breadcrumbs->prepend(
4034
'Products',
4135
['controller' => 'products', 'action' => 'index']
4236
);
4337

44-
// Prepend multiple crumbs at the top of the trail, in the order given
45-
$this->Breadcrumbs->prepend([
46-
['title' => 'Products', 'url' => ['controller' => 'products', 'action' => 'index']],
47-
['title' => 'Product name', 'url' => ['controller' => 'products', 'action' => 'view', 1234]],
48-
]);
49-
5038
// Insert in a specific slot. If the slot is out of
5139
// bounds, an exception will be raised.
5240
$this->Breadcrumbs->insertAt(
@@ -73,6 +61,37 @@ In addition to adding to the end of the trail, you can do a variety of operation
7361
['controller' => 'products', 'action' => 'index']
7462
);
7563

64+
Adding Multiple Crumbs
65+
----------------------
66+
67+
.. versionadded:: 5.3
68+
69+
You can add or prepend multiple crumbs at once using ``addMany()`` and
70+
``prependMany()``. These methods accept an array of crumbs and optional shared
71+
options that apply to all crumbs::
72+
73+
// Add multiple crumbs at the end of the trail
74+
$this->Breadcrumbs->addMany([
75+
['title' => 'Products', 'url' => ['controller' => 'products', 'action' => 'index']],
76+
['title' => 'Product name', 'url' => ['controller' => 'products', 'action' => 'view', 1234]],
77+
]);
78+
79+
// Prepend multiple crumbs at the top of the trail, in the order given
80+
$this->Breadcrumbs->prependMany([
81+
['title' => 'Products', 'url' => ['controller' => 'products', 'action' => 'index']],
82+
['title' => 'Product name', 'url' => ['controller' => 'products', 'action' => 'view', 1234]],
83+
]);
84+
85+
// Add multiple crumbs with shared options applied to all
86+
$this->Breadcrumbs->addMany([
87+
['title' => 'Home', 'url' => '/'],
88+
['title' => 'Products', 'url' => '/products'],
89+
['title' => 'Category'],
90+
], ['class' => 'breadcrumb-item']);
91+
92+
The shared options are merged with any options specified on individual crumbs,
93+
with individual crumb options taking precedence.
94+
7695
Using these methods gives you the ability to work with CakePHP's 2-step
7796
rendering process. Since templates and layouts are rendered from the inside out
7897
(meaning, included elements are rendered first), this allows you to define
@@ -190,7 +209,7 @@ when you want to transform the crumbs and overwrite the list::
190209
return $crumb;
191210
})->toArray();
192211

193-
$this->Breadcrumbs->reset()->add($crumbs);
212+
$this->Breadcrumbs->reset()->addMany($crumbs);
194213

195214
.. meta::
196215
:title lang=en: BreadcrumbsHelper

0 commit comments

Comments
 (0)