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

fix: pass any attribute value type to markup #31

Merged
merged 3 commits into from
May 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/AddAttributesTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ public function add_attributes($context, $additional_attributes = []) {
if ($value instanceof Attribute) {
$value = $value->toArray()[$key];
}
elseif (is_string($value)) {
$value = [$value];
}
else {
continue;
$value = [$value];
Copy link
Collaborator

Choose a reason for hiding this comment

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

@callinmullaney I am thinking this is a little too open, it seems like your use case (original question) is to support integers. Should we not have another case to handle integers (convert them to a string)?

Currently this is what I am seeing we are processing:

  1. Arrays (flat) - technically nested arrays would just not work
  2. (object) Attribute
  3. Strings
  4. Default - Do nothing

I think this would read easier if we were using a switch statement here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ccjjmartin I updated this PR to use a switch statement like you suggested. The original scope of this issue was to handle passing integers type values but with the changes I made we can also handle boolean.

That being said, while nested arrays and objects would also be a nice thing to process if passed to add_atributes() I think it's a bit out of scope for the original issue. The switch statement framework established here would be a good jumping off point for another branch to add support.

Can you take a quick look at this and confirm the testing criteria above?

}
}
// Merge additional attribute values with existing ones.
Expand Down