I wanted to utilise the Minimum/Maximum values of Integer field instance settings. I'd like to know where these are stored in the database, and whether it's feasible to use hook_node_save or presave to update these min/max fields. The site will use feeds to mass import nodes, and I was wondering if it'll be ok to update these values everytime the feed import is run?

Also is there an easy way to grab these min/max values on node view?


You can use field_info_instance() to get the details, and field_update_instance() to save them:

$entity_type = 'node';
$field_name = 'field_name';
$bundle = 'content_type';

// Load
$info = field_info_instance($entity_type, $field_name, $bundle);

// Get
$min = $info['settings']['min'];
$max = $info['settings']['max'];

// Set
$info['settings']['min'] = 1;
$info['settings']['max'] = 10;

// Save

I can't see any problem with updating those values during a mass import, but I can't see the benefit of doing it for every single node save. It would probably be better to run it once at the beginning/end of the import process.

You can use the same code in hook_node_view() to retrieve the values for display on the node page if you need them.

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.