function hook_content_register_content_type

6.x content.api.php hook_content_register_content_type()
4.x content.module hook_content_register_content_type()
5.x content.module hook_content_register_content_type()

Sample hook other modules implement to register a content type.

Simply return an array as illustrated below to register your module's content types.

IMPORTNAT: The type's machine name must be a valid variable name. No spaces or symbols.

Notice that the fields are set up much as you would set up a form using the normal form api.

The content module assumes that a database table has already been created, where every field name begins with field__

Also, the table itself should be named content__typename.

See also

the Alert module, and its install file.

5 functions implement hook_content_register_content_type()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

alerts_content_register_content_type in modules/alerts/alerts.module
For use with the content module. We will register our custom content type(s) for use with this module.
announcements_content_register_content_type in modules/announcements/announcements.module
Implementatin of content's hook_content_register_content_type
calendar_content_register_content_type in modules/calendar/calendar.module
For use with the content module. We will register our custom content type(s) for use with this module.
content_content_register_content_type in modules/content/content.module
Implementation of this module's hook_content_register_content_type.
engagements_content_register_content_type in modules/engagements/engagements.module
For use with the content module. We will register our custom content type(s) for use with this module.

File

modules/content/content.api.php, line 29

Code

function hook_content_register_content_type() {

  // Example is from the Alert module.

  $arr ['alert'] = array(
    'title' => 'Alert',
    'description' => 'Signal an alert, notification, or issue to be resolved for a student.',
    'settings' => array(
      'title' => array(
        'label' => t('Title / Short Description'),
        'weight' => 15,
      ),
    ),
  );


  // If we are in a popup (dialog)...
  if (@$_GET ['window_mode'] == 'popup') {
    // We want to make sure we redirect to our handler URL, which will close the dialog.
    $arr ['alert']['settings']['#redirect'] = array(
      'path' => 'content-dialog-handle-after-save',
      'query' => '',
    );
  }


  $fields = array();

  $fields ['student_id'] = array(
    'type' => 'textfield',
    'label' => 'Student',
    'weight' => 10,
  );


  $fields ['alert_status'] = array(
    'type' => 'select',
    'label' => 'Status',
    'options' => array(
      'open' => t('Open'),
      'closed' => t('Closed'),
    ),
    'required' => TRUE,
    'hide_please_select' => TRUE,
    'weight' => 40,
  );


  $fields ['department'] = array(
    'type' => 'select',
    'label' => 'Department',
    'hide_please_select' => TRUE,
    'options' => array(
      'default' => t("Default/None"),
      'finaid' => t('Financial Aid'),
      'reg' => t('Registrar'),
      'stu_aff' => t('Student Affairs'),
    ),
    'weight' => 60,
  );


  $fields ['alert_msg'] = array(
    'type' => 'textarea_editor',
    'label' => 'Message',
    'filter' => 'basic',
    'weight' => 70,
  );



  $fields ['visibility'] = array(
    'type' => 'radios',
    'label' => 'Visible to:',
    'options' => array('public' => 'Anyone (incl. student)', 'faculty' => 'Faculty/Staff only'),
    'weight' => 80,
  );

  $arr ['alert']['fields'] = $fields;



  return $arr;
}