/** * {@inheritdoc} */ public function render($row) { /** @var \Drupal\calendar\CalendarDateInfo $dateInfo */ $dateInfo = $this->dateArgument->view->dateInfo; $id = $row->_entity->id(); if (!is_numeric($id)) { return []; } // There could be more than one date field in a view so iterate through all // of them to find the right values for this view result. foreach ($this->dateFields as $field_name => $info) { // Clone this entity so we can change it's values without altering other // occurrences of this entity on the same page, for example in an // "Upcoming" block. /** @var \Drupal\Core\Entity\ContentEntityBase $entity */ $entity = clone $this->entities[$id]; if (empty($entity)) { return []; } // @todo clean up // $table_name = $info['table_name']; $delta_field = $info['delta_field']; // $tz_handling = $info['tz_handling']; // $tz_field = $info['timezone_field']; // $rrule_field = $info['rrule_field']; // $is_field = $info['is_field']; $event = new CalendarEvent($entity); // Retrieve the field value(s) that matched our query from the cached node. // Find the date and set it to the right timezone. $entity->date_id = []; $item_start_date = NULL; $item_end_date = NULL; $granularity = 'second'; $increment = 1; // @todo implement timezone support if ($info['is_field']) { $fields = $entity->getFields(); // Should CalendarHelper::dateViewFields() be returning this already $entity_field_name = str_replace('_value', '', $field_name); if (isset($fields[$entity_field_name])) { $fieldWrapper = new DateFieldWrapper($fields[$entity_field_name]); // $items = field_get_items($this->entity_type, $entity, $field_name, $this->language); // $item = $items[$delta]; // $db_tz = date_get_timezone_db($tz_handling, isset($item->$tz_field) ? $item->$tz_field : timezone_name_get($dateInfo->getTimezone())); // $to_zone = date_get_timezone($tz_handling, isset($item->$tz_field)) ? $item->$tz_field : timezone_name_get($dateInfo->getTimezone()); $eventDeltaCount = $dateInfo->getEventDeltaCount(); if (!array_key_exists($id, $eventDeltaCount)) { $delta = 0; } else { $delta = $eventDeltaCount[$id] + 1; } $eventDeltaCount[$id] = $delta; $dateInfo->setEventDeltaCount($eventDeltaCount); if (!$fieldWrapper->isEmpty()) { // $item_start_date = new dateObject($item['value'], $db_tz); $item_start_date = $fieldWrapper->getStartDate($delta); // $item_end_date = array_key_exists('value2', $item) ? new dateObject($item['value2'], $db_tz) : $item_start_date; $item_end_date = $fieldWrapper->getEndDate($delta); } } // $cck_field = field_info_field($field_name); // $instance = field_info_instance($this->entity_type, $field_name, $this->type); // @todo don't hardcode // $granularity = date_granularity_precision($cck_field['settings']['granularity']); $granularity = 'week'; // $increment = $instance['widget']['settings']['increment']; } elseif ($entity->get($field_name)) { $item = $entity->get($field_name)->getValue(); // @todo handle timezones // $db_tz = date_get_timezone_db($tz_handling, isset($item->$tz_field) ? $item->$tz_field : timezone_name_get($dateInfo->getTimezone())); // $to_zone = date_get_timezone($tz_handling, isset($item->$tz_field) ? $item->$tz_field : timezone_name_get($dateInfo->getTimezone())); // $item_start_date = new dateObject($item, $db_tz); $item_start_date = new \DateTime(); $item_start_date->setTimestamp($item[0]['value']); $item_end_date = $item_start_date; $entity->date_id = ['calendar.' . $id . '.' . $field_name . '.0']; } // If we don't have a date value, go no further. if (empty($item_start_date)) { continue; } // Set the item date to the proper display timezone; // @todo handle timezones // $item_start_date->setTimezone(new dateTimezone($to_zone)); // $item_end_date->setTimezone(new dateTimezone($to_zone)); $event->setStartDate($item_start_date); $event->setEndDate($item_end_date); $event->setTimezone(new \DateTimeZone(timezone_name_get($dateInfo->getTimezone()))); $event->setGranularity($granularity); // @todo remove while properties get transfered to the new object // $event_container = new stdClass(); // $event_container->db_tz = $db_tz; // $event_container->to_zone = $to_zone; // $event_container->increment = $increment; // $event_container->field = $is_field ? $item : NULL; // $event_container->row = $row; // $event_container->entity = $entity; // All calendar row plugins should provide a date_id that the theme can use. // @todo implement // $event_container->date_id = $entity->date_id[0]; // We are working with an array of partially rendered items // as we process the calendar, so we can group and organize them. // At the end of our processing we'll need to swap in the fully formatted // display of the row. We save it here and switch it in // template_preprocess_calendar_item(). // @FIXME // theme() has been renamed to _theme() and should NEVER be called directly. // Calling _theme() directly can alter the expected output and potentially // introduce security issues (see https://www.drupal.org/node/2195739). You // should use renderable arrays instead. // // // @see https://www.drupal.org/node/2195739 // $event->rendered = theme($this->theme_functions(), // array( // 'view' => $this->view, // 'options' => $this->options, // 'row' => $row, // 'field_alias' => isset($this->field_alias) ? $this->field_alias : '', // )); /** @var \Drupal\calendar\CalendarEvent[] $events */ $events = $this->explode_values($event); foreach ($events as $event) { switch ($this->options['colors']['legend']) { case 'type': if ($event->getEntityTypeId() == 'node') { $this->nodeTypeStripe($event); } break; case 'taxonomy': $this->calendarTaxonomyStripe($event); break; } $rows[] = $event; } } return $rows; }