Problem/Motivation
Currently the IEF simple widget does not provide an 'instance' property in the form_state storage (like the complex widget does) and doesn't make it's `ief_id` value availible to the `inline_entity_form` element it builds (like the complex widget does).
This means that it is imposible to reference the correct widget state for an simple `inline_entity_form` in `hook_inline_entity_form_entity_form_alter`, and even if you can there if no information about the inplimenting field avalible as the 'instance' propery is missing.
Proposed resolution
Allow the IEF Simple widget to set the correct ief_id on the `inline_entity_form` element and provide a 'instance' property in the widget storage.
Once the cahnges have been implements developers will be able to do the following:
/**
* Implements hook_inline_entity_form_entity_form_alter()
*/
function hook_inline_entity_form_entity_form_alter(array &$entity_form, FormStateInterface &$form_state) {
// Currently, can't do this for IEF Simple widgets
$widget_state = $form_state->get(['inline_entity_form', $entity_form['#ief_id']]);
// Currently, no easy way to access the definition of the field responsible for this inline_entity_form
$field_definition = $form_state->get(['inline_entity_form', $entity_form['#ief_id'], 'instance']);
if ($field_definition->getName() === 'field_custom') {
// Do stuff..
}
}
Issue fork inline_entity_form-3267941
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
lind101 commentedComment #3
lind101 commentedComment #4
lind101 commentedComment #5
lind101 commentedComment #7
lind101 commentedMR in #6 privides the DX improvements mentioned on the ticket.
Comment #8
lind101 commentedComment #9
geek-merlinThanks for raising this and providing a MR!
Let's take this apart...
# IefId
So you say the complex widget provides this in the $entity_form array, but not the simple, and we can fix this if we set $this->iefId?
If yes, that's uncontroversal, and i dimply remember which commit killed that. Can you provide a test for both widgets so this won't break in the future?
You can dig through the existing tests and add a method to one that seems fit.
# field instance
I'm a bit hesitant to add new APIs, as we must support them forever, and forever is a quite long time, esp. towards the end.
That said, i looked into this and don't have an idea how that use case can be done today (at least without killing lots of kittens).
So yes, so be it.
Can you
- first finish a MR with only the iefId fix, and test
- move the other to a second issue and MR
- add a test for that too?
Tha'd be great.