You are here

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'
calendar.services.yml in ./calendar.services.yml
calendar.services.yml
1 service uses TwigExtension
calendar.twig.extension in ./calendar.services.yml
Drupal\calendar\Template\TwigExtension

File

src/Template/TwigExtension.php, line 8

Namespace

Drupal\calendar\Template
View 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] . '">&nbsp;</div>' . "\n";
      }
    }
    return $output;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TwigExtension::getCalendarStripe public function Adds a striped background to the passed event.
TwigExtension::getFilters public function
TwigExtension::getName public function