3

How can I add a block with some HTML to the Node Add/Edit form? I've tried adding a new #markup field but I couldn't position it where I need by using weight.

See image below for desired location: just below the vertical tabs displayed to the right in the Seven theme.

Node edit form

  • 1
    I suggest posting your code here, so others can have a look and point out if there is anything wrong. – Aram Boyajyan Jul 20 '16 at 19:02
5

If you're looking insert renderable elements into the form array in the same manner as the grouped vertical tabs, you can hook_form_alter() your way to this via adding a details form element:

function MYMODULE_form_alter(&$form, $form_state, $form_id) {

  // @TODO: Add your own logic for filtering relevant node forms
  if (in_array($form_id, array('node_page_form', 'node_page_edit_form'))) {
    $form['example'] = array(
      '#type' => 'details',
      '#title' => t(''),
      '#description' => t(''),
      '#group' => 'advanced',
      '#open' => TRUE,
      'markup' => array(
        '#markup' => '<p>Random Markup</p>',
      ),
      '#weight' => 1000,
    );
  }
}

If you're looking to add markup that's not relevant to your node forms, you might be better off subtheming Seven and adding your own node-edit-form.html.twig template to your subtheme with your own markup additions:

<div class="layout-node-form clearfix">
  <div class="layout-region layout-region-node-main">
    {{ form|without('advanced', 'actions') }}
  </div>
  <div class="layout-region layout-region-node-secondary">
    {{ form.advanced }}
    <p>Random Markup</p>
  </div>
  <div class="layout-region layout-region-node-footer">
    {{ form.actions }}
  </div>
</div>
  • This is exactly what I was looking for. I didn't know about the "details" Form API element. Thank you! – kaldimar Jul 21 '16 at 15:33
1

Just place your block under Main content block on content region in Seven theme, It would place your block in bottom of the form, then you could design that with custom css.

Add the /node/*/edit /node/add/* paths in the block visibility field, it would add the block only on the node edit page, else the block will show in all the admin pages.

  • While this alternative works, I prefer Shawn's solution as it blends better with the form. This one would require a subtheme of Seven, or using a contrib module to inject styles in admin theme. – kaldimar Jul 21 '16 at 15:35
  • Yes, But the Shawn's solution also need custom module to edit the form, you could also add css from your custom modules. And also Block would be more user friendly for admin. – Leopathu Jul 21 '16 at 17:45

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.