4

I have this problem, I'm creating a content type by creating a module, using the example 'node_example' of examples project as a code template. The thing is that I get it work, I create the content type successfully but when I create a new node of that content type, all fields appear but the title. I'm a little lost. I put by myself the propperty 'has_title' to true on hook_node_info() but it stays the same. Cleared drupal caches several times, removed previous nodes, nothing. Any idea? Thanks.

(Maybe I don't follow all the standards, I'm quite a begginer and I try to follow them as possible) Module name: ct_conversacion. Content type: conversacion.

-------------edit:

Ok, it was tough but I found the solution. The function 'ct_conversacion_form' that I wrote below should be 'conversacion_form' (the content type name preceding).

My code:

  /**
   * Implements hook_node_info().
   */

      function ct_conversacion_node_info() { 

        return array(
          'conversacion' => array(       
        'name' => t('Conversacion'),   
        'base' => 'conversacion',    
        'description' => t('Es una conversacion.'),  
        'has_title' => TRUE,
        'title_label' => t('Title'),
        'locked' => TRUE,
      ),
    );
  }

  /**
   * Implement hook_form().
   */
  function ct_conversacion_form($node, $form_state) {
    return node_content_form($node, $form_state);
  }


  /**
   * Implements hook_node_type_insert(). 
   */

  function ct_conversacion_node_type_insert($content_type) {
    if ($content_type->type == 'conversacion') {  

      $body_instance = node_add_body_field($content_type, t('Mi descripcion')); 

      field_update_instance($body_instance);

      foreach (_conversacion_installed_fields() as $field) {
        field_create_field($field);
      }

      foreach (_conversacion_installed_instances() as $instance) { 
        $instance['entity_type'] = 'node';
        $instance['bundle'] = 'conversacion'; 
        field_create_instance($instance);
      }
    }
  }

  /**
   * Define the fields for our content type.
   *
   */
  function _conversacion_installed_fields() { // Cambiar *****
    return array(
      'conversacion_field2' => array(
        'field_name' => 'conversacion_field2',
        'cardinality' => 3,
        'type'        => 'text',
        'settings'    => array(
          'max_length' => 60,
        ),
      ),
    );
  }

  /**
   * Define the field instances for our content type.
   */

  function _conversacion_installed_instances() {
    return array(
      'conversacion_field2' => array(
        'field_name' => 'conversacion_field2',
        'label'       => t('Field 2 de Conversacion.'),
        'widget'      => array(
          'type'    => 'text_textfield',
        ),
      ),
    );
  }

1 Answer 1

1

the error is obviously because you use a wrong base

change it to 'ct_conversacion'

see https://api.drupal.org/api/drupal/modules%21node%21node.module/function/node_type_save/7

base: A string that indicates the base string for hook functions. For example, 'node_content' is the value used by the UI when creating a new node type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.