2012-04-24 2 views
1

私はプログラマチックにDrupal 7モジュールでカスタムコンテンツタイプを作成しています。私は例を辿ったが、インストール後何らかの理由でコンテンツタイプがコンテンツタイプリストの下に表示されず、コースタイプのコンテンツを作成するときにタイトルを入力する場所がない。Drupal 7のカスタムコンテンツタイプ - 私のタイトルはどこですか?

私は間違っていますか?ここで

は私のcourse.installファイルです:

<?php 
function course_schema() 
{ 
    $schema['course_status'] = array('description' => t('Stores user specific course status information.'), 
            'fields'  => array('id'   => array('description' => t('The primary identifier'), 
                        'type'  => 'serial', 
                        'unsigned' => TRUE, 
                        'not null' => TRUE), 
                  'uid'   => array('description' => t('The user identifier.'), 
                        'type'  => 'int', 
                        'unsigned' => TRUE, 
                        'not null' => TRUE, 
                        'default'  => 0), 
                  'nid'   => array('description' => t('The node identifier.'), 
                        'type'  => 'int', 
                        'unsigned' => TRUE, 
                        'not null' => TRUE, 
                        'default'  => 0), 
                  'visits'  => array('description' => t('The visit count.'), 
                        'type'  => 'int', 
                        'unsigned' => TRUE, 
                        'not null' => TRUE, 
                        'default'  => 0), 
                  'is_completed' => array('description' => t('The completion flag.'), 
                        'type'  => 'int', 
                        'unsigned' => TRUE, 
                        'not null' => TRUE, 
                        'default'  => 0), 
                  'completed_at' => array('description' => t('The completion date, as a timestamp.'), 
                        'type'  => 'int', 
                        'default'  => NULL)), 
            'primary key' => array('id')); 

    return $schema; 
} 

function course_install() 
{ 
    // During installation, the t() function is unavailable, so we use get_t() 
    // to store the name of the translation function. 
    $t = get_t(); 

    // We define the node type as an associative array. 
    $course = array('type'  => 'course', 
        'name'  => $t('Course'), 
     // 'base' tells Drupal the base string for hook functions. 
     // This is often the module name; if base is set to 'mymodule', Drupal 
     // would call mymodule_insert() or similar for node hooks. 
     // In this case, we set base equal to 'node_content' so Drupal will handle 
     // our node as if we had designed it in the UI. 
        'base'  => 'node_content', 
        'description' => $t('This is a course node.'), 
        'title_label' => $t('Title'), 
        'custom'  => TRUE,); 

    // 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($course); 

    //Course blocks have an image, and body. 
    node_add_body_field($content_type, $t('Description')); 

    // Save the content type 
    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(_course_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(_course_installed_instances() as $instance) 
    { 
     $instance['entity_type'] = 'node'; 
     $instance['bundle']  = $course['type']; 
     field_create_instance($instance); 
    } 

    //Don't show submitted info on course nodes 
// variable_set('node_submitted_course', 0); 
} 

/** 
* Returns a structured array defining the fields created by this content type. 
* This is factored into this function so it can be used in both 
* node_example_install() and node_example_uninstall(). 
* @return 
*   An associative array specifying the fields we wish to add to our 
*   new node type. 
* @ingroup node_example 
*/ 
function _course_installed_fields() 
{ 
    $t = get_t(); 
    return array('course_image'   => array('field_name' => 'course_image', 
               'type'  => 'image', 
               'cardinality' => 1,), 
       'course_curriculum_id' => array('field_name'  => 'course_curriculum_id', 
               'type'    => 'number_integer', 
               'settings'   => array('max_length' => 9), 
               'cardinality'  => 1,)); 
} 

/** 
* Returns 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. 
* This is factored into this function so it can be used in both 
* node_example_install() and node_example_uninstall(). 
* @return 
*   An associative array specifying the instances we wish to add to our new 
*   node type. 
* @ingroup node_example 
*/ 
function _course_installed_instances() 
{ 
    $t = get_t(); 
    return array('course_image'   => array('field_name' => 'course_image', 
               'label'  => $t('Image:'), 
               'required' => FALSE, 
               'widget'  => array('type' => 'image_image', 
                     'weight' => 2.10), 
               'display'  => array('course_list' => array('label' => 'hidden', 
                           'type' => 'image_link_content__thumbnail',))), 
       'course_curriculum_id' => array('field_name' => 'course_curriculum_id', 
               'label'  => $t('Curriculum Id') . ':', 
               'required' => TRUE, 
               'widget'  => array('type'    => 'text_textfield'), 
               'settings' => array('text_processing' => 0), 
               'display'  => array('course_list' => array('label' => 'hidden', 
                           'type' => 'hidden')))); 
} 

function course_uninstall() 
{ 
    // Drop my tables. 
    drupal_uninstall_schema('course'); 

    //remove any nodes of the type course 
    $sql = 'SELECT nid FROM {node} n WHERE n.type = :type'; 
    $result = db_query($sql, array(':type' => 'course')); 
    $nids = array(); 
    foreach($result as $row) 
    { 
     $nids[] = $row->nid; 
    } 

    // Delete all the nodes at once 
    node_delete_multiple($nids); 

    //remove the content type 
    node_type_delete('course'); 

    //and their associated fields 
    foreach(_course_installed_fields() as $field) 
    { 
     field_delete_field($field['field_name']); 
    } 
} 

?> 

そして私はcourse.moduleでこれを持っている:

<?php 
function course_node_info() 
{ 
    return array('course' => array('name'  => t('Course'), 
            'base'  => 'course', 
            'description' => t('A course content type'), 
            'has_title' => TRUE, 
            'title_label' => t('Title'), 
            'locked'  => FALSE,),); 
} 
?> 

を解決し、両方の問題に対する解決策は、これを追加することです判明しますコースモジュール:

function course_form($node, $form_state) 
{ 
return node_content_form($node, $form_state); 
} 

答えて

2

は、両方の問題に対する解決策がcourse.moduleにこれを追加することですが判明:

function course_form($node, $form_state) 
{ 
    return node_content_form($node, $form_state); 
} 
0

私はちょうど誰もが私が持っていた問題に遭遇した場合にはさておき、この問題に追加したいです。

カスタムタイプのノードを作成するときにノードフォームが表示されない場合は、小さなタイプのものを探します。ノードタイプのマシン名と異なる名前を使用していますか?ノードタイプのマシン名またはモジュール名を使用して、あなたのノードタイプのhook_form()の名前?

私はnovel_sectionと呼ばれるノード型を作成するモジュールという名前の小説を持っています。新しいnovel_sectionタイプのフォームが本文フィールドやタイトルフィールドを表示しない理由と、カスタムモジュールを使用してカスタムノードタイプを作成する方法についてオンラインでポストを読んだ後に約6時間後に、私はついにそれを実現しました私のhook_form()はnovel_formation()の代わりにnovel_form()と呼ばれていたためです(他のモジュール関数の名前と同じです)。このオンライン

すべての例では、あなたのモジュール名は、お使いのノードタイプのマシン名と同じで、それは常に念はない仮定を作っています。さらに、hook_form()は、モジュール名が何であっても、ノード型のマシン名を使用する必要があると誰も言及していません。

私のように、あなただけのノードタイプを作成するよりもはるかに多くの処理を行い、または複数のノードタイプを作成し、表示するタイトルおよび/または体を得ることができない理由を把握することはできませんモジュールを持ち、場合新しいノードタイプの新しいノードフォームでは、これが役立ちます。

関連する問題