Skip to content
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

Allow getCssFiles/getJsFiles in EntrypointLookup return files without filtering already returned #87

Open
davidrojo opened this issue Feb 20, 2020 · 3 comments

Comments

@davidrojo
Copy link

Hello,

I am trying to get the css files of an entry to then pass them to a javascript that builds an iframe and adds in the iframe the css files.

I am adding EntrypointLookupInterface as a dependency and call getCssFiles of an entry that I have declared in webpack.config.js. The problem is that the function getCssFiles calls getEntryFiles that filters already returned files, resulting that some common files are not added then in my website when I call in twig {{ encore_entry_link_tags }}.

Looking at the code I cannot see any way to get the files avoiding this filtering.

There could be another function to retrieve entries without filtering, or add a parameter to getCssFiles and getJsFiles to skip filtering.

@davidrojo
Copy link
Author

Currently as a workaround to get access to the entries I did this:

use ReflectionClass;
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface;

class Test {

    public function __construct(EntrypointLookupInterface $entrypointLookup){
        $this->entrypointLookup = $entrypointLookup;
    }

    public function getCssFilesForWebpackEntry($entry){
        $reflect = new ReflectionClass($this->entrypointLookup);
        $method = $reflect->getMethod('getEntriesData');
        $method->setAccessible(true);
        $result = $method->invoke($this->entrypointLookup);
        $css = [];
        foreach($result['entrypoints'][$entry]['css'] as $file){
            $css[] = $file;
        }
        return $css;
    }
}

@weaverryan
Copy link
Member

See #90 - we do need to make this possible. What about an argument to encore_entry_link_tags()? Hmm, or (because that already has several optional arguments), we might need a new function... :/ - like encore_entry_link_tags_all(). I'm not sure...

@davidrojo
Copy link
Author

Hi, @weaverryan I think that a new function should be better for better understanding, documentation and maintenance.

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

No branches or pull requests

2 participants