Archive

Archive for November, 2010

Drupal 7 Field Api Node Reference Field

November 14, 2010 9 comments

Update : (21st May 2011)
The References Module now provides support for Node Reference and User References fields

http://drupal.org/project/references

Seems like the D7 CCK contains nodereference and userreference fields (as of 14th Nov), but don’t know how stable it is at the moment. Another alternative is to use the taxonomy term reference field. Since in D7, taxonomy terms can also fielded, they’re as good as another node and can be addressed independently of the referencing node.

One thing is still a shame though. Synonyms for taxonomy have been removed from the D7 release. See http://drupal.org/node/567572

Although there is synonyms module that uses fields to mimick the synonyms behavior, its still very nascent and needs more work.

Drupal 7 Field Instances Default Value

November 13, 2010 6 comments

Well, it seems like the drupal documentation is not sufficient in describing how to specify a default value for a programatically created field instance. As of drupal 7 beta-2, if a default value is not specified and say you are performing any ajax operation on the page, the form will throw a validation error.

Here’s how its done.
'al_resource_type' => array(
'field_name' => 'al_resource_type',
'label' => $t('Resource Type'),
'required' => TRUE,
'widget' => array(
'type' => 'options_buttons',
),
// Need to specify a default value, else the form throws a validation
// error while uploading files.
// Used by field_get_default_value
'default_value' => array(array('value' => "1")),
)

One can also use a “default_value_function” to return a default value.