comparison 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
comparison
equal deleted inserted replaced
3:b28be78d8160 4:ce11bbd8f642
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Install file for RDF Example module.
7 *
8 * To demonstrate hook_rdf_mapping, this module creates it's own node type. For
9 * more information on creating node types, see Node Example in the Examples
10 * project, http://drupal.org/project/examples.
11 */
12
13 /**
14 * Implements hook_install().
15 *
16 * - Create photo, summary, nutrition info, serving size, and calorie fields.
17 * - Create photo, summary, nutrition info, serving size, and calorie instances.
18 */
19 function rdf_example_install() {
20 // use get_t() to get the name of our localization function for translation
21 // during install, when t() is not available.
22 $t = get_t();
23
24 // Define the node type.
25 $rdf_example = array(
26 'type' => 'recipe',
27 'name' => $t('Recipe'),
28 'base' => 'node_content',
29 'description' => $t('The recipe node is defined to demonstrate RDF mapping.'),
30 );
31
32 // Set additional defaults and save the content type.
33 $content_type = node_type_set_defaults($rdf_example);
34 node_type_save($content_type);
35
36 // Create all the fields we are adding to our content type.
37 // http://api.drupal.org/api/function/field_create_field/7
38 foreach (_rdf_example_installed_fields() as $field) {
39 field_create_field($field);
40 }
41
42 // Create all the instances for our fields.
43 // http://api.drupal.org/api/function/field_create_instance/7
44 foreach (_rdf_example_installed_instances() as $bundle_name => $bundle) {
45 foreach ($bundle as $instance) {
46 $instance['entity_type'] = $bundle_name == 'recipe' ? 'node' : 'field_collection_item';
47 $instance['bundle'] = $bundle_name;
48 field_create_instance($instance);
49 }
50 }
51 }
52
53 /**
54 * Return a structured array defining the fields created by this content type.
55 */
56 function _rdf_example_installed_fields() {
57 $t = get_t();
58 $return = array(
59 'recipe_photo' => array(
60 'field_name' => 'recipe_photo',
61 'cardinality' => 1,
62 'type' => 'image',
63 ),
64 'recipe_summary' => array(
65 'field_name' => 'recipe_summary',
66 'cardinality' => 1,
67 'type' => 'text',
68 'settings' => array(
69 'max_length' => 500,
70 ),
71 ),
72 'recipe_nutrition' => array(
73 'field_name' => 'recipe_nutrition',
74 'cardinality' => 1,
75 'type' => 'field_collection',
76 ),
77 'recipe_serving_size' => array(
78 'field_name' => 'recipe_serving_size',
79 'cardinality' => 1,
80 'type' => 'text',
81 ),
82 'recipe_calories' => array(
83 'field_name' => 'recipe_calories',
84 'cardinality' => 1,
85 'type' => 'number_integer',
86 ),
87 );
88
89 return $return;
90 }
91
92 /**
93 * Return a structured array defining the instances for this content type and
94 * related field collections.
95 */
96 function _rdf_example_installed_instances() {
97 $t = get_t();
98 $instances = array();
99 $instances['recipe'] = array(
100 'recipe_photo' => array(
101 'field_name' => 'recipe_photo',
102 'label' => $t('Photo of the prepared dish'),
103 ),
104 'recipe_summary' => array(
105 'field_name' => 'recipe_summary',
106 'label' => $t('Short summary describing the dish'),
107 'widget' => array(
108 'type' => 'text_textarea',
109 ),
110 ),
111 'recipe_nutrition' => array(
112 'field_name' => 'recipe_nutrition',
113 'label' => $t('Recipe Nutrition Information'),
114 ),
115 );
116 // We attach some fields directly to the field collections. The field
117 // collection bundles are created automatically with the field definition.
118 $instances['recipe_nutrition'] = array(
119 'recipe_serving_size' => array(
120 'field_name' => 'recipe_serving_size',
121 'label' => $t('Serving size'),
122 ),
123 'recipe_calories' => array(
124 'field_name' => 'recipe_calories',
125 'label' => $t('Calories'),
126 )
127 );
128
129 return $instances;
130 }