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

Make twig-bridge optional #134

Merged
merged 2 commits into from
Oct 6, 2023
Merged

Make twig-bridge optional #134

merged 2 commits into from
Oct 6, 2023

Conversation

VincentLanglet
Copy link
Owner

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Oct 6, 2023

Codecov Report

Merging #134 (1278334) into main (58f6fca) will not change coverage.
Report is 2 commits behind head on main.
The diff coverage is 100.00%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

@@             Coverage Diff             @@
##                main      #134   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       458       463    +5     
===========================================
  Files             36        36           
  Lines           1331      1336    +5     
===========================================
+ Hits            1331      1336    +5     
Files Coverage Δ
src/Environment/StubbedEnvironment.php 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

"symfony/filesystem": "^5.4 || ^6.0",
"symfony/process": "^5.4 || ^6.0",
"symfony/twig-bridge": "^5.4 || ^6.0",
Copy link

@MauricioFauth MauricioFauth Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also add this to the suggest section of composer.json.

@VincentLanglet VincentLanglet marked this pull request as ready for review October 6, 2023 13:29
@VincentLanglet VincentLanglet merged commit 1632615 into main Oct 6, 2023
12 checks passed
@VincentLanglet VincentLanglet deleted the option-twig-bridge branch October 6, 2023 13:29
@dpi
Copy link

dpi commented Oct 11, 2023

Just leaving a note for searchers.

We began getting errors like, in the context of Drupal projects:

File is invalid: Unexpected "trans" tag (expecting closing tag for the "if" tag defined near line 66).
File is invalid: Unknown "trans" tag

Since the 1.4.0 release.

Adding symfony/twig-bridge back as a dev dependency seems to have resolved it.

@VincentLanglet
Copy link
Owner Author

Just leaving a note for searchers.

We began getting errors like, in the context of Drupal projects:

File is invalid: Unexpected "trans" tag (expecting closing tag for the "if" tag defined near line 66).
File is invalid: Unknown "trans" tag

Since the 1.4.0 release.

Adding symfony/twig-bridge back as a dev dependency seems to have resolved it.

That's kinda expected indeed.
Symfony/twig-bridge is not automatically installed anymore.

I wasn't expecting any BC break because if you're using the trans tag, you would already need the bridge to having your project working. Seems like it's not the case @dpi, how does your code work if you don't install symfony/twig-bridge ?
Is there something specific to drupal which understand the tag ?

@dpi
Copy link

dpi commented Oct 11, 2023

@VincentLanglet in the lock change that updated to 1.4.0, I could see this dep was removed. So nothing in Drupal or our deps relies on this. I don't know precisely what the cause is. But I imagine its because Symfony [Bridge?] implements a trans and Drupal does also with its own implementation. I guess if other frameworks have a trans tag they will also get this problem.

Looks like Drupal's is in https://github.com/drupal/drupal/blob/11.x/core/lib/Drupal/Core/Template/TwigExtension.php#L121

It doesnt seem trivial to just bring in this class into a .twig-cs-fixer.php, so I opted a quick fix to re-add this bulky dev dep. Do you have any suggestions about resolving .twig-cs-fixer.php + above TwigExtension class?

@VincentLanglet
Copy link
Owner Author

Drupal does also with its own implementation. I guess if other frameworks have a trans tag they will also get this problem.

Looks like Drupal's is in drupal/drupal@11.x/core/lib/Drupal/Core/Template/TwigExtension.php#L121

Thanks for the link.
The issue is more about the token parser, so https://github.com/drupal/drupal/blob/11.x/core/lib/Drupal/Core/Template/TwigTransTokenParser.php#L25

It doesnt seem trivial to just bring in this class into a .twig-cs-fixer.php, so I opted a quick fix to re-add this bulky dev dep. Do you have any suggestions about resolving .twig-cs-fixer.php + above TwigExtension class?

You could try to add directly the token parser like https://github.com/VincentLanglet/Twig-CS-Fixer?tab=readme-ov-file#token-parser
and write:

<?php

$config = new TwigCsFixer\Config\Config();
$config->addTokenParser(new Drupal\Core\Template\TwigTransTokenParser());

return $config;

@dpi
Copy link

dpi commented Oct 11, 2023

Great! that works. Thanks @VincentLanglet

@njt1982
Copy link

njt1982 commented Apr 24, 2024

In case anyone else comes to this... ddev tends to execute from the web/docroot folder, not the repo root.. so I needed to do this:

ddev exec twig-cs-fixer lint --config=../.twig-cs-fixer.php themes/custom

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

Successfully merging this pull request may close these issues.

5 participants