-
Notifications
You must be signed in to change notification settings - Fork 45
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
Initialize props pattern #2 #1089
Conversation
…es _context and returns array of allowed props
This is looking good @danielamorse! I just pushed several commits that mostly rework syntax and some of the logic as well (nothing too drastic). Normally I wouldn't presume to impose my preferred syntax on someone else, but since you're still finding your way around PHP, I just went ahead and did it. I've still got some thinking and rewriting to do, but in the meantime, a few thoughts/questions:
I'll probably keep noodling on this tomorrow, but again, good stuff so far! |
@remydenton, nice edits to the PHP. It was helpful for me to review and see the improvements to syntax and readability.
I was inspired by this example from the docs and liked the idea of passing a short name instead of the full constant, especially if you were calling a converter function, e.g.
That is a very good point. I was assuming it was always an array before we called
As you probably saw currently I'm filtering those props out manually. Yes, it would be better to solve this as a higher-level. My concern with using
Good point. I think the subsequent check would weed it out, but would want to test to be sure. Side note: the other important thing here is that each schema-approved prop is added to the array after Thanks for putting in the time to clean this up. Let me know if/when you want some help. |
Since attributes type should be an array or object, it will not never make it through the type checks below, so the lines this commit removes are redundant.
Phew, okay, I think I've done all I have time for for now. Most significantly, I addressed the attributes coming in as an object issue. You can test by adding this at the top of
Before my last commit, that would throw errors about syntax (because the other logic in the twig file assumed this.data was an array when it wasn't). Now, it's always an attributes object and that's the presumption throughout the file. That unfortunately means a slightly more verbose syntax (e.g. Additionally:
|
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.
Can you please update with the latest code from master + make sure the Travis build is passing?
This is looking a lot better — I really like how the PHP for this is shaping up!!
I think that should just about do it for me. We need to update the branch to pull in the latest from master, resolve conflicts, and tweak one or two things based on my comments then I think this is good to approve and merge! 👍🏼 |
@sghoweri I updated with the latest from master and incorporated the changes you suggested. Just one remains, the one about optional dependencies. See comment. Thanks! |
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 looks great. Very nice work @danielamorse -- lets gettr merged!
Jira
Summary
I took another pass at the component
props
pattern with feedback from the team.Note: original PR #1041 was merged and reverted. This is a replacement PR.
Details
I added a new Twig function
initialize(_context, schema)
and a new utility functionbuildPropsArray()
.initialize()
returns an array with two keys:["props"]
: a Drupal Attributes object used for rendering props with keys formatted in kebab-case (includes "attributes").["data"]
: an array of props that includes default values from the schema with keys formatted in snake_case.The data returned only loops through the schema one-level deep, so props that are multi-level (like
author.title
) are skipped. Going forward, we want to flatten our component schemas, and so this decision keeps that pattern in mind.Next steps
How to test