Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#1 | addressfield-more_context-2442581-1.patch | 509 bytes | rudiedirkx |
Comments
Comment #1
rudiedirkx CreditAttribution: rudiedirkx commentedPatch adds 2 lines/vars to
$context
.Comment #2
bojanz CreditAttribution: bojanz commentedMy 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?
Comment #3
rudiedirkx CreditAttribution: rudiedirkx commentedConsistency 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. =)