In addressfield_field_formatter_view(), a $context is sent to addressfield_generate($address, $handlers, $context) that contains mode, field, instance, langcode and delta. All useful, but why not include all the knowns?

Missing: entity and display. Formatters might want to use them. (My formatter does.)

Patch later.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rudiedirkx’s picture

Title: Include entity in $context when generating the address markup » Include $entity and $display in $context when generating the address markup
Status: Active » Needs review
FileSize
509 bytes

Patch adds 2 lines/vars to $context.

bojanz’s picture

Status: Needs review » Closed (won't fix)

My initial thought was "why not", but then I remembered that the plugins rely on getting the same context for both the widget and the formatter use case, and $display and $entity can only be provided while formatting, making context inconsistent. Having the plugin output be the same for widgets and formatters has always been a strong consideration, though not necessarily one I agree with.

In your case it probably makes more sense to write a normal custom formatter instead of an addressfield plugin?

rudiedirkx’s picture

Consistency is obviously valuable, but since you're not removing anything, I'd say Add it all! In this case I'm not even a big fan of the 'consistency', because form and display are very different things that shouldn't have to use the same logic, but that's another discussion.

I can do a custom formatter, but that's a lot of work for something that already almost works. =)