2

I'm setting up an audit log for a large network of Drupal 7 sites with dozens of editors and 5 developers.

These events are already covered: Content Create, Content Update, Content Delete, User Login, User Logout, User Create, User Update (hook_user_update).

But I'm having a hard time logging:

  • Change in permissions
  • Change in settings

Any ideas how to go about logging that to watchdog?

1

Both of these are forms, so you can do something with a hook_form_alter. The easiest thing to do is do a View Source, find the form, and look at the ID on the <form> element.

The permissions form is user_admin_permissions. My suggestion would be to alter the form to add a new submit handler, eg

function mymodule_form_user_admin_permissions_alter(&$form, &$form_state, $form_id) {
  $form["#submit][] = 'mymodule_log_permission_change';
}

The settings changes are going to be tricky, as they are spread across many, many forms. The idea is the same, you just need to figure out whether you are on a setting for or not. You could alter all of the important setting forms, or you could try using the base hook_form_alter() and check the $form_id. You could also try checking the URL from withing the submit handler, as many of the settings live under /admin.

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.