-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Added twig extension for preg_match and preg_split #2788
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
thexmanxyz
wants to merge
1
commit into
getgrav:develop
from
thexmanxyz:feature/twig_preg_match_split
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot we just call the method directly:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mahagr The
preg_matchcode is taken directly from Gantry 5 in the form it is currently in this PR (withoutoffsetandflagsparameter). TBH IDK if incompatibilities might occur if we have different method signatures. Same for the thepreg_splitbut only with theflagsparameter omitted. I decided to also omit theflagsparameter as it was skipped forpreg_matchwithin Gantry5 as well.Additionally
preg_matchin Gantry 5 does not act the same way for return values as the default PHP method. Hence we can only update this PR forpreg_splitto something like this:otherwise we might break existing code that relies on the Twig
preg_matchfunction. Let me know and I will push a commit with the updated code forpreg_split.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mahagr you probably know best about the code in G5, but it seems that
falsereturn value is there for a reason in G5.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right. The
preg_match()PHP method returns true/false by default and puts the matching strings into the third parameter. It looks like @newkind added this method back in 2015, so I guess it's being used in a few themes.If this was a filter, I would agree on the returned value, but in the function, not sure. I guess that you cannot update values inside parameters in twig, so it would make sense to remove the third parameter altogether -- it's being returned anyway.