Note that there are some explanatory texts on larger screens.

plurals
  1. POBetter way for theming node_form
    text
    copied!<p>I've a module where I defined content type. Let's assume I have only <code>title</code> and <code>body</code> fields in it.</p> <p>When node form renders it has standard <code>title (textfield)</code> and <code>body (textarea)</code>.</p> <p>I want to wrap this two fields into <code>fieldset</code>.</p> <p>This is how I achieve this, however I don't feel that it's the best way.</p> <pre class="lang-php prettyprint-override"><code>/** * Implements hook_form(). */ function hook_form($node, $form_state) { return node_content_form($node, $form_state); } /** * Implements hook_form_FORM_ID_alter(). */ function hook_form_node_form_alter(&amp;$form, &amp;$form_state, $form_id) { if ($form_id == 'content_type_name_node_form') { $form['info'] = array( '#type' =&gt; 'fieldset', '#title' =&gt; t('Describe your content') ); $form['info']['title'] = $form['title']; unset($form['title']); $form['info']['body'] = $form['body']; unset($form['body']); } } </code></pre> <p>Any suggestions of how to make it better?</p> <p><strong>UPDATE</strong></p> <p>Another variant which I think of. It's pretty much the same, just a bit improved.</p> <pre><code>/** * Implements hook_form_FORM_ID_alter(). */ function hook_form_node_form_alter(&amp;$form, &amp;$form_state, $form_id) { if ($form_id == 'content_type_name_node_form') { $groups = array( 'info' =&gt; array( 'title' =&gt; t('Describe your content'), 'fields' =&gt; array('title', 'body') ) ); foreach ($groups as $key =&gt; $group) { $form[$key] = array( '#type' =&gt; 'fieldset', '#title' =&gt; $group['title'] ); foreach ($group['fields'] as $field) { $form[$key][$field] = $form[$field]; unset($form[$field]); } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload