Comments (1)
Hi @ozahorulia ,
in case you don't know, you don't always need to extend the original class. Symfony provides the so called "Decorator pattern": https://symfony.com/doc/current/service_container/service_decoration.html
With this, you can basically wrap the original breadcrumbs builder ("decorate") and either alter its input or change its output. Only thing you need to do is implement the correct interface, so sonata (and you) knows that all the required methods are available, and mark your new service with #[AsDecorator(...)]
.
E.g.:
<?php
declare(strict_types=1);
namespace App;
use Knp\Menu\MenuItem;
use Sonata\AdminBundle\Admin\BreadcrumbsBuilderInterface;
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
use Symfony\Component\DependencyInjection\Attribute\AutowireDecorated;
#[AsDecorator(decorates: '@sonata.admin.breadcrumbs_builder')]
class MyCustomBreadcrumbsBuilder implements BreadcrumbsBuilderInterface
{
public function __construct(
#[AutowireDecorated]
private BreadcrumbsBuilderInterface $decorated,
) {
}
public function getBreadcrumbs(AdminInterface $admin, string $action): array
{
// Call the original breadcrumbs builder first
$breadcrumbs = $this->decorated->getBreadcrumbs($admin, $action);
// Detect if breadcrumbs should be changed
// if (...) {
// Change label of last breadcrumb
$lastBreadcrumb = $breadcrumbs[array_key_last(breadcrumbs)];
assert($lastBreadcrumb instanceof MenuItem);
$lastBreadcrumb->setLabel('My custom label');
// }
// Return the updated breadcrumbs list
return $breadcrumbs;
}
}
If you use an older symfony version where the AsDecorator
attribute is not available yet, just change the documentation version to your desired symfony version and you will get instructions for your version instead.
NOTE: I did not test this. Usually i just need breadcrumbs for my custom pages, which i provide manually via the twig breadcrumb
block in the template (setting this block overwrites the default breadcrumb). But this should work just like any other service decoration.
I hope this helps.
Greetings!
from sonataadminbundle.
Related Issues (20)
- Datepicker calendar window is placed incorrectly if the field is at the bottom HOT 1
- Unable to use a custom message to be shown as the error flash message HOT 2
- admin-lte js package 2.4 is concerned by known critical vulnerabilities HOT 5
- ChoiceFieldMaskType with expanded: true does not work well when icheck is disabled HOT 2
- ModelList btn_delete bug when hit Enter key HOT 2
- Allow customize sonata-admin webpack build(s) HOT 1
- Rebuild template layer HOT 6
- Submitting a form with ->render instead of ->renderWithExtraParams does not work HOT 9
- Security threat within symfony/twig-bridge HOT 3
- SAML SSO and SCIM to the Admin Panel HOT 2
- Using SubClasses in admins create either not handable translation ids or urly urls HOT 2
- Overriding createQuery doesn't seem to be a thing anymore HOT 2
- symfony 7 compatibility HOT 1
- Problem 1 - symfony/security-acl[v3.1.0, ..., v3.1.2] require symfony/security-core ^3.4|^4.4|^5.0 -> found symfony/security-core[v3.4.0, ..., v3.4.49, v4.4.0, ..., v4.4.48, v5.0.0, ..., v5.4.30] but it conflicts with your root composer.json require (7.0.*). HOT 2
- Customise error message for ModelManagerException HOT 1
- CSRF token error occurs on record creation after applying symfony/security-http security patch HOT 4
- `Uncaught TypeError: __webpack_require__.O is not a function` after upgrading to a version >=4.24.0 HOT 8
- List add item using inline form HOT 1
- The name "Doctrine\ODM\MongoDB\ArrayCollectionelements" contains illegal characters. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sonataadminbundle.