From e486d9e61e4c6cd1de9f74d344d62876d9ba9d56 Mon Sep 17 00:00:00 2001
From: Eugene Brit <13477-eugene.brit@users.noreply.drupalcode.org>
Date: Mon, 22 May 2023 18:10:30 +0300
Subject: [PATCH] Issue #3015323 by ziomizar, eugene.brit, Musa.thomas: IEF
 does not invoke hook_entity_prepare_form

---
 src/Form/EntityInlineForm.php | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/Form/EntityInlineForm.php b/src/Form/EntityInlineForm.php
index e24fd8f0..235142ea 100644
--- a/src/Form/EntityInlineForm.php
+++ b/src/Form/EntityInlineForm.php
@@ -183,6 +183,9 @@ class EntityInlineForm implements InlineFormInterface {
   public function entityForm(array $entity_form, FormStateInterface $form_state) {
     /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
     $entity = $entity_form['#entity'];
+
+    $this->prepareInvokeAll($entity, 'entity_prepare_form', $form_state);
+    $this->prepareInvokeAll($entity, $entity->getEntityTypeId() . '_prepare_form', $form_state);
     $form_display = $this->getFormDisplay($entity, $entity_form['#form_mode']);
     $form_display->buildForm($entity, $entity_form, $form_state);
     $entity_form['#ief_element_submit'][] = [
@@ -258,6 +261,22 @@ class EntityInlineForm implements InlineFormInterface {
     return $entity_form;
   }
 
+  /**
+   * Invokes the specified prepare hook variant.
+   *
+   * @param \Drupal\Core\Entity\ContentEntityInterface $entity
+   *   The entity object.
+   * @param string $hook
+   *   The hook variant name.
+   * @param \Drupal\Core\Form\FormStateInterface $form_state
+   *   The current state of the form.
+   */
+  protected function prepareInvokeAll(ContentEntityInterface $entity, $hook, FormStateInterface $form_state) {
+    $this->moduleHandler->invokeAllWith($hook, function (callable $hook, string $module) use (&$entity, &$form_state) {
+      $hook($entity, 'add', $form_state);
+    });
+  }
+
   /**
    * {@inheritdoc}
    */
-- 
GitLab