Right now when you load a token it comes through as a full link rather than the bare URL. It also isn't possible to change this as there's no customizable Token view mode for the Multifield entity.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DamienMcKenna’s picture

It'd probably just fine to have expanded token integration to have additional sub-tokens, e.g. "[entity:field_name:url]".

Dave Reid’s picture

Title: Provide way to customize the token output » Add a plain text URL formatter and set as the default token formatter

Probably worth warranting changing the 'default token formatter' to the plain non-linked version, which doesn't exist yet.

To customize see https://drupal.org/node/1299662 which covers that request.

Dave Reid’s picture

Also could help to review #1778238: Add entity property API support for the sub-tokens when using the Entity tokens module.

DamienMcKenna’s picture

FYI I'm using the field in a Multifield which doesn't support the Tokens view mode, otherwise I wouldn't have asked.

DamienMcKenna’s picture

I'm working on a patch to add a default_token_formatter, will post shortly.

DamienMcKenna’s picture

DamienMcKenna’s picture

Status: Active » Needs review
FileSize
4.74 KB

Would this work? It adds a new url_raw formatter that runs it through check_plain() (optionally trimmed) prior to output.

DamienMcKenna’s picture

FileSize
4.73 KB

This replaces the check_plain() with check_url(), per discussion with Dave in IRC.

Dave Reid’s picture

+++ b/url.module
@@ -238,6 +239,13 @@ function url_field_formatter_info() {
+  $info['url_raw'] = array(
+    'label' => t('Raw URL'),

Let's name this formatter url_plain for consistency with text module. And have the label be 'Plain URL'

DamienMcKenna’s picture

FileSize
4.74 KB

As you wish.

DamienMcKenna’s picture

FileSize
4.72 KB

This version has actually been tested :) and outputs the desired plain URL.

Dave Reid’s picture

Status: Needs review » Needs work
  1. +++ b/url.module
    @@ -277,10 +293,22 @@ function url_field_formatter_settings_summary($field, $instance, $view_mode) {
    +    }
    +    $summary[] = t($message, array('@char' => $settings['trim_length']));
       }
    

    This prevents the string from being recognized by localize.drupal.org. We should just use $summary[] = t(...).

  2. +++ b/url.module
    @@ -277,10 +293,22 @@ function url_field_formatter_settings_summary($field, $instance, $view_mode) {
    +    }
    +    t('Link text not trimmed.');
    

    Missing $summary[] = ?

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
4.71 KB

Doh! How's about this?

JonMcL’s picture

Issue summary: View changes

Worked nicely for me, but very minimal testing. Using it to display the URL in some custom admin Views.

madar’s picture

I use it with Linked Field to navigate to an external url on an image field. Working as expected.

Anybody’s picture

Status: Needs review » Needs work

There is a little bug in the patch:

+    if ($display['type'] == 'url_default') {
+      $summary[] = t('Link text trimmed to @char characters.');
+    }
+    else {
+      $summary[] = t('URL trimmed to @char characters.');
+    }

The @char is missing its replacement!

After that the patch may be set RTBC from my point of view. My tests were also absolutely successful.

Anybody’s picture

Final note: I had to display the token display settings first, enable and set the URL field settings there, save it and disable the token display setting in the entity again to make it work.
The best solution might be to update the related settings via a hook_update, but I think that's bonus.

DamienMcKenna’s picture

Parent issue: » #2534394: Plan for URL Field 7.x-1.1 release
FileSize
4.68 KB

Shouldn't the messages for when the strings are not trimmed be different?

DamienMcKenna’s picture

Status: Needs work » Needs review
Anonymous’s picture

I'm using the patch from #18 with Linked Field in an Field Collection. Working as expected.

Anybody’s picture

Status: Needs review » Reviewed & tested by the community
stupiddingo’s picture

RTBC + 1 - working well for tokens and panes in panels.