TimeInterval.php in Views (for Drupal 7) 8.3
Definition of Drupal\views\Plugin\views\field\TimeInterval.
Namespace
Drupal\views\Plugin\views\fieldFile
lib/Drupal/views/Plugin/views/field/TimeInterval.phpView source
<?php
/**
* @file
* Definition of Drupal\views\Plugin\views\field\TimeInterval.
*/
namespace Drupal\views\Plugin\views\field;
use Drupal\Core\Annotation\Plugin;
/**
* A handler to provide proper displays for time intervals.
*
* @ingroup views_field_handlers
*
* @Plugin(
* id = "time_interval"
* )
*/
class TimeInterval extends FieldPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['granularity'] = array(
'default' => 2,
);
return $options;
}
public function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state);
$form['granularity'] = array(
'#type' => 'textfield',
'#title' => t('Granularity'),
'#description' => t('How many different units to display in the string.'),
'#default_value' => $this->options['granularity'],
);
}
function render($values) {
$value = $values->{$this->field_alias};
return format_interval($value, isset($this->options['granularity']) ? $this->options['granularity'] : 2);
}
}
Classes
Name | Description |
---|---|
TimeInterval | A handler to provide proper displays for time intervals. |