class TwigExtension in Calendar 8
A class providing Calendar Twig extensions.
Hierarchy
- class \Drupal\calendar\Template\TwigExtension extends \Drupal\calendar\Template\Twig_Extension
Expanded class hierarchy of TwigExtension
1 string reference to 'TwigExtension'
1 service uses TwigExtension
File
- src/
Template/ TwigExtension.php, line 8
Namespace
Drupal\calendar\TemplateView source
class TwigExtension extends \Twig_Extension {
/**
* {@inheritdoc}
*/
public function getName() {
return 'calendar';
}
/**
* {@inheritdoc}
*/
public function getFilters() {
return [
new \Twig_SimpleFilter('calendar_stripe', [
$this,
'getCalendarStripe',
], [
'is_safe' => [
'html',
],
]),
];
}
/**
* 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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TwigExtension:: |
public | function | Adds a striped background to the passed event. | |
TwigExtension:: |
public | function | ||
TwigExtension:: |
public | function |