TRUE); $options['granularity'] = array('default' => 2); $options['prefix'] = array('default' => '', 'translatable' => TRUE); $options['suffix'] = array('default' => '', 'translatable' => TRUE); return $options; } public function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); EntityFieldHandlerHelper::options_form($this, $form, $form_state); $form['format_interval'] = array( '#type' => 'checkbox', '#title' => t('Format interval'), '#description' => t('If checked, the value will be formatted as a time interval. Otherwise, just the number of seconds will be displayed.'), '#default_value' => $this->options['format_interval'], ); $form['granularity'] = array( '#type' => 'textfield', '#title' => t('Granularity'), '#default_value' => $this->options['granularity'], '#description' => t('Specify how many different units to display.'), '#dependency' => array('edit-options-format-interval' => array(TRUE)), '#size' => 2, ); $form['prefix'] = array( '#type' => 'textfield', '#title' => t('Prefix'), '#default_value' => $this->options['prefix'], '#description' => t('Text to put before the duration text.'), ); $form['suffix'] = array( '#type' => 'textfield', '#title' => t('Suffix'), '#default_value' => $this->options['suffix'], '#description' => t('Text to put after the duration text.'), ); } /** * Render the field. * * @param $values * The values retrieved from the database. */ public function render($values) { return EntityFieldHandlerHelper::render($this, $values); } /** * Render a single field value. */ public function render_single_value($value, $values) { if ($this->options['format_interval']) { $value = format_interval($value, (int) $this->options['granularity']); } // Value sanitization is handled by the wrapper, see // EntityFieldHandlerHelper::get_value(). return $this->sanitize_value($this->options['prefix'], 'xss') . $value . $this->sanitize_value($this->options['suffix'], 'xss'); } }