? examples.node_example_broken_755640_17.patch
? node_example.patch
Index: node_example/node_example.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/examples/node_example/node_example.install,v
retrieving revision 1.9
diff -u -p -r1.9 node_example.install
--- node_example/node_example.install	13 Sep 2010 15:42:35 -0000	1.9
+++ node_example/node_example.install	19 Sep 2010 16:37:29 -0000
@@ -3,44 +3,53 @@
 
 /**
  * @file
- * Install file for Node Example module.
- *
- * The definition of the fields for the module is here, although
- * node_example_node_info() provides the actual content type definition.
- *
- * See @link http://drupal.org/node/707832 Field API Tutorial @endlink
- *
- * See @link http://drupal.org/node/443536 Field API Handbook Page @endlink
- *
- * See @link field Field API documentation @endlink
+ * install file for Node Example module.
  *
+ * Most of the definition of the node type is in this module.
  */
 
 /**
  * Implements hook_install().
  *
- * - Add the body field.
- * - Configure the body field.
- * - 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']);
+  // get the name of our localization function for translation during install
+  // http://api.drupal.org/api/function/get_t/7
+  $t = get_t();
 
-  // Load the instance definition for our content type's body
+  // Define the node type.  This is similar to hook_node_info() in Drupal 6
+  $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 types body
   // http://api.drupal.org/api/function/field_info_instance/7
   $body_instance = field_info_instance('node', 'body', 'node_example');
 
   // 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
@@ -48,26 +57,27 @@ function node_example_install() {
 
   // Create all the fields we are adding to our content type.
   // http://api.drupal.org/api/function/field_create_field/7
-  foreach (_node_example_installed_fields() as $field) {
+  foreach (node_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 (_node_example_installed_instances() as $instance) {
+  foreach (node_example_installed_instances() as $instance) {
     $instance['entity_type'] = 'node';
-    $instance['bundle'] = 'node_example';
+    $instance['bundle'] = $node_example['type'];
     field_create_instance($instance);
   }
 }
 
 /**
- * Return a structured array defining the fields created by this content type.
+ * All fields created by this content type.  The field is the default definition
+ * that lets Drupal know that a field exists.
  *
- * This is packaged in a function so it can be used in both hook_install()
+ * This is inside its own function so that it can be used in both hook_install()
  * and hook_uninstall().
  */
-function _node_example_installed_fields() {
+function node_example_installed_fields() {
   $t = get_t();
   return array(
     'node_example_color' => array(
@@ -92,18 +102,16 @@ function _node_example_installed_fields(
 }
 
 /**
- * Return a structured array defining the instances for this 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.
+ * All instances created by this 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 to enter data into.
  *
- * This is provided as a function so that it can be used in both hook_install()
+ * This is inside its own function so that it can be used in both hook_install()
  * and hook_uninstall().
  */
-function _node_example_installed_instances() {
+function node_example_installed_instances() {
   $t = get_t();
   return array(
     'node_example_color' => array(
@@ -174,7 +182,7 @@ function node_example_uninstall() {
   // Loop over each of the fields defined by this module and delete
   // all instances of the field, their data, and the field itself.
   // http://api.drupal.org/api/function/field_delete_field/7
-  foreach (array_keys(_node_example_installed_fields()) as $field) {
+  foreach (array_keys(node_example_installed_fields()) as $field) {
     field_delete_field($field);
   }
 
Index: node_example/node_example.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/examples/node_example/node_example.module,v
retrieving revision 1.6
diff -u -p -r1.6 node_example.module
--- node_example/node_example.module	26 Jun 2010 00:01:34 -0000	1.6
+++ node_example/node_example.module	19 Sep 2010 16:37:29 -0000
@@ -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,43 +16,14 @@
  * 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 external database table to store this content types
+ * information.
  *
- * Most node types that provide fields do not require any custom code for
- * the fields, as the fields system provides storage and access.
- *
- * See @link http://drupal.org/node/707832 Field API Tutorial @endlink
- *
- * See @link http://drupal.org/node/443536 Field API Handbook Page @endlink
- *
- * 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 fields.
  */
 
 /**
- * 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().
  *
  * We are providing a default page to illustrate the use of our custom node view
Index: simpletest_example/simpletest_example.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/examples/simpletest_example/simpletest_example.install,v
retrieving revision 1.2
diff -u -p -r1.2 simpletest_example.install
--- simpletest_example/simpletest_example.install	7 May 2010 01:28:57 -0000	1.2
+++ simpletest_example/simpletest_example.install	19 Sep 2010 16:37:29 -0000
@@ -10,7 +10,7 @@
  * Implements hook_install().
  */
 function simpletest_example_install() {
-  // Ensure the simpletest_example node type is available.
+  // Ensure the blog node type is available.
   node_types_rebuild();
   $types = node_type_get_types();
   node_add_body_field($types['simpletest_example']);
Index: simpletest_example/simpletest_example.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/examples/simpletest_example/simpletest_example.module,v
retrieving revision 1.4
diff -u -p -r1.4 simpletest_example.module
--- simpletest_example/simpletest_example.module	13 Sep 2010 23:51:48 -0000	1.4
+++ simpletest_example/simpletest_example.module	19 Sep 2010 16:37:29 -0000
@@ -71,7 +71,22 @@ function simpletest_example_node_access(
  * Form for the node type.
  */
 function simpletest_example_form($node, $form_state) {
-  return node_content_form($node, $form_state);
+  $type = node_type_get_type($node);
+
+  $form = array();
+
+  if ($type->has_title) {
+    $form['title'] = array(
+      '#type' => 'textfield',
+      '#title' => check_plain($type->title_label),
+      '#required' => TRUE,
+      '#default_value' => $node->title,
+      '#maxlength' => 255,
+      '#weight' => -5,
+    );
+  }
+
+  return $form;
 }
 
 
