You are here

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

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'),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
field_timer_formatter_base::getTimestamp abstract protected function Convert field item value to timestamp. 16
field_timer_formatter_interface::getFieldType public function Get field type. 16
field_timer_text_base::enableFormatter public function @inheritdoc Overrides field_timer_formatter_interface::enableFormatter
field_timer_text_base::formatInterval protected function Formats interval according to granularity settings.
field_timer_text_base::formatterGranularityAuto protected function
field_timer_text_base::formatterGranularityManual protected function
field_timer_text_base::formatterTypes protected function
field_timer_text_base::getFormatterDefinition final public function @inheritdoc Overrides field_timer_formatter_interface::getFormatterDefinition
field_timer_text_base::getFormatterName public function @inheritdoc Overrides field_timer_formatter_interface::getFormatterName
field_timer_text_base::granularitySettingsSummary protected function
field_timer_text_base::granularityTypes protected function
field_timer_text_base::renderItem protected function Render field item.
field_timer_text_date_field_base::formatterDisplays protected function
field_timer_text_date_field_base::getDefaultSettings public function @inheritdoc Overrides field_timer_text_base::getDefaultSettings
field_timer_text_date_field_base::getSettingsForm public function @inheritdoc Overrides field_timer_text_base::getSettingsForm
field_timer_text_date_field_base::getSettingsSummary public function @inheritdoc Overrides field_timer_text_base::getSettingsSummary
field_timer_text_date_field_base::renderItems public function @inheritdoc Overrides field_timer_text_base::renderItems