1

I am using hook_form_alter in a custom module to remove some fields from the block edit screen to clean up the ui for users of a certain role

function module_form_block_admin_configure_alter(&$form, &$form_state, $form_id) {
  global $user;
  if (in_array('staff member', $user->roles)) {
    $form['visibility_title']['#access'] = FALSE;
    $form['visibility']['#access'] = FALSE;
    return $form;
  }
}

It works great. However, when the form appears in Drupal's admin overlay using the site's admin theme, Seven, the above code is not applied.

Is this because it's in an overlay? Or because it's a different theme? How can I get the hook_form_alter to apply globally?

FWIW, adding

function module_form_alter(&$form, &$form_state, $form_id) {
    dpm($form);
}

doesn't print anything above the form in the overlay. But when I switch the admin theme to the site's theme, it properly dpm's the form.

Note: The custom module and the site's custom theme have the same name. Is this the problem?

2
  • 2
    If you implement a form alter hook in a .module file it will be invoked no matter what theme you're using or whether the form is displayed in an overlay...is it possible you're actually implementing the hook at the theme level? – Clive Oct 27 '12 at 12:38
  • Thanks, Clive. My code is identical to what's above. It's in a .module file. Also, when I add: function module_form_alter(&$form, &$form_state, $form_id) { dpm($form); } it doesn't show anything above the form in the overlay. Hmmm... – felix Oct 27 '12 at 12:49
3

Thanks to Clive's tip I realized that because my module and theme had the same name, the hook was being applied at the theme level. I renamed my module and now it works!

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.