The hooks for instance and widget settings, hook_field_widget_settings_form() and hook_field_instance_settings_form() both return form arrays, but receive no information at all about the larger form they're inserting into.

This means that they can't add more complex behaviours such as dependencies and ajax -- hook_form_alter has to be used instead.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yched’s picture

That's true - cannot wrap a patch myself right now, so any takers welcome :-)

Though, note that introducing a $form param means the code in the existing hook implementations will need to be adapted, since most of them use $form as the name of the sub-element that the hook builds and return (in some cases, initializing $form as an empty array first thing). This internal var should be renamed $element or something.

joachim’s picture

Oh I hadn't thought of that.

$element to me implies a single form element which could be confusing perhaps?
How about $settings_form?

yched’s picture

$element is already used in other parts of drupal to identify "a subpart of a form / render array", I think.
+ that's also what core hook_field_formatter_settings_form() implementations use (because this hook does receive $form and $form_state :-/)

larowlan’s picture

Assigned: Unassigned » larowlan
Issue tags: +#pnx-sprint

I'll tackle this, hit it today trying to get ajax behaviour on a settings form

larowlan’s picture

Assume this is not back-portable?

joachim’s picture

> Assume this is not back-portable?

It depends. If you add the new parameters to the end, then yes, it can be backported, as older implementations of the hook simply won't care.

larowlan’s picture

Issue tags: +Needs backport to D7

Will add params at end.

larowlan’s picture

Status: Active » Needs review
FileSize
21.37 KB

First cut

Status: Needs review » Needs work

The last submitted patch, form-state-for-field-api-1391196-8.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review
FileSize
2.91 KB
21.85 KB

Take two ditching module_invoke so we can pass form_state by reference.

Status: Needs review » Needs work

The last submitted patch, form-state-for-field-api-1391196-10.patch, failed testing.

larowlan’s picture

Status: Needs work » Needs review
FileSize
1.23 KB
21.89 KB
CB’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me!

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

This should have automated tests.

larowlan’s picture

Hey Tim
Can you give me an example of how the tests should go here?
Testing ajax functionality on instance_settings_form? or is that too over the top.

LR

larowlan’s picture

Unless I'm mistaken, this is no longer relevant to D8 as Widget As Plugins has replaced many of these hooks (and the class methods pass $form and $form_state).
Any objections to setting this back to D7 and setting status as 'Patch needs port'?

yched’s picture

Widget settings forms have been taken care of in D8 with the "widgets as plugins" patch, but field and instance settings forms haven't yet. They will be, but not in the next couple weeks.
So strictly speaking, a D8 patch should still include the fix for those, and then #12 can be rerolled as a D7 patch.

swentel’s picture

Version: 8.x-dev » 7.x-dev

Field types are no plugins, so this doesn't apply anymore to D8. I'm not even sure whether we can change those function signatures in D7 though ... feels like a won't fix to me.

larowlan’s picture

Assigned: larowlan » Unassigned
mstrelan’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)
Issue tags: -Needs backport to D7

Discussed this with @larowlan and we agreed this is won't fix as per #18. The lack of interest over the past 9 years solidifies that case.