Posted By

depiction on 02/04/14


Tagged

drupal


Versions (?)

Drupal: Get Custom Field value and default value


 / Published in: PHP
 

This has been tested in page.tpl.php. Get the custom field value. If the value is emtpy, get the default value. Be sure to replace the field and content type values.

Also see: http://drupal.stackexchange.com/questions/60259/how-to-reset-a-form-element-to-its-ordinary-default-value and http://drupal.stackexchange.com/questions/7402/display-a-custom-field-of-a-content-type-in-template-with-php

  1. $phone = field_get_items('node', $node, 'field_phone_number');
  2. $phone = $phone[0]['safe_value'];
  3. if ($phone == NULL) {
  4. $field = field_info_field('field_phone_number');
  5. $instance = field_info_instance('node', 'field_phone_number', 'CONTENT_TYPE');
  6. $phone = field_get_default_value('node', $node, $field, $instance, $node->language);
  7. $phone = $phone[0][value];
  8. }

Report this snippet  

You need to login to post a comment.