It took me some time and an upgrade to the latest dev of workflow_access to get hook_workbench_access_node_element_alter to run to make some alterations to the default element.

I've found that when the hook is running in my_module.workbench_access.inc it only fires on the first page load after flushing the cache. From then on it doesn't run again and $element is back to the default state it was in before the alter.

If the hook is in my_module.module it runs each time the node form is loaded, which is the behaviour I would have expected.

Comments

agentrickard’s picture

That actually could be a core bug. Do you have code you can share?

ericaordinary’s picture

This is an example of the function that is working in my_module.module but not in my_module.workbench_access.inc:

function my_module_workbench_access_node_element_alter(&$element, $form_state, $active) {
  switch ($form_state['build_info']['args'][0]->type) {
    // Set the #access to FALSE on research lab nodes so that we can programatically update it after the new node is saved.
    case 'research_lab':
      $element['#access'] = FALSE;
      break;
    default:
      $element['#access'] = TRUE;
      break;
  }
}

When it's in .inc it will fire the first page load after a cache clear, but from then on #access is back to true. I also tested just making a simple change to the Section field label with the same result.

I also tried using the form_alter hook provided in the API but I couldn't get that function to fire at all, no matter which file it was in. This may or may not be related.

agentrickard’s picture

It may be that form caching doesn't allow this. I'll test.