Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug in getTemplating_Helper_AssetsService() Symfony 2.7-Beta 1 #14368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
apfz opened this issue Apr 16, 2015 · 14 comments
Closed

Bug in getTemplating_Helper_AssetsService() Symfony 2.7-Beta 1 #14368

apfz opened this issue Apr 16, 2015 · 14 comments

Comments

@apfz
Copy link

apfz commented Apr 16, 2015

This was triggered by having {{ tinymce_init() }} in a javascript block.

An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Argument 1 passed to Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper::__construct() must be an instance of Symfony\Component\Asset\Packages, string given, called in /my/directory/app/cache/dev/appDevDebugProjectContainer.php on line 5370 and defined"

@dosten
Copy link
Contributor

dosten commented Apr 16, 2015

Can you paste the generated getTemplating_Helper_AssetsService() method in app/cache/dev/appDevDebugProjectContainer.php ?

@apfz
Copy link
Author

apfz commented Apr 16, 2015

sorry I forgot. Here it is!


/**
 * Gets the 'templating.helper.assets' service.
 *
 * This service is shared.
 * This method always returns the same instance of the service.
 *
 * @return \Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper A Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper instance.
 */
 protected function getTemplating_Helper_AssetsService()
 {
     return $this->services['templating.helper.assets'] = new \Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper('', array());
 }

The first parameter for AssetHelper is an empty string, where as we look at the constructor of AssetHelper, it actually expects an Asset\Packages object.


namespace Symfony\Bundle\FrameworkBundle\Templating\Helper;
use Symfony\Component\Asset\Packages;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
use Symfony\Component\Templating\Helper\Helper;
/**
 * AssetsHelper helps manage asset URLs.
 *
 * @author Fabien Potencier 
 */
class AssetsHelper extends Helper
{
    private $packages;
    public function __construct(Packages $packages)
    {
        $this->packages = $packages;
    }

@taemtha
Copy link

taemtha commented Apr 20, 2015

I got the same error here.
This happen if i calling an twig extension which need the 'templating.helper.assets' service.

An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Argument 1 passed to Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper::__construct() must be an instance of Symfony\Component\Asset\Packages, string given, called in /var/www/app/cache/dev/DevDebugProjectContainer.php on line 5428 and defined") in myapp/src/App/Resources/views/app.config.html.twig at line 9.

Generated code in the devcontainer:

    /**
     * Gets the 'templating.helper.assets' service.
     *
     * This service is shared.
     * This method always returns the same instance of the service.
     *
     * @return \Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper A Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper instance.
     */
    protected function getTemplating_Helper_AssetsService()
    {
        return $this->services['templating.helper.assets'] = new \Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper('', array());
    }

@taemtha
Copy link

taemtha commented Apr 20, 2015

The faulty service is configured here:
./symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml

       <parameter key="templating.helper.assets.class">Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper</parameter>


        <!--
            This service will be moved to templating_php.xml in version 3.0, it exists here for BC reasons.
        -->
        <service id="templating.helper.assets" class="%templating.helper.assets.class%">
            <tag name="templating.helper" alias="assets" />
            <argument /> <!-- default package -->
            <argument type="collection" /> <!-- named packages -->
        </service>

but the class:
./symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/AssetsHelper.php

has only the new construcor with the only parameter " Package $package"

    public function __construct(Packages $packages)
    {
        $this->packages = $packages;
    }

@dosten
Copy link
Contributor

dosten commented Apr 20, 2015

@taemtha I don't find any code that replace the first argument with a default package, if you delete the <argument /> <!-- default package --> line, works?

@jakzal
Copy link
Contributor

jakzal commented Apr 20, 2015

The first argument is replaced by FrameworkExtension.

@dosten
Copy link
Contributor

dosten commented Apr 20, 2015

@jakzal that code replaces the default package and the packages into the assets.packages definition, AssetsHelper needs as first argument an instance of Packages, so this defintion is wrong, right?

<service id="templating.helper.assets" class="%templating.helper.assets.class%">
     <tag name="templating.helper" alias="assets" />
     <argument /> <!-- default package -->
     <argument type="collection" /> <!-- named packages -->
</service>

must be

<service id="templating.helper.assets" class="%templating.helper.assets.class%">
     <tag name="templating.helper" alias="assets" />
     <argument type="service" id="assets.packages" />
</service>

correct me if i'm wrong

@dosten
Copy link
Contributor

dosten commented Apr 20, 2015

The tests of AssetsHelper seems fine, but the definition seems wrong.

@xabbuh
Copy link
Member

xabbuh commented Apr 20, 2015

@apfz @taemtha Can you please check if the changes from #14419 solve your issue?

@markitosgv
Copy link
Contributor

Same bug error with IvoryCKEditorBundle library

@xabbuh
Copy link
Member

xabbuh commented Apr 20, 2015

@markitosgv Can you please also check if #14419 goddess this for you?

@markitosgv
Copy link
Contributor

@xabbuh test ok! solve IvoryCKEditorBundle problem too

fabpot added a commit that referenced this issue Apr 21, 2015
This PR was merged into the 2.7 branch.

Discussion
----------

inject asset packages in assets helper service

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14368
| License       | MIT
| Doc PR        |

Commits
-------

6928507 inject asset packages in assets helper service
@fabpot fabpot closed this as completed Apr 21, 2015
@taemtha
Copy link

taemtha commented Apr 21, 2015

@xabbuh The changes from #14419 solves my issue! Thanks!

@apfz
Copy link
Author

apfz commented May 8, 2015

Yes this fixed it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants