diff --git a/includes/calendar_plugin_row.inc b/includes/calendar_plugin_row.inc
index 616baa2..10b8fff 100644
--- a/includes/calendar_plugin_row.inc
+++ b/includes/calendar_plugin_row.inc
@@ -51,6 +51,7 @@ class calendar_plugin_row extends views_plugin_row {
'taxonomy_field' => array('default' => ''),
'calendar_colors_vocabulary' => array('default' => array()),
'calendar_colors_taxonomy' => array('default' => array()),
+ 'calendar_colors_date_field' => array('default' => array()),
'calendar_colors_group' => array('default' => array()),
));
return $options;
@@ -84,6 +85,9 @@ class calendar_plugin_row extends views_plugin_row {
if (module_exists('taxonomy')) {
$options['taxonomy'] = t('Based on Taxonomy');
}
+ if (module_exists('field') ) {
+ $options['field'] = t('Based on Date Fields');
+ }
if (module_exists('og')) {
$options['group'] = t('Based on Organic Group');
}
@@ -203,6 +207,45 @@ class calendar_plugin_row extends views_plugin_row {
}
}
}
+ if (module_exists('field') ) {
+ $colors = $this->options['colors']['calendar_colors_date_field'];
+ $field_options = $this->display->handler->get_option('fields');
+ foreach ($field_options as $name => $field) {
+ // Only date fields are useful, since only the (date) fields from argument handler appear as an event.
+ if ( (empty($field['type']) || $field['type'] != 'date_default') && !isset($field['custom_date_format'])) {
+ continue;
+ }
+
+ $id = $field['field'];
+ $label = $field['label'];
+
+ $form['colors']['calendar_colors_date_field'][$id] = array(
+ '#title' => check_plain(t($label)),
+ '#default_value' => isset($colors[$id]) ? $colors[$id] : '#ffffff',
+ '#dependency' => array('edit-row-options-colors-legend' => array('field')),
+ '#type' => 'textfield',
+ '#size' => 7,
+ '#maxlength' => 7,
+ '#element_validate' => array('calendar_validate_hex_color'),
+ '#prefix' => '
',
+ '#attributes' => array('class' => array('edit-calendar-colorpicker')),
+ '#attached' => array(
+ // Add Farbtastic color picker.
+ 'library' => array(
+ array('system', 'farbtastic'),
+ ),
+ // Add javascript to trigger the colorpicker.
+ 'js' => array(drupal_get_path('module', 'calendar') . '/js/calendar_colorpicker.js'),
+ ),
+ );
+ }
+ if (empty($form['colors']['calendar_colors_date_field'])) {
+ $form['colors']['date_field']['#options'] = array('' => '');
+ $form['colors']['date_field']['#suffix'] = t('You must add a date field to this view to use field stripe values. This is only useful for entities with multiple date fields.');
+ }
+
+ }
if (module_exists('og')) {
$colors_group = $this->options['colors']['calendar_colors_group'];
$groups = og_get_all_group();
@@ -311,6 +354,18 @@ class calendar_plugin_row extends views_plugin_row {
$field_name = 'revision_timestamp';
}
+ if (module_exists('field') ) {
+ // Overwrite label: Use Views, not Fields for fields in Legend (e.g. removes 'Content: '-part).
+ // This can only be done for fields that are in the fields list of the display
+ $field_options = &$this->display->handler->get_option('fields');
+ foreach ($field_options as $field) {
+ if ($field['field'] == $field_name) {
+ $info['label'] = $field['label'];
+ break;
+ }
+ }
+ }
+
$date_fields[$field_name] = $info;
}
}
@@ -356,6 +411,7 @@ class calendar_plugin_row extends views_plugin_row {
$tz_field = $info['timezone_field'];
$rrule_field = $info['rrule_field'];
$is_field = $info['is_field'];
+ $field_label = $info['label'];
$info = entity_get_info($this->entity_type);
$this->id_field = $info['entity keys']['id'];
@@ -444,6 +502,9 @@ class calendar_plugin_row extends views_plugin_row {
case 'taxonomy':
$this->calendar_taxonomy_stripe($entity);
break;
+ case 'field':
+ $this->calendar_date_field_stripe($entity);
+ break;
case 'group':
$this->calendar_group_stripe($entity);
break;
@@ -587,6 +648,25 @@ class calendar_plugin_row extends views_plugin_row {
}
/**
+ * Create a stripe based on the date field of the event.
+ */
+ function calendar_date_field_stripe(&$result) {
+ $colors = isset($this->options['colors']['calendar_colors_date_field']) ? $this->options['colors']['calendar_colors_date_field'] : array();
+ if (empty($colors)) {
+ return;
+ }
+ if (!empty($result->field_name)) {
+ $field_name = $result->field_name;
+ if (array_key_exists($field_name, $colors)) {
+ $result->stripe[] = $colors[$field_name];
+ $result->stripe_label[] = $result->field_label;
+ }
+ }
+
+ return;
+ }
+
+ /**
* Create a stripe based on group.
*/
function calendar_group_stripe(&$result) {