hook_entity_update always runs before EntityFormHandler::submitForm()

Created on 28 July 2022, over 2 years ago
Updated 21 October 2024, 2 months ago

After a node is updated, I'm attempting to run some logic to remove it from the sitemap.

However, regardless of what I do (such as rearranging the weight of the modules), the form submit handler (EntityFormHandler::submitForm) always runs after my hook and removes my override when it calls setEntityInstanceSettings().

Can someone please explain to me what I'm doing wrong?

I had to install https://www.drupal.org/project/hook_post_action to make it work by running it in hook_node_postupdate.

Here's my code:

  if ($node->bundle() == 'xxx') {

    /** @var \Drupal\simple_sitemap\Manager\Generator $generator */
    $generator = \Drupal::service('simple_sitemap.generator');

        if (!empty($node->get('field_no_link')->value)) {

          $status = $generator->setVariants('default')
            ->entityManager()
            ->getEntityInstanceSettings("node", $node->id());

          if (isset($status["default"]["index"]) && $status["default"]["index"] == TRUE) {
            // Unset XML Sitemap
            $generator->setVariants('default')
              ->entityManager()
              ->setEntityInstanceSettings('node', $node->id(), ['index' => FALSE]);
          }
        }
}
💬 Support request
Status

Fixed

Version

4.1

Component

Code

Created by

🇵🇹Portugal introfini

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024