Address field has many properties, we should be able to get all properities and rebuild for the output.

It would be perfect if Ctools/Panels has address field context.

dd

Comments

kriboogh’s picture

Donno if original poster is still interested, but I got this working for user contexts by patching the fieldaddress.tokens.inc file. (sorry my patch from local history isn't working in eclipse)

Replace addressfield_token_info_alter with:

function addressfield_token_info_alter(&$data) {

  $info = addressfield_token_info();
  $tokens = $info['tokens']['address-field'];

  // Loop over every address field on the site.
  foreach (array_filter(field_info_field_map(), 'addressfield_field_map_filter') as $field_name => $field) {
    foreach ($data['tokens'] as $group => $token){
      if (isset($data['tokens'][$group][$field_name]) && is_array($data['tokens'][$group][$field_name])) {

        foreach($tokens as $token => $info) {
          $info['type'] = 'text';
          $info['entity token'] = TRUE;
          $data['tokens'][$group][str_replace('_', '-', $field_name) . ':' .$token] = $info;
        }

        // Set the token type for the field to use the addressfield child tokens.
        //$data['tokens'][$group][$field_name]['type'] = 'address-field';
      }
    }
  }
}

Add extra checks on line 218: (line 205 originally)

  if ($type == 'entity' || $type == 'user' || $type == 'node') {

This will get you extra replacement tokens in the panels replacement patterns ui, style:
%user:field-my-address:first-name

The reason i did it this way was because panels uses 'user' a a context rather then 'entity'. Also the replacement patterns in panels are restricted only to the context object, so although the addressfield tokens are available when getting all tokens, it only lists the ones for the context object, being user, entity or node. Also ctools user.inc checks if the token is a key in the context. That's why i explicitly set the extra tokens with the ':' in them.

There is probably a way better way to do it, but i needed as solution fast and haven't got time to dive into ctools/panels/tokens at the moment. Donno if this breaks anything else, it will probably bite me back somewhere in views or so, but it does what is has to do for me at the moment. Which is getting the first-name in the title of a user profile overview using panelizer in panopoly.

joshf’s picture

Issue summary: View changes
StatusFileSize
new1.81 KB

Attached patch of #1.

rogical’s picture

Status: Active » Needs review