Follow-up for #111715: Convert node/content types into configuration

Problem/Motivation

Currently there's a hooks:
hook_load, hook_prepare, hook_view, hook_form, hook_validate, hook_insert, hook_update, hook_delete
That have similar hooks with node prefix - hook_node_insert

Also there's hook_ranking but depends on node...

Proposed resolution

Stop support node_hook() and remove usage of node_invoke()
Modules should move their implementations into corresponding hook_node_*() space and use hook_form_alter*() to modify node form

Remaining tasks

  1. Drop usage
  2. Change notice
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andypost’s picture

Status: Active » Needs review
FileSize
9.3 KB

Deprecated, and removed hooks docs
- hook_form moved to hook_node_form

Crell’s picture

I thought we'd removed hook_load and friends already. Yes please, they all need to die.

+++ b/core/modules/node/node.module
+++ b/core/modules/node/node.module
@@ -865,6 +865,8 @@ function node_rdf_mapping() {

@@ -865,6 +865,8 @@ function node_rdf_mapping() {
  *
  * @return string|false
  *   A string containing the function name or FALSE if it isn't found.
+ *
+ * @deprecated as of Drupal 8.0. Do not use this.
  */
 function node_hook($type, $hook) {

Why not just remove?

Status: Needs review » Needs work

The last submitted patch, node-hook-2018375-1.patch, failed testing.

andypost’s picture

Title: Get rid of node_hook » Get rid of node_hook and node_invoke
Status: Needs work » Needs review
FileSize
22.1 KB
13.31 KB

Let's try to drop and node_invoke() to help #353494: Remove node_invoke(), comment_invoke(), etc

catch’s picture

+  if (!$node->isNew()) {
+    $forum_terms = $node->taxonomy_forums;

Is this really always set? Otherwise looks amazing.

andypost’s picture

FileSize
25.87 KB
5.87 KB

Fix for remains

Berdir’s picture

+++ b/core/modules/node/lib/Drupal/node/NodeFormController.phpundefined
@@ -341,13 +338,9 @@ public function validate(array $form, array &$form_state) {
     // Can't use node_invoke() or module_invoke_all(), because $form_state must
     // be receivable by reference.
-    if ($function = node_hook($node->type, 'validate')) {
-      $function($node, $form, $form_state);

This still talks about node_invoke().

+++ b/core/modules/node/node.api.phpundefined
@@ -1105,7 +1052,7 @@ function hook_prepare(\Drupal\Core\Entity\EntityInterface $node) {
-function hook_form(\Drupal\Core\Entity\EntityInterface $node, &$form_state) {
+function hook_node_form(\Drupal\Core\Entity\EntityInterface $node, &$form_state) {
   $type = node_type_load($node->type);

That actually exists?

+++ b/core/modules/node/node.moduleundefined
@@ -3112,29 +3074,6 @@ function _node_access_rebuild_batch_finished($success, $results, $operations) {
  * @} End of "defgroup node_content".

The @defgroup definition is right above node_content_form(), looks like we can kill that? anything left that references it?

Agreed, this looks great.

andypost’s picture

drop @defgroup
Suppose it was last

andypost’s picture

FileSize
26.11 KB
587 bytes
catch’s picture

Status: Needs review » Reviewed & tested by the community

Don't see anything left to do here.

dmitrii’s picture

Here is some old hooks mentions in comments.
If anyone with good English please check.

/d8/core/modules/node/node.api.php (2 hits)
Line 510: * read from the database or the entity cache, hook_load() is invoked on the
Line 521: * module defines a content type, you can use hook_load() to respond to
/d8/core/modules/node/node.api.php (1 hits)
Line 400: * hook_delete() has been invoked, but before hook_entity_predelete() and
/d8/core/modules/file/lib/Drupal/file/Tests/ValidateTest.php (1 hits)
Line 40: // Now test for failures in validators passed in and by hook_validate.
/d8/core/modules/node/node.api.php (1 hits)
Line 731: * hook_validate() is invoked.
/d8/core/modules/node/node.api.php (1 hits)
Line 677: * type-specific hook_update() is invoked, and after field_attach_update() is
/d8/core/modules/node/node.api.php (2 hits)
Line 25: * content type as "forum", so during creation of a forum node, hook_insert() is
Line 457: * type-specific hook_insert() is invoked, and after field_attach_insert() is
/d8/core/modules/node/lib/Drupal/node/NodeFormController.php (1 hits)
Line 23: * Fills in a few default values, and then invokes hook_prepare() on the node
/d8/core/modules/node/node.api.php (1 hits)
Line 612: * type-specific hook_prepare() is invoked.

andypost’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
9.09 KB
34.39 KB

Drop remains. Changed comments needs review

ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community

couldnt find occurences and docs look good

catch’s picture

Title: Get rid of node_hook and node_invoke » Change notice: Get rid of node_hook and node_invoke
Priority: Normal » Critical
Status: Reviewed & tested by the community » Active

Committed/pushed to 8.x, thanks!

Will need a change notice.

andypost’s picture

andypost’s picture

Status: Active » Needs review

Mentioned about the change in https://drupal.org/node/2029519 do we really need separate notice?

catch’s picture

Title: Change notice: Get rid of node_hook and node_invoke » Get rid of node_hook and node_invoke
Status: Needs review » Fixed

No that's plenty, thanks!

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Component: node.module » node system
Issue summary: View changes