6

I need to alter data of a contrib module, which does a call drupal_alter('workbench_access_user', $access, $account);.

How must my function look like? My module's name is workbench_access_crud_by_state.

Is the following OK? What about the parameters? I am confused about that data and context stuff.

function workbench_access_crud_by_state_workbench_access_user_alter($access, $account) {
  //do sth
  $bla = 'test';
  debug($bla);
}

It seems that my hook implementation is not being called at all and there are no error messages.

8

A hook implementation is always prefixed by the short name of the module implementing it; alter hooks need to have _alter appended. So, in your case, since workbench_access_crud_by_state is the machine name of the module, workbench_access_crud_by_state_workbench_access_user_alter($access, $account) is the correct signature for that alter-hook implementation.

As for the parameters, drupal_alter() accepts:

  • $type is the type of the alter hook, without the _alter part; in your case, that is workbench_access_user

  • &$data is the reference to the variable which contains the value to alter

There are other three parameters, which are optional and normally used to give context to the operation being performed.

In Drupal 8, the call to drupal_alter() is replaced with a call to \Drupal::moduleHandler()->alter(); in this case, the number of context parameters has been reduced to 2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.