Custom Field Type hook_field_widget_form() not showing #title values I have created a custom field type. When creating a piece of content with this field type I get a select list and a text area like the image below. However, I have stated that the '#title' for the select list is Label and the textarea is Value.

These '#title''s I've given them do not show up. From looking at other modules that provide a field type that has multiple elements on its widget form seem to be doing it the same way but their titles show up.



function civsearch_property_labels_field_widget_form(&amp;$form, &amp;$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  if (isset($items[$delta]['label'])) {
    $default_label = $items[$delta]['label'];
  }

  if (isset($items[$delta]['value'])) {
    $default_value = $items[$delta]['value'];
  }

  // We are unserializing the variable_get because the string that was
  // serialized with variable_set was a serialized array. So we need to run the
  // unserialize process one more time.
  $options = array();
  $list_items = unserialize(variable_get('civsearch_property_labels', ''));
  foreach ($list_items as $list_item) {
    $explode = explode('|', $list_item);
    $options[$explode[0]] = $explode[1];
  }

  $labels = $element;
  $labels += array(
    '#type' =&gt; 'select',
    '#title' =&gt; t('Label'),
    '#options' =&gt; $options,
    '#default_value' =&gt; isset($default_label) ? $default_label : '',
    '#suffix' =&gt; '&lt;br \&gt;',
  );

  $values = $element;
  $values += array(
    '#type' =&gt; 'textarea',
    '#title' =&gt; t('Value'),
    '#default_value' =&gt; isset($default_value) ? $default_value : '',
  );

  return array(
    'label' =&gt; $labels,
    'value' =&gt; $values,
  );
}
According to hook_field_widget_form() the $element parameter will already have a #title set. If you take a look at the docs for PHP array operators:


  The + operator returns the right-hand array appended to the left-hand array; for keys that exist in both arrays, the elements from the left-hand array will be used, and the matching elements from the right-hand array will be ignored.


Emphasis mine.

So your new #title is currently being ignored.

Try this instead:

$labels = array(
  '#type' =&gt; 'select',
  '#title' =&gt; t('Label'),
  '#options' =&gt; $options,
  '#default_value' =&gt; isset($default_label) ? $default_label : '',
  '#suffix' =&gt; '&lt;br \&gt;',
) + $element;


The example in hook_field_widget_form() might be a bit confusing as it uses an approach similar to your original one, but if you look closely neither of the properties added exist in the list of defaults that $element will contain, so there's no chance of a collision.