0

I'm creating one of my first Drupal modules which should create a node (type= page) when you activate the module, and then add some javascript to site.

But when I activate the module, it creates three nodes with the desired node-title, and drupal produces an error:

Notice: Undefined index: module i FieldInfo->prepareInstanceWidget() (linje 591 af /var/www/SITENAME/public_html/modules/field/field.info.class.inc).
Notice: Undefined index: module i FieldInfo->prepareInstanceDisplay() (linje 626 af /var/www/SITENAME/public_html/modules/field/field.info.class.inc).
Notice: Undefined index: module i FieldInfo->prepareInstanceDisplay() (linje 626 af /var/www/SITENAME/public_html/modules/field/field.info.class.inc).

I am creating the node in the .module file like this:

$node = new stdClass(); 
$node->type = "page"; 
$node->title = "Page title";
$node->language = LANGUAGE_NONE; 
$node->path = array('alias' => 'some-path');
node_object_prepare($node); 
$node->uid = 1; 
// Let's add standard body field
$node->body[$node->language][0]['value'] = 'This is a body text';
$node->body[$node->language][0]['summary'] = '';
$node->body[$node->language][0]['format'] = 'full_html';
$node = node_submit($node); 
node_save($node); 

The above code is based on this article

If i were to use the above path for the node, i would get three pages created with the following paths (i have pathauto installed):

/some-path
/some-path
/page-title.html

All of the pages have the "Page title" title set, and if i edit them they all have the 'This is a body text' body content.

Any help would be appreciated.

0

Have you installed the drupal for a specific language. If yes than please take care of the language on the time of node creation. e.g. for engisg code is en.

Also please make sure that the function you are calling is attached to only 1 menu. It should not be called by several other source on that module. So, please check HOOK_install, HOOK_menu, HOOK_init wherever you add code for the same.

  • Thank you for your answer.. HOOK install was the solution needed. Do you know if it is possible to add a meta content="nofollow" tag to the node i have just created..? – neessen Feb 4 '15 at 11:04
  • On the view page of the node or the link you want to add it? – Shubham Feb 4 '15 at 16:52
  • You can do it like this You can use below code for adding no-follow and no-index meta for the node. Put this code in your themes template.php file. function MYTHEME_html_head_alter(&$head_elements) { if (arg(0) == 'node' && arg(1) == 'YOUR NODE NID' && !arg(2)) { $head_elements['MYMODULE_meta_robots'] = array( '#tag' => 'meta', '#type' => 'html_tag', '#attributes' => array( 'name' => 'robots', 'content' => 'noindex' ) ); } } – Shubham Feb 4 '15 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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