/**
  * Implements \Drupal\block\BlockBase::build().
  */
 public function build()
 {
     if (!($view = views_get_page_view())) {
         return;
     }
     $style = $view->display_handler->getOption('style');
     if ($style['type'] != 'fullcalendar') {
         return;
     }
     $fields = array();
     foreach ($view->field as $field) {
         if (fullcalendar_field_is_date($field)) {
             $fields[$field->field_info['field_name']] = $field->field_info;
         }
     }
     return array('#theme' => 'fullcalendar_legend', '#types' => $this->buildLegend($fields));
 }
示例#2
0
 /**
  * @todo.
  */
 protected function prepareEvents()
 {
     $events = array();
     foreach ($this->view->result as $delta => $row) {
         // Collect all fields for the customize options.
         $fields = array();
         // Collect only date fields.
         $date_fields = array();
         foreach ($this->view->field as $field_name => $field) {
             $fields[$field_name] = $this->getField($delta, $field_name);
             if (fullcalendar_field_is_date($field)) {
                 $date_fields[$field_name] = array('value' => $field->getItems($row), 'field_alias' => $field->field_alias, 'field_name' => $field->field_info['field_name'], 'field_info' => $field->field_info);
             }
         }
         // If using a custom date field, filter the fields to process.
         if (!empty($this->options['fields']['date'])) {
             $date_fields = array_intersect_key($date_fields, $this->options['fields']['date_field']);
         }
         // If there are no date fields (gcal only), return.
         if (empty($date_fields)) {
             return $events;
         }
         $entity = $row->_entity;
         $classes = $this->moduleHandler->invokeAll('fullcalendar_classes', array($entity));
         $this->moduleHandler->alter('fullcalendar_classes', $classes, $entity);
         $classes = array_map('drupal_html_class', $classes);
         $class = implode(' ', array_unique($classes));
         $event = array();
         foreach ($date_fields as $field) {
             // Filter fields without value.
             if (empty($field['value'])) {
                 continue;
             }
             foreach ($field['value'] as $index => $item) {
                 $start = $item['raw']['value'];
                 $end = $start;
                 $all_day = FALSE;
                 $uri = $entity->uri();
                 $event[] = array('#type' => 'link', '#title' => $item['raw']['value'], '#href' => $uri['path'], '#options' => array('html' => TRUE, 'attributes' => array('allDay' => $all_day, 'start' => $start, 'end' => $end, 'editable' => (int) TRUE, 'field' => $field['field_name'], 'index' => $index, 'eid' => $entity->id(), 'entity_type' => $entity->entityType(), 'cn' => $class, 'title' => strip_tags(htmlspecialchars_decode($entity->label(), ENT_QUOTES)), 'class' => array('fullcalendar-event-details'))));
             }
         }
         if (!empty($event)) {
             $events[$delta] = array('#theme' => 'fullcalendar_event', '#event' => $event, '#entity' => $entity);
         }
     }
     return $events;
 }