Adding a new node type programmatically from .install file.

3 replies [Last post]
Mark Frandson
Offline
Last seen: 11 years 12 weeks ago
Joined: 2011-03-04

Great video on adding a new node type with a module.

Got everything to work on my residential listing node type except I'm stuck on how to set the precision and scale for a decimal field (e.g. decimal 12,6). And I don't know how to set the length of a text field. Here's two of the fields I need to modify:

function _residential_installed_fields() {
  return array(
    'field_r_longitude' => array(
      'field_name'  => 'field_r_longitude',
      'type'        => 'number_decimal',
      'cardinality' => 1,
    'field_r_public_remarks' => array(
      'field_name'  => 'field_r_public_remarks',
      'type'        => 'text',
      'cardinality' => 1,
    ),  

How would I set the field_r_longitude to decimal 12,6 and how would I set field_r_public_remarks to hold up to 1000 characters?

Mark Frandson
Offline
Last seen: 11 years 12 weeks ago
Joined: 2011-03-04
I got the decimal field working. Still need text field though.

I got the decimal field working by changing the code to:

    'field_r_long' => array(
      'field_name'  => 'field_r_long',
      'type'        => 'number_decimal',
      'settings' => array('precision' => 12, 'scale' => 6, 'decimal_separator' => '.'),
      'cardinality' => 1,

Probably the text field setting is obvious, but not to me yet.

Mark Frandson
Offline
Last seen: 11 years 12 weeks ago
Joined: 2011-03-04
And now for the text field

 
    'field_r_public_remarks' => array(
      'field_name'  => 'field_r_public_remarks',
      'type'        => 'text',
      'settings' => array('max_length' => 1000),
      'cardinality' => 1,
    ),    

As easy as these settings were -- I had a hard time tracking down this info. But I think I'm getting used to using Chris's trick of searching through the site files with Komodo and looking for clues in the code itself.

I also found this example for installing a custom node type demonstrating presets for several field types http://davsblog.me/drupal-7-field-api-setup-a-new-content-type-o

Chris Shattuck
Offline
Last seen: 10 weeks 3 days ago
Joined: 2009-08-16
Thank you so much Mark for

Thank you so much Mark for posting your progress on this, nice work! I'm wondering if there's anything documented for those field settings. I'll have to do some fishing at some point and see if I can dig something up. Or, if you find something, please post back here.

Cheers!
Chris

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:


Loading...
Contact us

Below are the supported keyboard shortcuts for our video player.

space
Start / stop video
shift
Go to next video
shift
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
1...9
Jump to a percentage (2 is 20%, for example)
f
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
$29
1 month
$156
6 months
10% off
$276
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
user
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.