view sites/all/modules/rdf_example/rdf_example.install @ 4:ce11bbd8f642

added modules
author danieleb <danielebarchiesi@me.com>
date Thu, 19 Sep 2013 10:38:44 +0100
parents
children
line wrap: on
line source
<?php
// $Id$

/**
 * @file
 * Install file for RDF Example module.
 *
 * To demonstrate hook_rdf_mapping, this module creates it's own node type. For
 * more information on creating node types, see Node Example in the Examples
 * project, http://drupal.org/project/examples.
 */

/**
 * Implements hook_install().
 *
 * - Create photo, summary, nutrition info, serving size, and calorie fields.
 * - Create photo, summary, nutrition info, serving size, and calorie instances.
 */
function rdf_example_install() {
  // use get_t() to get the name of our localization function for translation
  // during install, when t() is not available.
  $t = get_t();

  // Define the node type.
  $rdf_example = array(
    'type' => 'recipe',
    'name' => $t('Recipe'),
    'base' => 'node_content',
    'description' => $t('The recipe node is defined to demonstrate RDF mapping.'),
  );

  // Set additional defaults and save the content type.
  $content_type = node_type_set_defaults($rdf_example);
  node_type_save($content_type);

  // Create all the fields we are adding to our content type.
  // http://api.drupal.org/api/function/field_create_field/7
  foreach (_rdf_example_installed_fields() as $field) {
    field_create_field($field);
  }

  // Create all the instances for our fields.
  // http://api.drupal.org/api/function/field_create_instance/7
  foreach (_rdf_example_installed_instances() as $bundle_name => $bundle) {
    foreach ($bundle as $instance) {
      $instance['entity_type'] = $bundle_name == 'recipe' ? 'node' : 'field_collection_item';
      $instance['bundle'] = $bundle_name;
      field_create_instance($instance);
    }
  }
}

/**
 * Return a structured array defining the fields created by this content type.
 */
function _rdf_example_installed_fields() {
  $t = get_t();
  $return = array(
    'recipe_photo' => array(
      'field_name' => 'recipe_photo',
      'cardinality' => 1,
      'type'        => 'image',
    ),
    'recipe_summary' => array(
      'field_name'  => 'recipe_summary',
      'cardinality' => 1,
      'type'        => 'text',
      'settings'    => array(
        'max_length' => 500,
      ),
    ),
    'recipe_nutrition' => array(
      'field_name'  => 'recipe_nutrition',
      'cardinality' => 1,
      'type'        => 'field_collection',
    ),
    'recipe_serving_size' => array(
      'field_name'  => 'recipe_serving_size',
      'cardinality' => 1,
      'type'        => 'text',
    ),
    'recipe_calories' => array(
      'field_name'  => 'recipe_calories',
      'cardinality' => 1,
      'type'        => 'number_integer',
    ),
  );

  return $return;
}

/**
 * Return a structured array defining the instances for this content type and
 * related field collections.
 */
function _rdf_example_installed_instances() {
  $t = get_t();
  $instances = array();
  $instances['recipe'] = array(
    'recipe_photo' => array(
      'field_name'  => 'recipe_photo',
      'label'       => $t('Photo of the prepared dish'),
    ),
    'recipe_summary' => array(
      'field_name' => 'recipe_summary',
      'label'       => $t('Short summary describing the dish'),
      'widget'      => array(
        'type'    => 'text_textarea',
      ),
    ),
    'recipe_nutrition' => array(
      'field_name' => 'recipe_nutrition',
      'label'      => $t('Recipe Nutrition Information'),
    ),
  );
  // We attach some fields directly to the field collections. The field
  // collection bundles are created automatically with the field definition.
  $instances['recipe_nutrition'] = array(
    'recipe_serving_size' => array(
      'field_name' => 'recipe_serving_size',
      'label'       => $t('Serving size'),
    ),
    'recipe_calories' => array(
      'field_name' => 'recipe_calories',
      'label'       => $t('Calories'),
    )
  );

  return $instances;
}