public function Calendar::calendarTaxonomyStripe in Calendar 8
Create a stripe based on a taxonomy term.
Parameters
\Drupal\calendar\CalendarEvent $event: A calendar event.
1 call to Calendar::calendarTaxonomyStripe()
- Calendar::render in src/
Plugin/ views/ row/ Calendar.php - Render a row object. This usually passes through to a theme template of some form, but not always.
File
- src/
Plugin/ views/ row/ Calendar.php, line 682
Class
- Calendar
- Plugin which creates a view on the resulting object and formats it as a Calendar entity.
Namespace
Drupal\calendar\Plugin\views\rowCode
public function calendarTaxonomyStripe(CalendarEvent &$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;
}