abstract class field_timer_county_base in Field Timer 7.2
Base class for field_timer_county formatter.
Hierarchy
- class \field_timer_formatter_base implements field_timer_formatter_interface
- class \field_timer_formatter_js_base
- class \field_timer_county_base
- class \field_timer_formatter_js_base
Expanded class hierarchy of field_timer_county_base
File
- includes/
field_timer_county.inc, line 13 - Help file. Contains help classes to perform field_timer_county formatter related actions.
View source
abstract class field_timer_county_base extends field_timer_formatter_js_base {
/**
* @inheritdoc
*/
public function enableFormatter() {
$library = libraries_detect('county');
return $library && !empty($library['installed']);
}
/**
* @inheritdoc
*/
public final function getFormatterDefinition() {
return array(
'label' => t('County'),
'description' => t('Use County jQuery plugin to display countdown.'),
);
}
/**
* @inheritdoc
*/
public function getDefaultSettings() {
return array(
'animation' => 'fade',
'speed' => 500,
'county_theme' => 'blue',
'background' => '',
'reflection' => 1,
'reflectionOpacity' => 0.2,
);
}
/**
* @inheritdoc
*/
public function getSettingsSummary($settings, $field) {
$summary = array();
$animations = $this
->formatterAnimations();
$themes = $this
->formatterThemes();
$summary[] = t('Animation: %animation', array(
'%animation' => $animations[$settings['animation']],
));
$summary[] = t('Speed: %speed', array(
'%speed' => $settings['speed'] . 'ms',
));
$summary[] = t('Theme: %theme', array(
'%theme' => $themes[$settings['county_theme']],
));
$summary[] = t('Background: %css', array(
'%css' => $settings['background'],
));
$summary[] = t('Reflection: %state', array(
'%state' => $settings['reflection'] ? 'Enabled' : 'Disabled',
));
if ($settings['reflection']) {
$summary[] = t('Reflection opacity: %opacity', array(
'%opacity' => $settings['reflectionOpacity'],
));
}
return $summary;
}
/**
* @inheritdoc
*/
public function getSettingsForm($settings, $field) {
$settings_form = array();
$settings_form['animation'] = array(
'#type' => 'select',
'#title' => t('Animation'),
'#options' => $this
->formatterAnimations(),
'#default_value' => $settings['animation'],
);
$settings_form['speed'] = array(
'#type' => 'textfield',
'#title' => t('Speed'),
'#default_value' => $settings['speed'],
);
$settings_form['county_theme'] = array(
'#type' => 'select',
'#title' => t('Theme'),
'#options' => $this
->formatterThemes(),
'#default_value' => $settings['county_theme'],
);
$settings_form['background'] = array(
'#type' => 'textfield',
'#title' => t('Background'),
'#default_value' => $settings['background'],
'#description' => t("Data from this field will be added to css property 'background'."),
);
$settings_form['reflection'] = array(
'#type' => 'checkbox',
'#title' => t('Add reflection'),
'#default_value' => $settings['reflection'],
'#attributes' => array(
'class' => array(
'field-timer-county-reflection',
),
),
);
$settings_form['reflectionOpacity'] = array(
'#type' => 'textfield',
'#title' => t('Reflection opacity'),
'#default_value' => $settings['reflectionOpacity'],
'#description' => t('Float value between 0 and 1.'),
'#states' => array(
'invisible' => array(
'input.field-timer-county-reflection' => array(
'checked' => FALSE,
),
),
),
);
return $settings_form;
}
/**
* @inheritdoc
*/
public function renderItems($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
if (!$this
->loadLibrary()) {
return array();
}
$info = entity_get_info($entity_type);
$id_key = $info['entity keys']['id'];
$elements = array();
$settings = $display['settings'];
foreach ($items as $delta => $item) {
$elements[$delta] = array(
'#type' => 'markup',
'#markup' => '<div id="county-' . $entity_type . '_' . $entity->{$id_key} . '_' . $field['field_name'] . '_' . $delta . '" ' . 'style="background: ' . $settings['background'] . ';"></div>',
);
}
$this
->loadJSandCSS($entity_type, $entity, $field, $instance, $langcode, $items, $display);
return $elements;
}
/**
* @inheritdoc
*/
public function getFormatterName() {
return 'field_timer_county';
}
/**
* @inheritdoc
*/
public function getPluginName() {
return 'county';
}
/**
* @inheritdoc
*/
protected function loadLibrary() {
if (!$this->library_loaded) {
$library = libraries_load('county');
$this->library_loaded = $library && !empty($library['loaded']);
$js_name = 'county.js';
$base_path = 'sites/all/libraries/county';
if (!$this->library_loaded) {
drupal_set_message(t("Can't load County library. Please download !url jQuery plugin and extract it to @path, so @js can be found at @full_path.", array(
'!url' => l(t('County'), 'http://www.egrappler.com/free-jquery-count-down-plugin-county/', array(
'absolute' => TRUE,
)),
'@path' => $base_path,
'@js' => $js_name,
'@full_path' => $base_path . '/js/' . $js_name,
)), 'error');
}
}
return $this->library_loaded;
}
/**
* @inheritdoc
*/
protected function generateJSSettings($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$info = entity_get_info($entity_type);
$id_key = $info['entity keys']['id'];
$js_settings = array();
$settings = $display['settings'];
foreach ($items as $delta => $item) {
$key = $entity_type . '_' . $entity->{$id_key} . '_' . $field['field_name'] . '_' . $delta;
$js_settings[$key]['timestamp'] = $this
->getTimestamp($item, $field);
$js_settings[$key]['options'] = $settings;
$js_settings[$key]['plugin'] = $this
->getPluginName();
}
return $js_settings;
}
protected function formatterAnimations() {
return array(
'fade' => t('Fade'),
'scroll' => t('Scroll'),
);
}
protected function formatterThemes() {
return array(
'black' => t('Black'),
'gray' => t('Gray'),
'red' => t('Red'),
'blue' => t('Blue'),
);
}
}