Problem/Motivation

https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/node/...

The function node_reindex_node_search() is called from Node.php, mixing procedural code with object-oriented code. This doesn't align with modern Drupal practices.

Proposed resolution

Deprecate the node_reindex_node_search() function in node.module.

Move the search reindexing logic to a more appropriate place, into a proper hook such as hook_node_update()

Remaining tasks

  • Deprecate node_reindex_node_search()
  • Move the logic into a new public method on a new NodeEntityHooks class
  • Move the following methods from NodeHooks1 into NodeEntityHooks: commentInsert, commentUpdate, commentDelete
  • Remove the call from Node.php, move into a #[Hook('node_update')] hook on NodeEntityHooks

API changes

node_reindex_node_search() will be deprecated.

Issue fork drupal-3533612

Command icon 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

virag.jain created an issue. See original summary.

acbramley’s picture

Issue summary: View changes

There is only 1 usage of this function according to http://codcontrib.hank.vps-private.net/search?text=node_reindex_node_sea... and that module doesn't have a release, looks unmaintained.

I don't think we need a replacement here, we'll just do all the work in a new Hooks file. Have updated the proposed solution.

libbna made their first commit to this issue’s fork.

libbna’s picture

Status: Active » Needs work

Hey, in #4 I have done the following changes:

  1. Deprecate node_reindex_node_search()
  2. Move the logic into a new public method on a new NodeEntityHooks class
  3. Move the following methods from NodeHooks1 into NodeEntityHooks: commentInsert, commentUpdate, commentDelete
  4. Remove the call from Node.php, move into a #[Hook('node_update')] hook on NodeEntityHooks

Let me know if everything looks good or if any changes are needed, or if I’ve missed anything. I'm changing the status to "Needs Work" for now so the work can continue in case the pipeline fails or test cases need to be added.

acbramley’s picture

Status: Needs work » Needs review

Actioned feedback and fixed up linting.

Only thing I'm not sure on is if we should even mention the new replacement in the CR, it's in a Hooks class so it's a bit weird but it does technically mean there's a way to do it without us having to add yet another service.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

I'm generally not very fond of modules implementing their own entity hooks but I think this is a good example for when it makes sense: Optional integration with another module, this allows us to encapsulate and group all related hooks for that in one service. And with #3524377: Allow to skip OOP hooks and services for modules that are not installed, we plan to have a means for dynamically registering this hooks service only when the search module is installed, something that for now would either require a node_search glue module or custom ServiceProvider code.

And then with this we also have a real use case in core that we can test it with.

I think mentioning the replacement in the CR is fine, personally I wouldn't really have bothered with the Why section. Realistically speaking, we plan to deprecate basically all runtime procedural code by deprecating .module files, doesn't really matter where it's called from.

catch’s picture

Status: Reviewed & tested by the community » Needs work

The replacement doesn't seem right to me - asked a question on the MR. fwiw I'd also be fine with 'deprecated with no replacement'.

acbramley’s picture

Status: Needs work » Reviewed & tested by the community

Agreed, also made the hooks method protected.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x, thanks!

  • catch committed 45f48d76 on 11.x
    Issue #3533612 by acbramley, virag.jain, libbna, berdir: Deprecate...

Status: Fixed » Closed (fixed)

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