The project page states, "This module has an extra hook in case you want to try to do a little extra cleanup to make a specific node type work." I have read the README and looked through the code itself, but I still can't figure out what this "extra cleanup" hook is or how to call it. What am I missing?

Thanks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ldweeks’s picture

Status: Active » Needs review
FileSize
791 bytes

Found it. Here's a patch for some documentation for the next guy.

Jax’s picture

In the 7.x version the signature is different:
drupal_alter('clone_node', $node, $context);

moshe weitzman’s picture

Version: 6.x-1.3 » 7.x-1.x-dev

Ideally this is documented in a new api.node_clone.inc file for D7.

RobLoach’s picture

Title: Where is the "extra hook" for "extra cleanup"? » API Documentation
Status: Needs review » Needs work

clone.api.php


/**
 * @file
 * API documentation for the Node Clone module.
 */

/**
 * Conduct alterations to the node after prepopulation of its fields.
 *
 * @param $node
 *   The node of which is being prepopulated.
 * @param $context
 *   An array of context associated during this prepopulation step. Holds a
 *   "method", and "original_node" values to help determine the current context
 *   of the node.
 */
function hook_clone_node_alter(&$node, $context) {
}

/**
 * Change the access granted to clone the given node.
 */
function hook_clone_access_alter(&$access, $node) {
}

johnv’s picture

Just for reference: there is also some text in clone.pages.inc.

function clone_node_prepopulate($original_node) {
  if (isset($original_node->nid)) {
    global $user;

    if (clone_is_permitted($original_node->type)) {
      ...
      // Let other modules do special fixing up.
      // The function signature is: hook_clone_node_alter(&$node, $context)
      // $context is an array with two elements, 'method' and 'original_node',
      // where 'method' is either 'prepopulate' or 'save-edit'.
      $context = array('method' => 'prepopulate', 'original_node' => $original_node);
      drupal_alter('clone_node', $node, $context);
      // Make sure the file defining the node form is loaded.
      module_load_include('inc', 'node', 'node.pages');
      return drupal_get_form($node->type .'_node_form', $node);
    }
  }
}
johnv’s picture

Title: API Documentation » API Documentation for hook_clone_node_alter()
dww’s picture

Assigned: Unassigned » dww
Status: Needs work » Needs review
FileSize
3.48 KB
3.75 KB

I was just using node_clone for a project and wanted to know if it invoked any hooks. Didn't see clone.api.php. Grepped the code. Found the alter hooks, and wrote my own API docs to contribute. Was about to submit a new issue but searched first and found this. ;) Here are patches for both D6 and D7, ready for git am goodness.

Cheers,
-Derek

johnv’s picture

This is nice - it took me a long time before mastering the hook_alter, although it is mentioned in the docu.
Perhaps you can add the following switch + simplification in the example:

function hook_clone_node_alter(&$node, $context) {
  switch ($context['method']) {
    case 'prepopulate':
      if ($node->type = 'special') {
        $node->special = special_something();
      }
      break;

    case 'save-edit':
      break;
  }
}
pwolanin’s picture

Thanks dww!

do we really need to remove the inline docs, or you just think that will get stale?

dww’s picture

Sure! :) Just seems pointless to duplicate them in multiple places where people aren't going to look. [module].api.php is the ubiquitous standard now, so if we've got that, we're set.

Cheers,
-Derek

pwolanin’s picture

Status: Needs review » Fixed

committed to 6 and 7

Status: Fixed » Closed (fixed)

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

  • Commit ce64a89 on 7.x-1.x, 8.x-1.x authored by dww, committed by pwolanin:
    Issue #1256478 by dww: add API Documentation for hook_clone_node_alter...