0

I am following this guide to build a custom node type in Drupal 7:

http://www.sitepoint.com/creating-a-new-drupal-node-type/

Unfortunately, my code is not working and drupal is not outputting any error either. The module is there, is enabled, but the new custom type is not showing up. I have double checked the code several times and I'm sure I wrote it right, the same way of the guide.

How can I debug this kind of issue? I have installed the debug module, I am looking at the documentation here:

http://ratatosk.net/drupal/tutorials/debugging-drupal.html

but I'm a bit lost on where exactly should I up the debugging code to find the issue. I was hoping drupal has some kind of error log (like wordpress does) where I can see anything that goes wrong.

EDIT: I made the custom type work, now I can make a new custom type, but the code about the custom fields is ignored, like it's not there. Here the source of productcustomtype.install:

<?php
/**
 * Implements hook_install().
 */
function productcustomtype_install() {
    node_types_rebuild();
    $types = node_type_get_types();
    node_add_body_field($types['product']);
    productcustomtype_add_custom_fields();
}
/**
 * Implements hook_uninstall().
 */
function productcustomtype_uninstall() {
    $ournewtype = 'product';
    $sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
    $result = db_query($sql, array(':type' => $ournewtype));
    $nodeids = array();
    foreach ($result as $row) {
        $nodeids[] = $row->nid;
    }
    node_delete_multiple($nodeids);
    productcustomtype_delete_custom_fields();
    node_type_delete($ournewtype);
    field_purge_batch(500);
}

function productcustomtype_delete_custom_fields() {
    foreach (array_keys(_productcustomtype_installed_fields()) as $field) {
        field_delete_field($field);
    }
    $instances = field_info_instances('node', 'product');
    foreach ($instances as $instance_name => $fieldinstance) {
        field_delete_instance($fieldinstance);
    }
}

function _productcustomtype_installed_fields() {
    $t = get_t();
    return array(
        'productcustomtype_price' => array(
            'field_name' => 'productcustomtype_price',
            'label' => $t('Price of the product'),
            'type' => 'text'
        ),
        'productcustomtype_quantity' => array(
            'field_name' => 'productcustomtype_quantity',
            'label' => $t('Quantity of the product'),
            'type' => 'text'
        )
    );
}

function _productcustomtype_installed_instances() {
    $t = get_t();
    return array(
        'productcustomtype_price' => array(
            'field_name' => 'productcustomtype_price',
            'type' => 'text',
            'label' => $t('Price of the product'),
            'widget' => array(
                'type' => 'text_textfield'
            ),
            'display' => array(
                'example_node_list' => array(
                    'label' => $t('Price of the product'),
                    'type' => 'text'
                )
            )
        ),
        'productcustomtype_quantity' => array(
            'field_name' => 'productcustomtype_quantity',
            'type' => 'text',
            'label' => $t('Quantity of the product'),
            'widget' => array(
                'type' => 'text_textfield'
            ),
            'display' => array(
                'example_node_list' => array(
                    'label' => $t('Quantity of the product'),
                    'type' => 'text'
                )
            )
        )
    );
}
function productcustomtype_add_custom_fields() {
    foreach (_productcustomtype_installed_fields() as $field) {
        field_create_field($field);
    }
    foreach (_productcustomtype_installed_instances() as $fieldinstance) {
        $fieldinstance['entity_type'] = 'node';
        $fieldinstance['bundle'] = 'product';
        print_r($fieldinstance);
        field_create_instance($fieldinstance);
    }
}
5
  • 1
    check db_log(drush ws)
    – Vamsi
    Commented Apr 8, 2016 at 10:34
  • 1
    Please show the code you are using; without that, the question is not answerable, and the question needs not to depend on off-site resources, to be answered.
    – avpaderno
    Commented Apr 8, 2016 at 11:01
  • I am replicating the module example, I literally copy pasted the code of the tutorial, but I can edit the question and add the source
    – Terix
    Commented Apr 8, 2016 at 16:17
  • 1
    Have you tried using the debug function to output your variables at different part of the workflow? For example, right after line foreach(productcustomtype_installed_fields() as $field) { I'd add debug($field,'field',TRUE); and see if you are getting the installed fields data to begin with. From there, you can move your debug function to other parts of the workflow to find out where things go wrong. Commented Apr 11, 2016 at 0:47
  • how do I check if the install hook gets loaded? I have placed debug strings all over around, but none of them show up.
    – Terix
    Commented Apr 11, 2016 at 17:38

1 Answer 1

0

To make sure the changes apply and work, it is needed to disable the module and unistall it. This important step was missing on the guide.

Your Answer

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

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