-
-
Notifications
You must be signed in to change notification settings - Fork 90
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 array values for meta tags #600
Conversation
Co-authored-by: Christian Gripp <[email protected]>
$this->normalize($name), | ||
$this->normalize($content) | ||
); | ||
if (\is_array($content)) { |
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.
This method has a large code complexity and is hard to understand. Can you try to extra a few methods.
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.
I can pass an $extra variable to generateMetaTag() method as a new property, then the foreach would not be duplicated. The structured properties (additional tags) would be generated from the inside as a recursive function.
Or should I simply introduce a new generateMetaTagExtra() method and call it?
Wouldnt it better to say that the add method always has the same behavior to support array values for every possible tags ? And if needed we can introduce later a reset/replace/set/... method. |
I am not sure if all possible metatag allows multiple values. I guess not all of them do. |
Even if they dont, it would be better if you dont need to know if they do when you use the add method to determine the behavior you'll get. Two different methods might be better |
@VincentLanglet In my PR I introduced a constant ( @core23 I understand the problem with the code complexity - and it's mainly because of the two options how we store the metadata. Most of the time it will be a string as it was before though - not much was added there. The real new feature is rendering structured data through the $extra variable - it can generate additional meta tags under the root node. |
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.
TLDR: This feature might seems easy but could introduce multiple inconsistency issues and BC-break to me. Might be simplier to think about a plan, add deprecation in this branch and finish it in next major. Good news the next major will be released soon.
Looking at the method:
setMetas
is resetting the metas and then calling addMeta with every value.addMeta
is supposed to add a value, without replacing the previous one when the value is in this special array of "multiple values allowed". When it's not it will replace the value.- a
setMeta
method could be introduce to reset and set a new value but it's basicallyremoveMeta
+addMeta
.
The new strategy could add some issues:
- First adding/removing a key to this new constant is a BC-break ; because we're changing the behavior of the addMeta method.
- The addMeta won't have a consistent behavior depends of the tag used.
- The addMeta won't have a consistent behavior with all add method like
addHtmlAttributes
,addHeadAttribute
(you can also notice the lack of consistency with thes
). - Also, you're checking the name but your usage is only in the case of a type
property
- Since you're changing the structure of the metas, the call
setMetas(getMetas())
is not possible anymore.foreach ($metaItem as $name => $meta) {
can give us array of array.
I don't like the add
name to set a value. Renaming
addHtmlAttributes
to setHtmlAttribute
, etc, would make sens.
then removeHtmlAttributes
to unsetHtmlAttribute
, etc, would make sens too.
The addMeta
would be deprecated to a setMeta
method which ALWAYS override the value.
And a new addMeta
could be introduce and ALWAYS add the value to the existing array.
Also, it would be simplier to say that a meta is ALWAYS an array of array to avoid always checking if it's a string or an array and just doing a foreach on it.
This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Subject
og:image
Renders as:
:
Renders as:
I am targeting this branch, because it's a missing feature and it should be available in 2.x too.
Closes #554
Changelog