English 中文(简体)
第7博士中的习俗内容类型——我的头衔在哪里?
原标题:Custom Content Type in Drupal 7 - Where s my Title?

I m programally establishing atom content category in a Drupal 7 model. 我先看这些例子,但出于某种原因,在安装后,内容类别清单中显示的内容类型为吨数,在设定类型课程内容时,没有发现进入所有权。

我做了什么错误?

Here s my course.install file:

<?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 ]);
    }
}

?>

我当然也这样做。 模块:

<?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,),);
}
?>

Solved Turns out the solution to both issues is to add this to course.module:

function course_form($node, $form_state)
{
return node_content_form($node, $form_state);
}
最佳回答

解决这两个问题的办法当然是增加这一点。 模块:

function course_form($node, $form_state)
{
    return node_content_form($node, $form_state);
}
问题回答

我只想在任何人卷入我前面的问题时,再补充这个问题。

如果你在制造你习惯型号时难以展示出 no,看一小点:你是否使用与你的单元名称不同的名称作为你的机器名称,你是否使用你的帽子,用你的机器名称或模块名称来为贵重型号。

I have a module named novel which creates a node type called novel_section. After about 6 hours of trying to figure out why the form for a new novel_section type wasn t displaying the body or title fields and after reading post after post online about how to create a custom node type with a custom module, I finally realized it was because my hook_form() was called novel_form() (like you would name any other module function) instead of novel_section_form().

网上所有例子都假设,你的模块名称与你的机器名称相同,而且情况并不总是如此。 此外,没有任何人提到“照像”需要使用你的机器名称,而不论单元名称为何。

如果像我一样,你有一个模块,其作用远不止是制造一种 no子或制造多种 no,你可以说明,为什么你拿到所有权和(或)身体,以新的 no子形式展示你的新的 no子,这应该有所帮助。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签