Coder Social home page Coder Social logo

apy / apybreadcrumbtrailbundle Goto Github PK

View Code? Open in Web Editor NEW
80.0 7.0 30.0 153 KB

Generate a dynamic Twig breadcrumbs trail via Annotations, PHP Attributes or PHP methods.

PHP 95.35% Makefile 3.10% Twig 1.55%
breadcrumbs symfony php annotations attributes symfony-bundle bundle twig

apybreadcrumbtrailbundle's Introduction

Getting Started With BreadcrumbTrailBundle

This bundle provides a breadcrumb trail service also known as breadcrumbs or Fil d'Ariane. Breadcrumbs can be defined with Attributes, annotations, PHP and Twig.

Installation

Please follow the steps given in installation.md to install this bundle.

Bundle documentation

Tests

Several make targets can get used to run the PHPUnit test suite on different PHP environments:

$ make test
$ make test-php73
$ make test-php74-lowest

In case all test suites pass but running tests still returns an error code, that might be related to the number of allowed deprecations. Make sure that the SYMFONY_DEPRECATIONS_HELPER value of max[self] as found in phpunit.xml.dist matches the "Remaining self deprecation notices" count from the test runner output.

Code style

PHP-CS-Fixer is used to keep the code style in shape. There is a make target that uses Docker to fix the code style without having to install any other dependencies:

$ make cs

Static code analysis

PHPStan is used to keep the code quality up to par. There is a make target that uses Docker to test the code quality without having to install any other dependencies:

$ make static

apybreadcrumbtrailbundle's People

Contributors

ben-synapse avatar cmfcmf avatar danez avatar hsz avatar maximepinot avatar mondane avatar nclshart avatar notfloran avatar npotier avatar richard87 avatar rvanlaak avatar strategy47 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

apybreadcrumbtrailbundle's Issues

Tag symfony 6.1

Hi,
I tried the master branch in my sf6.1/ php8.1 app and it seems running perfectly.
will you tag this version ?

regards

APY organization

Do you have room for an additional developer in the APY organization?

Update symfony/deprecation-contracts?

Is it possible to update symfony/deprecation-contracts to 3.*?

Currently v2.4 is preventing other packages from updating, e.g. api-platform:

  • apy/breadcrumbtrail-bundle dev-feature/php81-symfony6 requires symfony/deprecation-contracts ^2.4 -> satisfiable by symfony/deprecation-contracts[v2.4.0, ..., v2.5.2].
  • api-platform/core v3.0.5 requires symfony/deprecation-contracts ^3.1 -> satisfiable by symfony/deprecation-contracts[v3.1.0, v3.1.1].

Setter injection setTemplate never called => null template var instead of string

Hi everyone!

I simply installed the bundle but had this error:

Argument 1 passed to Twig\Environment::getTemplateClass() must be of the type string, null given, called in /var/www/election/vendor/twig/twig/src/Environment.php on line 309

In Resources/config/services.xml the setter injection should set the template property in APY\BreadcrumbTrailBundle\BreadcrumbTrail\Trail with the default template.
The apy_breadcrumb_trail.template is well defined (checked with bin/console debug:container --parameters).
I xdebugged it and the setter is never called.

I suspect the autowire="true" option to be part of the problem because I tried to set autowire="false" on the apy_breadcrumb_trail service definition only and debugging that service with bin/console debug:container APY\BreadcrumbTrailBundle\BreadcrumbTrail\Trail show the service is autowired.

I checked other bundle with setter injection like the standard symfony/twig-bundle and its setters are well called (but that bundle doesn't use autowiring).

My symfony version: 5.0.11 (so I'm stuck with the last version 1.6 of this bundle).

I read that you test the updates in other closed issue so maybe I got something wrong.

Bug 1.7 #[Breadcrumb("{book.title}")]

Hi,
First of all i would like to thank you for this bundle.

I found a bug in the 1.7 version.
If you try to access to the object property and the class toString method does not exist you get an error.

exemple :
#[Breadcrumb("{book.title}")]
-> Object of class App\Entity\Book could not be converted to string

The issue is in the Trail.php file line 103 :
$objectValue = (string) $object;

it should be something like
$objectValue = get_class($object);

Best regards

Introduce annotation to reset breadcrumb trail

I found another tiny bug
you cannot use this annotation to reset the trail cause in the constructor signature $title as no default value
#[Breadcrumb()] ->Too few arguments to function APY\BreadcrumbTrailBundle\Annotation\Breadcrumb::__construct()

Workaround: pass null
#[Breadcrumb(null)]

TODO

  • deprecate passing null, error on v2
  • introduce "reset trail" attribute class

Working without sensio extra framework

Hi,
I find an issue when we removed the deprecated sensioExtraFramework.
The $request->attributes does not have the entity name ($varName) property.
So it can't resolve the title like {user.username}.

I think i can decorate an event to fix add it but it seems a bad solution.

Best regards

New release

Hi, could you please tag a new release (for the SF 3 compatibility fixes). Thanks!

Continue trail of another Route

First, thanks for this amazing bundle. I have a suggestion that could be implemented:

There is an attribute to reset the Breadcrumb called: ResetBreadcrumbTrail. There could be another attribute that recieves the name of a route by parameter and continues the trail of an already declared Breadcrumb in that route.

This will help a lot because changes in a parent in the breadcrumb wouldn't break all the breadcrumbs in its descendants.

Found unknown escape character "\B"

Hi,
I just installed your bundle (look like nice :)), but i have a problem when i used it :
image

That's what i did to have this error, maybe I missed something ... (I'm on a SF 4.4 project):

  • composer require apy/breadcrumbtrail-bundle
  • next i saw this
    image
    Because i have flex on my project so it's ok :)
  • I add on my route index
    image
    Of course use has being added by my ide
    image
  • next I add in 'config/packages/twig.yaml'
    Those lines
    image
  • next i add in my template the render of breadcrumb :
    image

What I did wrong ? what I missed ? thank you.

It is not compatible with Symfony 7.0

When attempting to update to the latest version of Symfony, I encounter the following error:

PHP Fatal error:  Declaration of APY\BreadcrumbTrailBundle\DependencyInjection\Configuration::getConfigTreeBuilder() must be compatible with Symfony\Component\Config\Definition\ConfigurationInterface::getConfigTreeBuilder(): Symfony\Component\Config\Definition\Builder\TreeBuilder in appName\vendor\apy\breadcrumbtrail-bundle\src\DependencyInjection\Configuration.php on line 19    

Fatal error: Declaration of APY\BreadcrumbTrailBundle\DependencyInjection\Configuration::getConfigTreeBuilder() must be compatible with Symfony\Component\Config\Definition\ConfigurationInterface::getConfigTreeBuilder(): Symfony\Component\Config\Definition\Builder\TreeBuilder in appName\vendor\apy\breadcrumbtrail-bundle\src\DependencyInjection\Configuration.php on line 19
Symfony\Component\ErrorHandler\Error\FatalError^ {#3256
  #message: "Compile Error: Declaration of APY\BreadcrumbTrailBundle\DependencyInjection\Configuration::getConfigTreeBuilder() must be compatible with Symfony\Component\Config\Definition\ConfigurationInterface::getConfigTreeBuilder(): Symfony\Component\Config\Definition\Builder\TreeBuilder"
  #code: 0
  #file: "appName\vendor\apy\breadcrumbtrail-bundle\src\DependencyInjection\Configuration.php"
  #line: 19
  -error: array:4 [
    "type" => 64
    "message" => "Declaration of APY\BreadcrumbTrailBundle\DependencyInjection\Configuration::getConfigTreeBuilder() must be compatible with Symfony\Component\Config\Definition\ConfigurationInterface::getConfigTreeBuilder(): Symfony\Component\Config\Definition\Builder\TreeBuilder"
    "file" => "appName\vendor\apy\breadcrumbtrail-bundle\src\DependencyInjection\Configuration.php"
    "line" => 19
  ]
}

slug in Route parameter

Above all your work is great, its very suitable for me, but I just encountered a problem.
In your example we can add route parameter in annotation like :

@Breadcrumb("Level 4b", route={"name"="level_4b", "parameters"={"var1"=1,"var2"=2}})

How can I dynamically add like "id" or "slug" as parameter in route?

"parameters"={"id"="$id"}

or

"parameters"={"id"="{id}"}

both not work :(

Conversion from parameter to object not working as intended in Symfony 6.3

The following code doesn't work as intended:

 #[Route('/{id}', name: 'inicio')]
 #[Breadcrumb(title: "{convocatoria}" , routeName:'concursotraslados_inicio', routeParameters: ['id' => '{id}'])]
 public function inicio(Convocatoria $convocatoria) : Response
    {

Instead of showing __tostring of the object "convocatoria" it renders as "{convocatoria}" (literal), here is a image:

image

In the documentation, @ParamConverter is referenced. But that is deprecated and I undestand it shouldn't be used.

Is there an alternative way to do this?

Circular reference detected

Hi,
I've started using this bundle on my SF2.8 app, using annotations. I'm facing this weird issue : the first time I display the page, everything works great. But if I refresh the page, I get the following error

Circular reference detected for service "templating", path: "templating -> twig -> apy_breadcrumb_trail.twig.extension".

Here is my PHP code

/**
 * @Breadcrumb("home", route={"name"="home"})
 */
class MyController extends Controller
{
    /**
     * @Route("/var", name="var")
     * @Method({"GET"})
     * @Breadcrumb("var", route={"name"="var"})
     * @Template()
     */
    public function varAction($var)
    {
        // mycode
        return [''var' => $var];
    }
}

I'm also overriding the template but only to ass some Micro Data...

Any clue ?

Page freeze

I'm using Symfony 5.1 for a project when i use route parameter in annotation like @breadcrumb("myroute", route={"name"="my_route"}) it's not working. But If i remove(rename) the services.xml in the bundle's config folder, it's work.

Now if i use in annotations variable parameter like @breadcrumb('{User}"), it doesn't work as because services.xml is requested.
I tried to watch in code, but my knowledges is not enought with bundle configuration.

Now if i'm click on a link on my page, now services.xml is requested again

I think something in services.xml is deprecated and something happened with cache

If you'll can solve this bug, it will be super. Your bundle is probably the best for breadcrumbs generation.

Best regards

Deprecation Symfony 3.4

Hi,

When using this bundle in symfony 3.4+ you get a deprecation warning.

User Deprecated: The "apy_breadcrumb_trail" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.

Is this bundle still being supported or should I replace it with something else ?

PHP 8.1 deprecation warnings

After updating to PHP 8.1 the following warnings are issued:

Deprecated: Return type of APY\BreadcrumbTrailBundle\BreadcrumbTrail\Trail::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor\apy\breadcrumbtrail-bundle\src\BreadcrumbTrail\Trail.php on line 199
Deprecated: Return type of APY\BreadcrumbTrailBundle\BreadcrumbTrail\Trail::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor\apy\breadcrumbtrail-bundle\src\BreadcrumbTrail\Trail.php on line 191

EngineInterface is deprecated in Symfony 4.3, and they will only work with Twig

TwigEngine is deprecated in Symfony 4.3

/**
 * This engine knows how to render Twig templates.
 *
 * @author Fabien Potencier <[email protected]>
 *
 * @deprecated since version 4.3, to be removed in 5.0; use Twig instead.
 */
class TwigEngine implements EngineInterface, StreamingEngineInterface
{

Since APYBreadcrumbTrailBundle uses Twig anyway:

        <service id="apy_breadcrumb_trail.twig.extension" class="%apy_breadcrumb_trail.twig.extension.class%">
            <argument type="service" id="apy_breadcrumb_trail" />
            <argument type="service" id="twig" />
            <tag name="twig.extension" />
        </service>

(by the name twig.extension, it should just take the twig service, wich solves the problem).

    /**
     * BreadcrumbTrailExtension constructor.
     * @param Trail $trail
     * @param Environment $templating
     */
    public function __construct(Trail $trail, Twig\Environment $templating)
    {
        $this->trail = $trail;
        $this->templating = $templating;
    }

Add breadcrumb in template

I'm customizing the error template and want to add display a breadcrumb. Let's say for the 404-page, it should be:

Home > 404 page.

Is it possible to call your bundle in a template to add objects to the trail, if so, could you give an example?

Tag for stable version

It would be useful to have tags of the bundle, in order to be able to download the last stable version with our project.

What do you think?

Breadcrumb duplicates itself during functional tests

Breadcrumb is working fine when browsing pages, but not in functional test.

When there is only one page to display, it works fine. But if for example i try to go to the login page, connect the user and display an other page, i still have the breadcrumb from the login page in addition of the breadcrumb from the current page...

@ParamConverter not working

It seems that your annotation class is executed before the ParamConverter.

The request is not modified and we can not access the real entity.

(by the way I did not manage to call the request argument either ? )

Deprecation notices (symfony 5.2.6 / deprecation-contracts 2.4.0)

After updating the symfony deprecation-contracts to 2.4 I get these notices:
Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" in "(...)\vendor\apy\breadcrumbtrail-bundle\src\DependencyInjection/../Resources/config\services.xml" is deprecated.
and
Since symfony/dependency-injection 5.1: Not setting the attribute "version" of the node "deprecated" in "(...)\vendor\apy\breadcrumbtrail-bundle\src\DependencyInjection/../Resources/config\services.xml" is deprecated.
It seems that services.xml is missing the mentioned tags "package" and "version".

Overriding template in Symfony 5

Hello,

I've been using the bundle in a Symfony2 project and I'm now trying to implement it in a Symfony5 project. It works great but I'm a bit confused about the overriding of the default template.

Looking through the others issues, I'm not even sure if the bundle supports Symfony 4/5. After trying different things, I'm asking for a little help.

I tried to follow the documentation : https://github.com/APY/APYBreadcrumbTrailBundle/blob/master/src/Resources/doc/override_template.md, but it's not up to date for Symfony5 as the config/config.yml file does not exist anymore. It should be replaced by a "apy_breadcrumb_trail.yaml" file, with the same config inside.

Not a big deal, I did it, but now I've got an error saying that Twig cannot find my template. I tried different syntaxes :

  • APYBreadcrumbTrailBundle::breadcrumbtrail.html.twig
  • APYBreadcrumbTrailBundle/breadcrumbtrail.html.twig
  • APYBreadcrumbTrail::breadcrumbtrail.html.twig
  • APYBreadcrumbTrail/breadcrumbtrail.html.twig
  • @APYBreadcrumbTrailBundle/breadcrumbtrail.html.twig
  • @APYBreadcrumbTrailBundle::breadcrumbtrail.html.twig
  • @APYBreadcrumbTrail::breadcrumbtrail.html.twig
  • @APYBreadcrumbTrail/breadcrumbtrail.html.twig

The last one actually works... but it use the default template, not mine.
Following the Symfony documentation, I've put my template in tempaltes/APYBreadcrumbTrailBundle/Resources/views/breadcrumbtrail.html.twig (https://symfony.com/doc/current/bundles/override.html#templates) but nothing ever works.

I'm using the following versions :

  • Symfony 5.3.6
  • APYBreadcrumbTrailBundle 1.6.1

Anyone can tell me what I am missing here ? The bundle documentation is still written for Symfony 2, so it's quite confusing.

Thanks a lot !

Run Rector upgrade script as Composer plugin

Given PHP 8.0 will be the minium PHP version for v2, running a Rector upgrade script will always upgrade the annotations to attributes.

This idea came up during the PHPWVL talk where Tomas Votruba held a talk about including effortless upgradeability as a Composer Plugin, and is a follow-up of the discussion in #72

TODO

  • find a way how to hook into the Rector process to transform the parameter labels
  • rewrite the old route array values to routeName, routeParameters, routeAbsolute
  • find a way to run a Rector rule when installing v2 (and how to only run it once)

Sample Rector rule

return static function (ContainerConfigurator $containerConfigurator): void {
    $services = $containerConfigurator->services();
    $services->set(AnnotationToAttributeRector::class)->call('configure', [
        [
            AnnotationToAttributeRector::ANNOTATION_TO_ATTRIBUTE => ValueObjectInliner::inline([
                new AnnotationToAttribute(\APY\BreadcrumbTrailBundle\Annotation\Breadcrumb::class),
            ]),
        ],
    ]);
};

Symfony 3.0 and Twig 2.0 compatibility

I'm getting some deprecation notices from the debug toolbar of Symfony framework:

DEPRECATED - Using an instance of "Twig_Function_Method" for function "apy_breadcrumb_trail_render" is deprecated. Use Twig_SimpleFunction instead.

Can you fix this please in order to make it future compatible?

Pass parameters to trans

Being able to dynamically pass parameters to the breadcrumbs because of the @ParamConverter is really awesome.

https://github.com/Abhoryo/APYBreadcrumbTrailBundle/blob/master/Resources/doc/annotation_configuration.md#routes-with-parameters

These parameters could come in really handy if they also should be passed to the Twig trans filter. That way we can use a translation key as the breadcrumb label, and use the parameters in the actual translation.

https://github.com/Abhoryo/APYBreadcrumbTrailBundle/blob/master/Resources/views/breadcrumbtrail.html.twig#L10-L12

Would also be nice to configure the translation domain via an option in the Twig renderer. So something like an OptionResolver and some extra default configuration parameters would be nice.

How to avoid translation of dynamic content

Hello,

I am trying to understand how to avoid the translation of strings from the database. Indeed we obtain "missing translations" in the profiler for each entity.

Do you have a solution ?

Two routes one action

Hello is there any way to specify different breadcrumb for each route, when there r multiple on one action?

Symfony 6.3 deprecation warnings

After updating to Symfony 6.3, we get the following deprecation warnings with version 1.9.2 of this package.

Method "Symfony\Component\DependencyInjection\Extension\ExtensionInterface::load()" might add "void" as a native return type declaration in the future. Do the same in implementation "APY\BreadcrumbTrailBundle\DependencyInjection\APYBreadcrumbTrailExtension" now to avoid errors or add an explicit @return annotation to suppress this message.
Method "Symfony\Component\Config\Definition\ConfigurationInterface::getConfigTreeBuilder()" might add "TreeBuilder" as a native return type declaration in the future. Do the same in implementation "APY\BreadcrumbTrailBundle\DependencyInjection\Configuration" now to avoid errors or add an explicit @return annotation to suppress this message.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.