I think this is a token issue and not a meta tag issue, let me know if that's wrong.

GOAL: insert url tokens using the token browser.

ISSUE:
In the meta tag Edit page there's an optional "Browse available tokens" modal window. It then lists out the token tree. However, the url tokens listed don't work as expected. The options available formatted like `[url:absolute]`, however the actual token is `[current-page:url:absolute]`.

Comments

icicleking created an issue. See original summary.

hussainweb’s picture

Issue summary: View changes

URL is a type of token and hence it shows up over there (similar to Array, date, random, etc). I haven't seen metatag code but it probably needs to set 'show_nested' to FALSE to not show these token types.

berdir’s picture

url needs a url, so I think metatag (incorrectly) defines that it has a url, that's why it shows up.

berdir’s picture

Project: Token » Metatag
damienmckenna’s picture

@icicleking: Please explain where you saw that popup? The module passes different arguments to the token browser depending upon where it's called for.

damienmckenna’s picture

Here's what Metatag is doing to generate the token browser link:

    $form['tokens'] = [
      '#theme' => 'token_tree_link',
      '#token_types' => !empty($token_types) ? $token_types : 'all',
      '#global_types' => TRUE,
      '#click_insert' => TRUE,
      '#show_restricted' => FALSE,
      '#recursion_limit' => 3,
      '#text' => t('Browse available tokens'),
    ];

a) What should it be? b) Is there a difference between the options available to the last release of the Token module and what's currently in -dev? c) When will the next release of Token be?

damienmckenna’s picture

Oh hey, I just saw that Token 8.x-1.0-beta1 is out - awesome work Berdir (and everyone)!

damienmckenna’s picture

Status: Active » Needs review
StatusFileSize
new1.23 KB

Is this the correct way of doing it?

berdir’s picture

Status: Needs review » Needs work
+++ b/src/MetatagToken.php
@@ -72,9 +72,10 @@ public function tokenBrowser($token_types = NULL) {
       '#theme' => 'token_tree_link',
-      '#token_types' => !empty($token_types) ? $token_types : 'all',
+      '#token_types' => !empty($token_types) ? $token_types : NULL,
       '#global_types' => TRUE,
       '#click_insert' => TRUE,
+      '#show_nested' => FALSE,
       '#show_restricted' => FALSE,
       '#recursion_limit' => 3,

The default empty value is an empty array, not NULL. I'd just change the default value of your method to [], then you can remove the condition and just pass along $token_types.

Also, you specify a lot of default options. There isn't really a need to have them. It doesn't hurt, but when I look at that, I assume you override the default, which is not the case.

The only thing you need is #theme and #token_types.

The first part in the patch looks unrelated?

damienmckenna’s picture

@berdir: Thanks for the feedback.

The first part of the patch fixes a problem where it wasn't passing in the correct entity type to the browser for the global configurations, basically the existing code didn't work correctly.

I'll try a new patch with fewer options and see how it works.

damienmckenna’s picture

Status: Needs work » Needs review
StatusFileSize
new1.57 KB

This appears to still work correctly, what do you think?

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Looks ok to me. you might need to update the @param docs for the argument, in case that mentioned null somehow.

damienmckenna’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new2.54 KB
new3.31 KB

Some minor improvements, mostly focused on the $token_types argument handling.

  • DamienMcKenna committed 27d03ab on 8.x-1.x
    Issue #2774807 by DamienMcKenna, Berdir, hussainweb: Token browser...
damienmckenna’s picture

Status: Needs review » Fixed

Committed. Thanks for your help!

Status: Fixed » Closed (fixed)

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