The line:

  // Allow other modules to alter step information.
  drupal_alter('msnf_info_steps', $steps_cached, $entity_type, $bundle, $form, $form_state);

lacks context when it gets to the actual implementation of the alter as drupal_alter() only does this:

function drupal_alter($type, &$data, &$context1 = NULL, &$context2 = NULL) {
...
  $function($data, $context1, $context2);
...
}

So it is better to pass through a contextual array instead.

Sadly this is an API change, but it is required to provide any additional context other than just $entity_type (isn't this always 'node' or does the module handle other things) and $bundle.

Patch uses a two argument alter that provides a $context parameter.

Implementation changes are:

function HOOK_msnf_info_steps_alter(&$steps_cached, $entity_type, $bundle, $form = NULL, $form_state = NULL) {
  // $form and $form_state are never populated.
  if ($bundle == 'page') {
    // do something ....
  }
}

to

function HOOK_msnf_info_steps_alter(&$steps_cached, $context) {
  // The lazy way - extract the variables to a local namespace.
  extract($context, EXTR_SKIP); // Extract the variables to a local namespace
  if ($bundle == 'page') {
    // do something ....
  }

  ### OR  ###

  // Reference the array data directly or pull these out one by one "$bundle = $context['bundle'];".
  if ($context['bundle'] == 'page') {
    // do something ....
  }
}

And to support any version of msnf:

function HOOK_msnf_info_steps_alter(&$steps_cached, $entity_type, $bundle) {
  if (is_array($entity_type)) {
    extract($entity_type, EXTR_SKIP);
    $bundle = $entity_type['bundle'];
    $entity_type = $entity_type['entity_type'];
  }
  // Exactly the same as before with possible copies of the $form, $form_state
}

Not actually sure what Form really is here, but it is not a renderable element afaick, but has the node object that I was after.

Comments

rooby’s picture

StatusFileSize
new2.2 KB

Patch looks good to me.

The only changes I made are:
* Removing duplicate comment above drupal_alter() call.
* Adding changes to the api docs to match the new format and also to fix bugs that were already in the docs.

I guess I shouldn't RTBC this since I made all the changes to the docs that will need review, but it does work.

pfournier’s picture

Works for me

stborchert’s picture

Status: Needs review » Fixed

Thanks for your work. Committed to 7.x-1.x-dev.

  • stBorchert committed 9e717e2 on 7.x-1.x authored by Alan D.
    Issue #1967284 by Alan D., rooby: Calling drupal_alter() with too many...

Status: Fixed » Closed (fixed)

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