You are here

function _node_example_installed_instances in Examples for Developers 7

Define the field instances for our content type.

The instance lets Drupal know which widget to use to allow the user to enter data and how to react in different view modes. We are going to display a page that uses a custom "node_example_list" view mode. We will set a cardinality of three allowing our content type to give the user three color fields.

This big array is factored into this function for readability.

Return value

array An associative array specifying the instances we wish to add to our new node type.

Related topics

2 calls to _node_example_installed_instances()
NodeExampleTestCase::testInstallationApi in node_example/node_example.test
API-level content type test.
node_example_node_type_insert in node_example/node_example.module
Implements hook_node_type_insert().

File

node_example/node_example.module, line 328
Module file for Node Example module.

Code

function _node_example_installed_instances() {
  return array(
    'node_example_color' => array(
      'field_name' => 'node_example_color',
      'label' => t('The colors available for this object.'),
      'widget' => array(
        'type' => 'text_textfield',
      ),
      'display' => array(
        'example_node_list' => array(
          'label' => 'hidden',
          'type' => 'node_example_colors',
        ),
      ),
    ),
    'node_example_quantity' => array(
      'field_name' => 'node_example_quantity',
      'label' => t('Quantity required'),
      'type' => 'text',
      'widget' => array(
        'type' => 'text_textfield',
      ),
      'display' => array(
        'example_node_list' => array(
          'label' => 'hidden',
          'type' => 'hidden',
        ),
      ),
    ),
    'node_example_image' => array(
      'field_name' => 'node_example_image',
      'label' => t('Upload an image:'),
      'required' => FALSE,
      'widget' => array(
        'type' => 'image_image',
        'weight' => 2.1,
      ),
      'display' => array(
        'example_node_list' => array(
          'label' => 'hidden',
          'type' => 'image_link_content__thumbnail',
        ),
      ),
    ),
  );
}