2

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

I have tried to create a custom content-type from code like here:

Update code https://github.com/jmvelasco/drupal

But the way, after install/activate it I get these warnings:

Warning: Illegal offset type in isset or empty in FieldInfo->getField() (line 270 of /users/gen00/web/html/modules/field/field.info.class.inc).
Warning: Illegal offset type in isset or empty in FieldInfo->getField() (line 274 of /users/gen00/web/html/modules/field/field.info.class.inc).
Warning: Illegal offset type in FieldInfo->getField() (line 291 of /users/gen00/web/html/modules/field/field.info.class.inc).
Warning: Illegal offset type in isset or empty in FieldInfo->getField() (line 270 of /users/gen00/web/html/modules/field/field.info.class.inc).
Warning: Illegal offset type in isset or empty in FieldInfo->getField() (line 274 of /users/gen00/web/html/modules/field/field.info.class.inc).
Warning: Illegal offset type in FieldInfo->getField() (line 291 of /users/gen00/web/html/modules/field/field.info.class.inc).
Warning: Illegal offset type in isset or empty in FieldInfo->getField() (line 270 of /users/gen00/web/html/modules/field/field.info.class.inc).
Warning: Illegal offset type in isset or empty in FieldInfo->getField() (line 274 of /users/gen00/web/html/modules/field/field.info.class.inc).
Warning: Illegal offset type in FieldInfo->getField() (line 291 of /users/gen00/web/html/modules/field/field.info.class.inc).

Although the content-type is apparently created.

EDIT the content could be created once I update the base value

But when go to Create Content of this new content-type, I have the following error

array
  'error' => 
    array
      0 => string '<em class="placeholder">Warning</em>: Missing argument 3 for node_form(), called in /users/gen00/web/html/modules/node/node.pages.inc on line 161 and defined in <em class="placeholder">node_form()</em> (line <em class="placeholder">107</em> of <em class="placeholder">/users/gen00/web/html/modules/node/node.pages.inc</em>).' (length=324)

Also, when uninstall the module I get this notice:

Notice: Trying to get property of non-object in content_access_node_type_delete() (line 524 of /users/gen00/web/html/sites/all/modules/contrib/content_access/content_access.module).

I can't figure out where is my mistake and I have come here wondering if any drupal-ninja could help me to understand my mistake and create this content-type correctly. Anyone?

Thanks in advance.

0

The errors are produced inside the file slider.install, line 99, replace:

 if (!field_info_field($field)) {
            field_create_field($field);
}

By

field_create_field($field);

The reason is that the function field_info_field() calls to $cache->getField($field_name);

For more information, go to Drupal: field_info_field()

  • You should pass field_name in when calling this function field_info_field($field_name) not $field object. – Saud Alfadhli May 1 '17 at 12:46
0

In your hook_node_info, 'base' should not be node. It has to be something else and generally your module name is advised.

Explanation from the node_example.module

// '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 our case, the base is 'node_example'.
  • I've updated the code and now it's possible to create content of this content type. That's great, thanks. Btw when installed, still appears those Warnings and I'd like to understand them and make what I need to don't have them. Could you help? Thanks. – manou Jan 14 '15 at 20:36
  • Can you specify what warnings? Your original post contains 3 types. – Maarten De Block Jan 15 '15 at 6:53
  • Hi, thank you for your hands up. The warnings I get is those I post. It's true that they are really three by each field I create at my cutom content type. The content type is now well created and I can create content, but always I install/reinstall the module I get these warnings and I think I might not have them and I could being skipping something important – manou Jan 15 '15 at 8:37
0

Can you use features module - Drupal.org/project/features ? It will be very easy for you to export the content type in code.

  • Thank you @Vaibhav, I was considering that idea but I'd like to become a drupal developer more than a webmaster so I want to understand and get deep knowledge from the drupal API. – manou Jan 15 '15 at 12:17

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.