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.
For Drupal 7, if you provide a super advanced formatter for a field type, and your field is named 'advanced_field_formatter', because your module is listed alphabetically first, this means your formatter is listed first as the default formatter in select boxes for the field type. It is interesting that hook_field_widget_info() supports a 'weight' parameter, but not hook_field_formatter_info(). I think it should. It's an easy one-line add for Drupal 7.
Comment | File | Size | Author |
---|---|---|---|
#29 | formatter_weight-1982776-29.patch | 5.78 KB | plopesc |
#29 | formatter_weight-1982776-29-test-only.patch | 4.75 KB | plopesc |
#18 | formatter_weight-1982776-18-test-only.patch | 9.24 KB | plopesc |
#16 | issue-1982776-ordering-weights-16.patch | 4.44 KB | netsensei |
#16 | interdiff.txt | 943 bytes | netsensei |
Comments
Comment #1
Dave ReidPatch attached for D7, needs to be re-rolled for D8.
Comment #2
Dave ReidPatch against D8.
Comment #4
Dave ReidBlargh.
Comment #5
Dave ReidAnd revised patch for D7.
Comment #6
haydeniv CreditAttribution: haydeniv commentedYeah I ran into this problem with Select (or other) #1953284: Increase module weight with random ordering of the widget list. I ended up having to increase my whole module weight got get it to drop below the other formatters. I thought it was a bit strange that I could change weight on widget but not formatter.
Comment #7
swentel CreditAttribution: swentel commentedMakes sense, patch in #4 still applies fine.
Comment #8
alexpottI think we should adds tests for this...
Comment #9
Dave ReidWell there were no tests for widget weights, but I'll try to add some.
Comment #10
swentel CreditAttribution: swentel commentedTagging
Comment #11
netsensei CreditAttribution: netsensei commentedGoing to take a stab at this one.
Comment #12
netsensei CreditAttribution: netsensei commentedOkay. First attempt.
A bit new-ish at this: per Swentels' instructions:
a/ Patch with a test which should fail
b/ Patch with a test and a fix which should pass.
Comment #13
netsensei CreditAttribution: netsensei commentedSuggested by Swentel: fix comment which exceeded the 80 character line.
Comment #14
haydeniv CreditAttribution: haydeniv commentedLooks good. Patch was RTBC before. Now has passing tests. I gave it one more look so RTBC. Excited to have this so I can fix module weight issue over at Select (or Other)
Comment #15
alexpottWe should use the
Drupal\Component\Utility\SortArray::sortByWeightElement()
here as this is OO code and we should call into common.inc unless absolutely necessary.Testing sort order by only asserting on an array of one formatter seems odd.
Comment #16
netsensei CreditAttribution: netsensei commented1.
Changed the uasort compare callback.
2.
Yes. Tests for this should be fleshed out some more. I'm new at writing good tests, so not sure how this should practically look like. This test only works on an explicit formatter case (field_weight_test) with the weight parameter set. I could test a normal default case where no weight properties are set and we assume a default ordering.
Comment #18
plopescRe-rolling.
Instead of adding a new formatter, adding weight to existing ones to test the ordering. Also adding same tests for widgets.
Regards.
Comment #20
swentel CreditAttribution: swentel commentedHmm, this comment mixes formatters with widgets.
Other than that, this looks good to me.
Comment #21
plopescUps, I didn't remove all the widget references... :(
Comment #22
swentel CreditAttribution: swentel commented21: formatter_weight-1982776-21.patch queued for re-testing.
Comment #23
swentel CreditAttribution: swentel commentedComment #25
swentel CreditAttribution: swentel commented21: formatter_weight-1982776-21.patch queued for re-testing.
Comment #26
swentel CreditAttribution: swentel commentedLet's hope this one doesn't run 14 days either.
Comment #27
webchickCommitted and pushed to 8.x. Thanks!
Comment #28
Dave ReidTime for D7 then!
Comment #29
plopescBackporting patch. Also adding tests for both widget and formatter weight.