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);
}
}
foreach(productcustomtype_installed_fields() as $field) {
I'd adddebug($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.