The Google Map formatter needs to clear the tokens if the field/source is empty and a replacement can't be found.

/Plugin/FIeld/FieldFormatter/GeolocationGoogleMapFormatter.php
Line 212:

- $content = \Drupal::token()->replace($settings['info_text'], $token_context, ['callback' => [$this, 'geolocationItemTokens']]);
+  $content = \Drupal::token()->replace($settings['info_text'], $token_context, ['callback' => [$this, 'geolocationItemTokens'], 'clear' => TRUE]);

API: Token::replace

Also the returned token replacements need to passed to the theme layer as a render array otherwise the output will display markup as a string,

/Plugin/FIeld/FieldFormatter/GeolocationGoogleMapFormatter.php
Line 214:

$content = \Drupal::token()->replace($settings['info_text'], $token_context, ['callback' => [$this, 'geolocationItemTokens'], 'clear' => TRUE]);
+ $content = \Drupal\Core\Render\Markup::create($content);

Sorry I would supply a patch but I'm unlikely to create it cleanly.

CommentFileSizeAuthor
#4 2857185-4-token-clear.patch2.09 KBchristianadamski

Comments

dkre created an issue. See original summary.

dkre’s picture

Title: Tokens should be cleared if no replacement is found » Marker info text token output needs improvement
Category: Bug report » Task
Issue summary: View changes
dkre’s picture

Issue summary: View changes
christianadamski’s picture

Status: Active » Needs review
StatusFileSize
new2.09 KB

Hey @dkre,

thanks for this, good point!

- Added clears where token::replace is used.
- Markup will only return a string itself, plus its marked as @internal. So I won't add that part, unless you have a really good reason why.

  • dkre authored 97534f9 on 8.x-1.x
    Issue #2857185 by ChristianAdamski, dkre: Marker info text token output...
christianadamski’s picture

Status: Needs review » Fixed

Thanks!

Status: Fixed » Closed (fixed)

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