abstract class field_timer_text_date_field_base in Field Timer 7.2
Base class for field_timer_text formatter and date field types.
Hierarchy
- class \field_timer_formatter_base implements field_timer_formatter_interface
- class \field_timer_text_base
Expanded class hierarchy of field_timer_text_date_field_base
File
- includes/
field_timer_text.inc, line 271 - Contains help classes to perform field_timer_text formatter related actions.
View source
abstract class field_timer_text_date_field_base extends field_timer_text_base {
/**
* @inheritdoc
*/
public function getDefaultSettings() {
return parent::getDefaultSettings() + array(
'title' => '',
'title2' => '',
'type2' => 'auto',
'granularity_type2' => 'auto',
'granularity_auto2' => 2,
'granularity_manual2' => array(
'day' => 'day',
),
'fromto' => 'both',
);
}
/**
* @inheritdoc
*/
public function getSettingsSummary($settings, $field) {
$summary = array();
if (!empty($field['settings']['todate'])) {
$types = $this
->formatterTypes();
$displays = $this
->formatterDisplays();
$granularity_options = $this
->granularitySettingsSummary($settings['granularity_type'], $settings['granularity_auto'], $settings['granularity_manual']);
$granularity_options2 = $this
->granularitySettingsSummary($settings['granularity_type2'], $settings['granularity_auto2'], $settings['granularity_manual2']);
$summary[] = t('Type for Start date: %type', array(
'%type' => $types[$settings['type']],
));
$summary[] = t('Granularity for Start date: %granularity_type (%granularity)', $granularity_options);
$summary[] = t('Title for Start date: %title', array(
'%title' => $settings['title'],
));
$summary[] = t('Type for End date: %type', array(
'%type' => $types[$settings['type2']],
));
$summary[] = t('Granularity for End date: %granularity_type (%granularity)', $granularity_options2);
$summary[] = t('Title for End date: %title', array(
'%title' => $settings['title2'],
));
$summary[] = t('Display: %display', array(
'%display' => $displays[$settings['fromto']],
));
}
else {
$summary[] = t('Title: %title', array(
'%title' => $settings['title'],
));
$summary = array_merge($summary, parent::getSettingsSummary($settings, $field));
}
return $summary;
}
/**
* @inheritdoc
*/
public function getSettingsForm($settings, $field) {
$settings_form = parent::getSettingsForm($settings, $field);
$settings_form['title'] = array(
'#type' => 'textfield',
'#title' => empty($field['settings']['todate']) ? t('Title') : t('Title for Start date'),
'#default_value' => $settings['title'],
'#weight' => -10,
);
if (!empty($field['settings']['todate'])) {
$settings_form['type']['#title'] = t('Type for Start date');
$settings_form['granularity_type']['#title'] = t('Granularity for Start date');
$settings_form['title2'] = array(
'#type' => 'textfield',
'#title' => t('Title for End date'),
'#default_value' => $settings['title2'],
);
$settings_form['type2'] = array(
'#type' => 'select',
'#title' => t('Type for End date'),
'#options' => $this
->formatterTypes(),
'#default_value' => $settings['type2'],
);
$settings_form['granularity_type2'] = array(
'#type' => 'select',
'#title' => t('Granularity for End date'),
'#options' => $this
->granularityTypes(),
'#default_value' => $settings['granularity_type2'],
'#attributes' => array(
'class' => array(
'field-timer-text-granularity-type-2',
),
),
);
$settings_form['granularity_auto2'] = array(
'#type' => 'select',
'#options' => $this
->formatterGranularityAuto(),
'#default_value' => $settings['granularity_auto2'],
'#states' => array(
'visible' => array(
'select.field-timer-text-granularity-type-2' => array(
'value' => 'auto',
),
),
),
);
$settings_form['granularity_manual2'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#options' => $this
->formatterGranularityManual(),
'#default_value' => $settings['granularity_manual2'],
'#states' => array(
'visible' => array(
'select.field-timer-text-granularity-type-2' => array(
'value' => 'manual',
),
),
),
);
$settings_form['fromto'] = array(
'#type' => 'select',
'#title' => t('Display'),
'#options' => $this
->formatterDisplays(),
'#default_value' => $settings['fromto'],
);
}
return $settings_form;
}
/**
* @inheritdoc
*/
public function renderItems($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$settings = $display['settings'];
$elements = $settings['fromto'] != 'to' ? parent::renderItems($entity_type, $entity, $field, $instance, $langcode, $items, $display) : array();
$granularity_option = $settings['granularity_' . $settings['granularity_type2'] . '2'];
foreach ($items as $delta => $item) {
if ($settings['fromto'] != 'to' && !empty($settings['title'])) {
$elements[$delta]['#markup'] = '<span class="field-timer-start-date-title">' . $settings['title'] . '</span> ' . $elements[$delta]['#markup'];
}
if ($settings['fromto'] == 'both' && !empty($field['settings']['todate'])) {
$elements[$delta]['#markup'] = '<div class="field-timer-start-date">' . $elements[$delta]['#markup'] . '</div>';
}
if ($settings['fromto'] != 'from' && !empty($field['settings']['todate'])) {
$title = !empty($settings['title2']) ? '<span class="field-timer-end-date-title">' . $settings['title2'] . '</span> ' : '';
$time = $this
->renderItem($settings['type2'], $settings['granularity_type2'], $granularity_option, $this
->getTimestamp($item, $field, 'value2'));
if ($settings['fromto'] == 'to') {
$elements[$delta] = array(
'#type' => 'markup',
'#markup' => $title . $time,
);
}
else {
$elements[$delta]['#markup'] .= '<div class="field-timer-end-date">' . $title . $time . '</div>';
}
}
}
return $elements;
}
protected function formatterDisplays() {
return array(
'both' => t('Both Start and End dates'),
'from' => t('Start date only'),
'to' => t('End date only'),
);
}
}