summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRandy Fay2010-10-15 14:52:26 (GMT)
committer Randy Fay2010-10-15 14:52:26 (GMT)
commitf0d7bf61b0e9f81fae423a04f3017783622233f0 (patch)
treec273c7ac68d9e1bdf0cc034d146877654415504f
parent2241fb52afac2d3663457cd1ff12d866adcfd195 (diff)
#755640-34 by chx, rfay with #35: Move appropriate node creation elements back into the .install file.
-rw-r--r--node_example/CHANGELOG.txt4
-rwxr-xr-xnode_example/node_example.install37
-rwxr-xr-xnode_example/node_example.module31
3 files changed, 37 insertions, 35 deletions
diff --git a/node_example/CHANGELOG.txt b/node_example/CHANGELOG.txt
deleted file mode 100644
index 58f3658..0000000
--- a/node_example/CHANGELOG.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-# $Id$
-
-#508342 by cyberswat, ilo, torelad, rfay | jhodgdon, c960657, Crell:
- node example D7 version. \ No newline at end of file
diff --git a/node_example/node_example.install b/node_example/node_example.install
index c069480..99d90cf 100755
--- a/node_example/node_example.install
+++ b/node_example/node_example.install
@@ -24,15 +24,35 @@
* - Create color, quantity, and image fields.
* - Create color, quantity, and image instances.
*
+ * @see node_type_set_defaults()
* @see field_info_instance()
* @see field_update_instance()
* @see field_create_field()
* @see field_create_instance()
*/
function node_example_install() {
- node_types_rebuild();
- $types = node_type_get_types();
- node_add_body_field($types['node_example']);
+ // 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.
+ $node_example = array(
+ 'type' => 'node_example',
+ 'name' => $t('Example Node'),
+ 'base' => 'node_content',
+ 'description' => $t('This is an example node type with a few fields.'),
+ 'body_label' => $t('Example Description')
+ );
+
+ // Complete the node type definition by setting any defaults not explicitly
+ // declared above.
+ // http://api.drupal.org/api/function/node_type_set_defaults/7
+ $content_type = node_type_set_defaults($node_example);
+ node_add_body_field($content_type);
+
+ // Save the content type
+ node_type_save($content_type);
+
// Load the instance definition for our content type's body
// http://api.drupal.org/api/function/field_info_instance/7
@@ -40,7 +60,10 @@ function node_example_install() {
// Add our example_node_list view mode to the body instance display by
// instructing the body to display as a summary
- $body_instance['type'] = 'text_summary_or_trimmed';
+ $body_instance['display']['example_node_list'] = array(
+ 'label' => 'hidden',
+ 'type' => 'text_summary_or_trimmed',
+ );
// Save our changes to the body field instance.
// http://api.drupal.org/api/function/field_update_instance/7
@@ -56,7 +79,7 @@ function node_example_install() {
// http://api.drupal.org/api/function/field_create_instance/7
foreach (_node_example_installed_instances() as $instance) {
$instance['entity_type'] = 'node';
- $instance['bundle'] = 'node_example';
+ $instance['bundle'] = $node_example['type'];
field_create_instance($instance);
}
}
@@ -64,8 +87,8 @@ function node_example_install() {
/**
* Return a structured array defining the fields created by this content type.
*
- * This is packaged in a function so it can be used in both hook_install()
- * and hook_uninstall().
+ * This is packaged in a function so it can be used in both
+ * node_example_install() and node_example_uninstall().
*/
function _node_example_installed_fields() {
$t = get_t();
diff --git a/node_example/node_example.module b/node_example/node_example.module
index 260d92c..ac03edc 100755
--- a/node_example/node_example.module
+++ b/node_example/node_example.module
@@ -3,8 +3,8 @@
/**
* @file
- * This example shows how a module can define a new
- * node type. In Drupal 7 we move much of what was once needed in this file
+ * This is an example outlining how a module can be used to define a new
+ * node type. In Drupal 7 we move most of what was once needed in this file
* to the node_example.install file so that it can be managed efficiently.
*
* Our example node type will allow users to specify multiple "colors",
@@ -16,8 +16,8 @@
* return it's data. This module declares a custom view mode called
* "example_node_list".
*
- * We no longer need an extra per-module database table to store this content
- * type's information.
+ * We no longer need an extra database table to store this content type's
+ * information.
*
* Most node types that provide fields do not require any custom code for
* the fields, as the fields system provides storage and access.
@@ -29,28 +29,11 @@
* See @link field Field API documentation @endlink
*
* See @link field_example.install field_example.install @endlink
+ *
+ * Remember that most node types do not require any custom code, as one
+ * simply creates them using the fields UI.
*/
-/**
- * Implements hook_node_info() to provide our node_example type.
- */
-function node_example_node_info() {
- return array(
- 'node_example' => array(
- 'name' => t('Example Node'),
- 'base' => 'node_example',
- 'description' => t('This is an example node type with a few fields.'),
- 'has_title' => TRUE,
- ),
- );
-}
-
-/**
- * Implement hook_form() with the standard default form.
- */
-function node_example_form($node, $form_state) {
- return node_content_form($node, $form_state);
-}
/**
* Implements hook_menu().