I'm using the contrib module contact block and I would like to edit the block form settings. By default, there is a textfield (title) and the "Display title" checkbox, I need to hide those fields by use of some hook(s) but I don't know which one should I use, already tested:

  • hook_form_alter()
  • hook_field_widget_WIDGET_TYPE_form_alter()

My form. enter image description here

How could I hide them (without css)? Thanks all.

  • 1
    Can you please post the code you tried when testing hook_form_alter?
    – user72672
    Commented Nov 18, 2019 at 11:45
  • I just debugged the generic form alter to see if it came in
    – Javier Rey
    Commented Nov 18, 2019 at 11:47

1 Answer 1


You can use hook_form_alter do this but first should check the form concern only your block, if you check only on $form_id == 'block_form' you will hide those field in all block forms.
Try with the following.

 * Implements hook_form_alter().
function MyModule_form_alter(&$form, $form_state, $form_id) {
  // Check if the provider is contact_block, to target only contact_block form
  if ($form_id == 'block_form' && isset($form['settings']['provider']['#value']) && $form['settings']['provider']['#value'] == 'contact_block') {
    // Hide  Display title checkbox
    $form['settings']['label_display']['#access'] = FALSE;
    // Hide title textfield
    $form['settings']['label']['#access'] = FALSE;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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