Closed (fixed)
Project:
Token
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
10 Jan 2016 at 04:46 UTC
Updated:
26 Jan 2016 at 11:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
hussainwebI tested this manually and it works. Let's see what the tests say.
Comment #4
hussainwebI found a related error which might be affecting the tests. Let's see if it fixes the tests.
Comment #6
hussainwebThis should fix the error.
Comment #7
berdirNot a fan of mixed argument types like that. It prevents us from using proper type hinting, for example. My only idea so far is a separate method, buildRenderableAllTypes or something, that contains the all logic.
This seems like an unrelated change
do we have all the options here covered from above?
This is now the last function in this file, which is great. Lets do a small follow-up and move it into .module
I'm not sure we fully understand each other about the render caching yet and I still think we need to move #token_types to be processed in the element type. But lets continue that discussion in the next issue/step.
Comment #8
hussainwebPlease let me know your thoughts on 1 and 2.
Comment #9
hussainwebFor 1, another idea is to pass this as a flag in $options. I don't like it very much (if it is set, the first parameter is ignored, which would not be intuitive) but I thought I should list it for completeness.
Comment #10
berdir1. The problem is that we can't change the API later, we have to design it now in a way that works. This is our one and only chance to do it :) Empty array doesn't work, that means "only global types". Separate method should be easy enough? You just explicitly load and forward all types to the other method?
2. Hm. It doesn't really matter that much now that I already reviewed it, so lets keep it. Stuff like this makes reviewing a patch slightly harder because I had to figure out what/if something changed :)
Comment #11
hussainwebAgree and agree. I will work on getting a new method. I just wanted to keep refactoring separate from moving stuff (so that there is a trace in commits where things changed). I fully intended to handle the refactor in a quick follow-up, maybe pre-alpha-2.
And I totally accept your comments on these changes making it harder to review. It's just that when I scroll through the module, there are a lot of _small_ things I want to improve or streamline but it feels an overkill to keep creating an issue. So, when I touch a line of code, I will try to improve it whatever I can.
Working on a patch...
Comment #12
hussainwebHere is the patch.
Comment #14
hussainwebI only realized it would fail after I submitted. :)
Comment #15
berdirha, so we still have the option here :)
Since we're moving around this code anyway, maybe clean this up a bit? You have two checks now, first you conditionally set $token_types and then you have an if/else on that. I think you can just use $options['token_types'] in the if check?
Comment #16
hussainwebDoh! Funnily, I made a similar mistake with unset just now. It's good I caught it before posting the patch. :)
And on that note, I removed unset. The method doesn't use $options['token_types']. It might be leftover from earlier changes.
Comment #17
berdirCan you add a comment why we disable global types (because we already explicitly add them, but that might not be obvious from the code)
Other than that, looks good to me. While not perfect, I think the separate method like this is cleaner. Agreed?
(sorry for the multiple posts), this was a crosspost with your previous patch and I only noticed just now. You're too fast :)
Comment #19
hussainweb:)
I think it is cleaner than before but the way the methods call each other is less than ideal. It is definite a step in the right direction though.
What do you think of this comment?
Comment #20
hussainwebI have identified the fix for failure. Just waiting for your approval on comment and I will submit the patch.
Comment #21
berdirComment is perfect :)
Comment #22
hussainwebThanks! Here is the patch. :)
Comment #23
berdirSorry found something else :)
hm. now that I see this, I don't think we can change this. As I said above, this means that it's no longer possible to have the token tree with *only* the global tokens. If this isn't failing any tests, we should add test coverage for that, should be easy enough now :) possibly just an assertNoText() for a token that shouldn't be there.
So, you can't do empty() check, at least here, we need to keep the all special case.
Comment #24
hussainwebI think it is getting a little confusing. I added a comment on the controller which hopefully explains this.
Comment #25
hussainwebSince the patch in #22 should have failed with the new test, I am attaching a patch with changes in #22 with the test added in #24. This should fail.
Comment #28
hussainwebOkay, the test in #25 cannot be applied without the fixes. The failure in #24 is something else, though. I somehow assumed that array would be a global token type. Changing that.
Comment #29
juampynr commentedAre this and the next bit part of the @TODO item?
Comment #30
hussainwebYes, I left it from the original code in the theme hook. Caching is right after this and I thought it would be useful to let it be.
Comment #32
berdirYes, the caching it like that is fine for now, makes sense to keep it. Looks good now to me, yay for more test coverage.
Comment #33
dawehnerWould be nice to have some sort of change record about that.
Comment #34
berdirGood point. I think we can do a single change record on all the related changes here:
1) That #dialog = TRUE ( which we already removed in previous issues) now must use the separate theme template token_tree_link and is in fact the recommended way of embedding a token tree.
2) That this theme function was removed in favor of the buildRenderable()
3) And that tree_table was converted to a #type.
There are still 1-2 changes outstanding until we're done here (caching and what that will require) but in 90+% of the cases, modules should use token_tree_link anyway and we should highlight that.
Comment #35
hussainwebStarted a rough CR at https://www.drupal.org/node/2648394.
Comment #36
dawehner@hussainweb++
Comment #37
hussainwebCreated #2648608: Implement (render) caching for token tree to discuss caching.
Comment #38
juampynr commentedI added an example to the change record. @hussainweb, please verify that it makes sense: #2648394: Theme functions have been replaced with template preprocess, render elements, or service methods.
Comment #39
berdirI simplified the example a bit, there's no need to add all the optional attributes and also used an explicit token type. Published.