Comments

hussainweb created an issue. See original summary.

hussainweb’s picture

Status: Active » Needs review
StatusFileSize
new11.11 KB

I tested this manually and it works. Let's see what the tests say.

Status: Needs review » Needs work

The last submitted patch, 2: remove_token_tree_theme-2647532-2.patch, failed testing.

hussainweb’s picture

Status: Needs work » Needs review
StatusFileSize
new1.02 KB
new11.44 KB

I found a related error which might be affecting the tests. Let's see if it fixes the tests.

Status: Needs review » Needs work

The last submitted patch, 4: remove_token_tree_theme-2647532-4.patch, failed testing.

hussainweb’s picture

Status: Needs work » Needs review
StatusFileSize
new558 bytes
new11.44 KB

This should fix the error.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/src/TreeBuilderInterface.php
    @@ -44,4 +44,27 @@ interface TreeBuilderInterface {
    +   * @param string|array $token_types
    +   *   An array containing token types that should be shown in the tree, or
    +   *   'all' if all token types should be shown.
    

    Not 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.

  2. +++ b/token.module
    @@ -22,17 +22,14 @@ use Drupal\Core\Url;
    -    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    -    $renderer = \Drupal::service('renderer');
    -    $output .= '<dd>' . $renderer->render($token_tree) . '</dd>';
    +    $output .= '<dd>' . \Drupal::service('renderer')->render($token_tree) . '</dd>';
    

    This seems like an unrelated change

  3. +++ b/token.module
    @@ -69,7 +55,7 @@ function token_theme() {
    -    ] + $info['token_tree']['variables'],
    +    ],
    

    do we have all the options here covered from above?

  4. +++ b/token.pages.inc
    +++ b/token.pages.inc
    @@ -23,13 +23,19 @@ function template_preprocess_token_tree_link(&$variables) {
    

    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.

hussainweb’s picture

  1. I agree and I wanted to change it too, but I thought we should keep initial logic while refactoring like we did earlier. If we want to do it now, I was thinking that passing in an empty array would be equivalent of passing 'all'. I don't mind your idea of a separate method either but it would need a good amount of refactoring to keep the code clean.
  2. Yes, I thought we could make this cleaner while we're at it. If you want, I will revert it.
  3. Yes, I checked each option.
  4. Sure, okay. :)

Please let me know your thoughts on 1 and 2.

hussainweb’s picture

For 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.

berdir’s picture

1. 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 :)

hussainweb’s picture

Agree 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...

hussainweb’s picture

Status: Needs work » Needs review
StatusFileSize
new3.06 KB
new12.05 KB

Here is the patch.

Status: Needs review » Needs work

The last submitted patch, 12: remove_token_tree_theme-2647532-12.patch, failed testing.

hussainweb’s picture

Status: Needs work » Needs review
StatusFileSize
new1.28 KB
new12.17 KB

I only realized it would fail after I submitted. :)

berdir’s picture

+++ b/src/Controller/TokenTreeController.php
@@ -44,7 +44,12 @@ class TokenTreeController extends ControllerBase {
     $token_types = !empty($options['token_types']) ? $options['token_types'] : 'all';
...
-    $build = $this->treeBuilder->buildRenderable($token_types, $options);
+    if ($token_types == 'all') {
+      $build = $this->treeBuilder->buildAllRenderable($options);
+    }
+    else {
+      $build = $this->treeBuilder->buildRenderable($token_types, $options);
+    }

ha, 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?

hussainweb’s picture

StatusFileSize
new1014 bytes
new12.06 KB

Doh! 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.

berdir’s picture

+++ b/src/TreeBuilder.php
@@ -111,6 +108,16 @@ class TreeBuilder implements TreeBuilderInterface {
+    $options['global_types'] = FALSE;
+    return $this->buildRenderable($token_types, $options);

Can 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 :)

Status: Needs review » Needs work

The last submitted patch, 16: remove_token_tree_theme-2647532-16.patch, failed testing.

hussainweb’s picture

:)

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?

    // Disable merging in global types as we will be adding in all token types
    // explicitly. There is no difference in leaving this set to TRUE except for
    // an additional method call which is unnecessary.
hussainweb’s picture

I have identified the fix for failure. Just waiting for your approval on comment and I will submit the patch.

berdir’s picture

Comment is perfect :)

hussainweb’s picture

Status: Needs work » Needs review
StatusFileSize
new1.2 KB
new12.8 KB

Thanks! Here is the patch. :)

berdir’s picture

Status: Needs review » Needs work

Sorry found something else :)

+++ b/src/Tests/Tree/TreeTest.php
@@ -42,7 +42,7 @@ class TreeTest extends TokenTestBase {
   public function testAllTokens() {
-    $this->drupalGet($this->getTokenTreeUrl(['token_types' => 'all']));
+    $this->drupalGet($this->getTokenTreeUrl());
 

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.

hussainweb’s picture

Status: Needs work » Needs review
StatusFileSize
new2.75 KB
new13.78 KB

I think it is getting a little confusing. I added a comment on the controller which hopefully explains this.

    // The option token_types may only be an array OR 'all'. If it is not set,
    // we assume that only global token types are requested.
hussainweb’s picture

Since 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.

The last submitted patch, 24: remove_token_tree_theme-2647532-24.patch, failed testing.

Status: Needs review » Needs work
hussainweb’s picture

Status: Needs work » Needs review
StatusFileSize
new454 bytes
new13.74 KB

Okay, 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.

juampynr’s picture

+++ b/src/TreeBuilder.php
@@ -51,6 +51,77 @@ class TreeBuilder implements TreeBuilderInterface {
+      /*'#cache' => array(

Are this and the next bit part of the @TODO item?

hussainweb’s picture

Yes, 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.

  • Berdir committed f66bf0d on 8.x-1.x authored by hussainweb
    Issue #2647532 by hussainweb: Remove token_tree theme hook
    
berdir’s picture

Status: Needs review » Fixed

Yes, the caching it like that is fine for now, makes sense to keep it. Looks good now to me, yay for more test coverage.

dawehner’s picture

Would be nice to have some sort of change record about that.

berdir’s picture

Good 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.

hussainweb’s picture

dawehner’s picture

@hussainweb++

hussainweb’s picture

juampynr’s picture

I 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.

berdir’s picture

I simplified the example a bit, there's no need to add all the optional attributes and also used an explicit token type. Published.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.