/** * Adds a striped background to the passed event. * * @param \Drupal\calendar\CalendarEvent $event * * @return string * A HTML output string. */ public function getCalendarStripe($event) { if (empty($event->getStripeHexes()) || !count($event->getStripeHexes())) { return; } $output = ''; foreach ($event->getStripeLabels() as $k => $stripe_label) { if (!empty($event->getStripeHexes()[$k]) && !empty($stripe_label)) { $output .= '<div style="background-color:' . $event->getStripeHexes()[$k] . ';color:' . $event->getStripeHexes()[$k] . '" class="stripe" title="Key: ' . $event->getStripeLabels()[$k] . '"> </div>' . "\n"; } } return $output; }
/** * Create a stripe based on a taxonomy term. * * @param CalendarEvent $event */ function calendarTaxonomyStripe(&$event) { $colors = isset($this->options['colors']['calendar_colors_taxonomy']) ? $this->options['colors']['calendar_colors_taxonomy'] : []; if (empty($colors)) { return; } $entity = $event->getEntity(); $term_field_name = $this->options['colors']['taxonomy_field']; if ($entity->hasField($term_field_name) && ($terms_for_entity = $entity->get($term_field_name))) { /** @var EntityReferenceFieldItemListInterface $item */ foreach ($terms_for_entity as $item) { $tid = $item->getValue()['target_id']; $term = Term::load($tid); if (!array_key_exists($tid, $colors) || $colors[$tid] == CALENDAR_EMPTY_STRIPE) { continue; } $event->addStripeLabel($term->name->value); $event->addStripeHex($colors[$tid]); } } return; }