Esempio n. 1
0
 /**
  * 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;
 }