Needs work
Project:
Rules
Version:
8.x-3.x-dev
Component:
Rules Core
Priority:
Major
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
6 Jun 2014 at 09:57 UTC
Updated:
5 Mar 2016 at 17:17 UTC
Jump to comment: Most recent
Comments
Comment #1
jesse.d commentedComment #2
jesse.d commentedComment #3
Anonymous (not verified) commentedAssigning to me as this is a requirement for #2317193: Port "Add an item to a list" action to D8 which I am working on.
Comment #4
Anonymous (not verified) commentedCode for this is now up at https://github.com/fago/rules/pull/99
Comment #5
fagoThanks, merged!
Comment #8
fagoLet's address the @todo for adding the missing info-alter as #2456829: Context definition needs to be updated before execution is done - see EntityFetchByField as example.
Comment #9
dasjoComment #10
Anonymous (not verified) commentedI was working on this on the TGV. Doing the "run tests & see if I can figure out the error messages enough" route - started learning about typed data by reading the code & interfaces as couldn't tether on the train. Got as far as getting this error - I think I'll figure it out once I understand typed data but understand if you need to move it forward - I've only one example to go from at the mo (the one which fago mentioned) but understanding more minute by minute ;) Would like to continue but understand if you need to move it ahead though, I'll read the solution with interest.
This is what I've put in
DataListContains:...and this in
ListContainsTest(which I'm guessing should be renamed DataListContainsTest?):I know the code doesn't make much logic at the moment because I'm half way between copy & paste and "oh... d'oh" moments.
Thanks for an awesome week, have set some time aside this week to look into the derivatives to see if I can understand then document that too.
Trying to keep momentum going this time!
Comment #11
Anonymous (not verified) commentedOK, current question I have at the moment because I've been reading about typed data api over at #1794140: Typed Data API overview:
- the example in
EntityFetchByFieldenables refining of theprovides = {"entity_fetched"whereas there is noprovidesinDataListContains, it just returns the resultant value ofin_array($item, $list). Does this mean it shouldn't just return a value but set a provided context so we can then add the refine context?Comment #12
Anonymous (not verified) commented...but that doesn't make much sense, because why would you want to change a boolean result? Was trying to loop through the list earlier but didn't really 'get' why you would want to change the type of each list item but perhaps you would.
Comment #13
Anonymous (not verified) commentedOh, hang on, item is a list too, isn't it - d'oh.
And you probably would want to change the type of a list item - d'oh.
Maybe, just thinking out loud as you said update... I generally don't as you can see the threads get long and often embarrassing for me ;)
Comment #14
Anonymous (not verified) commentedAnother day and it's like a new brain. Reading the example again I see it's seeing if there's a type sent through in the context, and if so then sets the type of the entity provided. That's because that's what that rules action does - this rules condition takes a list and an item and returns whether or not the item is in the list. The contexts of any of these could be refined, so the code needs to get the info using the Typed Data API. The doc on that is sparse but links to the more thorough Entity API docs at https://www.drupal.org/node/1795854 which I'm going through.
So I may laugh at this in time to come, but lists are complex structures so presumably I'll need to step through the list with the refine context function, and once on the item (which isn't a list as I said above, but I could still change my mind...)
Comment #15
Anonymous (not verified) commentedOK so I can see I can use
getProvidedContextDefinition('item')->getDataType();to get the type of the item, but now confused as to what I would then set - the example is clearer as type is an actual context. Now less sure I'll need to do anything to the list.Guess I should hop on IRC at some point, I'll RTFM more first - must say I'm impressed with the quality of the Drupal 8 Entity API documentation there is in the code, makes it a pleasure to read, thanks!
Comment #16
Anonymous (not verified) commentedOK this is what I have so far for
item, working onlist:Comment #17
klausiI'm not exactly sure what we want to do here - do we want to refine the "item" context or the "list" context or both? Does a list always contain items of the same type? If not, then we cannot refine the list type.
Assigning to fago so he can take a look what we should do here exactly.
Comment #18
Anonymous (not verified) commentedThat's one of the questions I mentioned in my ramblings above, good to see I wasn't too far off in my thinking.
Enjoyed my little trip around the entity api, it's slowly making more sense!
Comment #19
fagoThe answer is simle: the same as in d7. Look at the d7 info alter and follow it.
>Does a list always contain items of the same type?
yes.
We need to refine the item afair, but check d7.
Comment #20
fagoComment #21
Anonymous (not verified) commentedGood point, well made. I'll RTF7M ;)
Comment #22
Anonymous (not verified) commentedThe code in 7 uses the same info alter for add and remove actions, posting here whilst I get lost in setting & getting context definitions!
Comment #23
Anonymous (not verified) commentedSo here's where my thinking's at currently:
- from what I can tell, 7 allows you to alter the type of a list item. It uses the same alter hook for many similar functions such as add item to list, list contains, etc. With my limited knowledge of form api I can't tell whether it allows for the type of the item being added to the list (or whatever the function is) to be altered or not, but my hunch is it doesn't. Should it? That's another question - if alter hooks are there for enabling the complete control over types at runtime then yes, it should.
- in 8 we should allow for refining configs on all available places, i.e. type of item and type of each item in list. I don't currently know how to achieve this in code, hence why posting update here before I spend days figuring out something which is wrong ;) It does beg the question though that surely if all this alter 'hook' is allowing for is changing of type then it could be extracted to a level higher up as 'type' should be discoverable?
Still reading up on various discussions around this so no doubt more will become clear as has done in the past week!
Comment #24
Anonymous (not verified) commentedHave updated the PR with (working) code and comments (with questions) https://github.com/fago/rules/pull/184#issuecomment-104692862
Comment #25
Anonymous (not verified) commentedHi - so I've been following progress today and saw the resultant issue https://www.drupal.org/node/2501939
Could you please have a look at this again and let me know what, if anything I can do on this? Am not really understanding the whole refining context story.
Have been stuck on this for ages, happy to look into other issues, feel free to point me to something!
Comment #26
dasjoHi steve,
I will wait for fago or klausi to comment on this.
If you are generally looking for stuff, you should be able to pick anything from
https://www.drupal.org/node/2245015#contributing
Feel free to reach out on irc if I can be of any assistance
Best,
dasjo
Comment #27
Anonymous (not verified) commentedCool thanks - also met @matslats who created and maintains mutual credit suite of modules last week at a workshop on money here in Brightoncisco - certainly an interesting area! I mentioned I'd been helping on rules and he's got a D8 version in development needing help with rules so will also apply some knowledge and time there - it's good to see things in action, helps my understanding of things. Drupal dev is a little abstract ;)
Comment #28
klausiLeft a comment at the PR, please try to fix that.
Comment #29
Anonymous (not verified) commentedSee my comments on https://github.com/fago/rules/pull/184#discussion_r33425007 - I added the code but it doesn't pass my tests checking whether it refines the context or not.
Comment #30
Anonymous (not verified) commentedStill working out what I need to mock for the tests to work - not sure what I'd ask if I was on IRC so reading up more on mocking
Comment #31
Anonymous (not verified) commentedHaving discussed this with dasjo, fago, and klausi I am postponing this until the issue about runtime context setting is figured out.
Comment #32
fagoThat's solved now, see #2281079: Port "Data comparison (data_is)" condition to 8.x for an example.