I need to get this hook to pre create a fix number of paragraphs.

Also I saw that the hook entity prepare form is never triggering with IEF.

Here a patch to call this hook

Comments

Musa.thomas created an issue. See original summary.

musa.thomas’s picture

StatusFileSize
new1.78 KB
ziomizar’s picture

Status: Active » Needs review
StatusFileSize
new935 bytes
new1.89 KB

The patch on #2 for me, just a minor fix on the $entity parameter

neeravbm’s picture

Status: Needs review » Reviewed & tested by the community

The patch is working fine. I was able to apply the patch using Composer. Then I added hook_entity_prepare_form() in a custom module and made sure that the code in this hook is being executed.

joachim’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/src/Form/EntityInlineForm.php
    @@ -225,6 +228,27 @@ class EntityInlineForm implements InlineFormInterface {
    +    $implementations = $this->moduleHandler->getImplementations($hook);
    +    foreach ($implementations as $module) {
    +      $function = $module . '_' . $hook;
    +      if (function_exists($function)) {
    

    What's the reason for building the function name rather than using module handler's invokeAll()? This should be explained in the comments.

  2. +++ b/src/Form/EntityInlineForm.php
    @@ -225,6 +228,27 @@ class EntityInlineForm implements InlineFormInterface {
    +        // Ensure we pass an updated translation object and form display at
    +        // each invocation, since they depend on form state which is alterable.
    +        $args = [$entity, 'add', &$form_state];
    

    I don't understand how the comment relates to the code. Where or what is the updated translation object?

ziomizar’s picture

Just a minor hint is that the suggestions and questions reported in #5 apply also in core from which this patch has been based https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!EntityForm...

geek-merlin’s picture

Title: Hook entity_prepare_form is never trigger » IEF does not invoke hook_entity_prepare_form
Priority: Normal » Major
Related issues: +#3119807: Provide a hook_paragraph_entity_prepare_form

Thank ya all! Setting major as this violates a basic API expectation.

As of #5/#6: An updated patch should state where that code is copied from (no shame ;-). And rewrite comments that probably had been copied but not adapted before (shame!).

eugene.brit’s picture

StatusFileSize
new1.53 KB
new1.74 KB

Re-roll #3 for 10.0.x

podarok’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
Status: Needs work » Needs review

  • podarok committed e486d9e6 on 2.0.x authored by eugene.brit
    Issue #3015323 by ziomizar, eugene.brit, Musa.thomas: IEF does not...
podarok’s picture

Status: Needs review » Fixed

#8 is in
tnx

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

geek-merlin’s picture

Version: 2.0.x-dev » 3.x-dev
Status: Closed (fixed) » Needs review
Related issues: +#3401656: Clean up problematic 2.x branch

Bulk reopen.

geek-merlin’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

I still like this a lot. Revisiting this after quite some time, my gut feeling is that this must not re-purpose hook_entity_prepare_form, but invent an IEF version of it. (Anyone with a good reasoning that it is not so, please explain!)

geek-merlin’s picture

The related issue confirms that this implementation is wrong and must not be committed.
An IEF version of that hook makes sense though.

dww’s picture

geek-merlin’s picture

Title: IEF does not invoke hook_entity_prepare_form » Add hook_inline_entity_form_entity_prepare_form
Category: Bug report » Task

#14:
> still like this a lot. Revisiting this after quite some time, my gut feeling is that this must not re-purpose hook_entity_prepare_form, but invent an IEF version of it.

Comment #3364996-15: Parent form entity builders run on IEF resulting in fatal errors of that issue elaboratest that brilliantly.

Updating title accordingly.

geek-merlin’s picture

Title: Add hook_inline_entity_form_entity_prepare_form » Add hook_inline_entity_form_[entity|ENTITYTYPE]_prepare_form