0

I have a group in a node set as a vertical tab, and I want to add some markup into this vertical tab via code. How can I do it?

Thanks!

1
  • What are the steps you did for this ? Any approch you follow?
    – Rupesh
    Commented Apr 6, 2014 at 16:52

2 Answers 2

1

Let's say that you are doing this in a module named custom.

First, take a look at how the form is structured using dsm($form) in custom.module. Make sure you have the devel module enabled and that you have permissions to see devel's output.

<?php

custom_form_alter(&$form, &$form_state, $form_id) {
  dsm($form);
}

That will give you the structure of the $form array, which you can then add your markup to. So, let's say that you want to add some markup to the author pane in the vertical tabs. From the output from dsm($form), we see that we are working with $form['author'].

So, in custom_form_alter(), we simply add the markup element we desire using the standards documented in the Drupal 7 Form API.

In the code below, I also give the custom element (which I have aptly named "custom") a weight, so it appears above the other elements.

/**
 * Implements hook_form_alter().
 */
function custom_form_alter(&$form, $form_state, $form_id) {
  // Add custom markup to the "Authoring Information" tab when adding or editing a page.
  if ($form_id == 'page_node_form') {
    $form['author']['custom']['#markup'] = 'Text goes here';
    $form['author']['custom']['#weight'] = -9;
  }
}

Also, rather than using an if statement to target the form id, I could have used hook_form_FORM_ID_alter(), like this:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function custom_form_page_node_form_alter(&$form, $form_state, $form_id) {
  // Add custom markup to the "Authoring Information" tab when adding or editing a page.
  $form['author']['custom']['#markup'] = 'Text goes here';
  $form['author']['custom']['#weight'] = -9;
}
0

Actually I found a solution:

$form['markup'] = array(
  '#markup' => '<div>markup</div>',
);
$form['#group_children']['markup'] = 'group_NAME';

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.