Skip to main content
knackforge blog knowledge base

Display a custom content type's field in 'Manage fields' page

Recently I had a requirement to create a custom content type. I was no new to this as I had previous such encounters. Post creation of this content type I noticed that the fields were misplaced while creating a node from the same. At first glance it looked a cakewalk shot as we are aware about the default configuration.
 
Considering the same, I traced to Structure->Content Type->Manage Fields(for my custom content type) to change the order of the fields. Strange to witness, my fields was not present in content type's Manage field page! I was taken aback in astonishment to note such a thing, as this field was visible in node creation form and not in manage field form.
 
Then came my Team Lead Sivaji to put a helping hand, who then shared information about hook_field_extra_fields(). Without this hook my requirement to change the order would have taken days to complete, thanks to Drupal for having such a powerful hook.
 
  1. **
  2.  * Implements hook_field_extra_fields().
  3.  */
  4. function hook_field_extra_fields() {
  5.   $extra['node']['node_type'] = array(
  6.     'form' => array(
  7.       'field1' => array(
  8.         'label' => t('Field1 name'),
  9.         'description' => t('Description about field1'),
  10.         'weight' => -4,
  11.       ),
  12.       'field2' => array(
  13.         'label' => t('Field2 name'),
  14.         'description' => t('Description about field2'),
  15.         'weight' => -5,
  16.       )
  17.     ),
  18.   );
  19.   return $extra;
  20. }
 
In the above code replace the hook with your module's name. '$extra' returns the additional configurations related to your node's fields. So replace node_type with the machine name of your node.
 
Replace field1 and field2 with your fields, which you want to make drag-gable in the 'manage fields' page of your content type. Once done reload the 'manage fields' page of your content type, there the presence of these fields can be noticed.
 
Hope this helps someone, as it did to me.