You are here

class TwigExtenderService in Twig Extender 4.x

Same name and namespace in other branches
  1. 8.4 src/TwigExtenderService.php \Drupal\twig_extender\TwigExtenderService
  2. 8 src/TwigExtenderService.php \Drupal\twig_extender\TwigExtenderService
  3. 8.2 src/TwigExtenderService.php \Drupal\twig_extender\TwigExtenderService
  4. 8.3 src/TwigExtenderService.php \Drupal\twig_extender\TwigExtenderService

Service Provider Class for TwigExtesion Plugins.

Hierarchy

Expanded class hierarchy of TwigExtenderService

File

src/TwigExtenderService.php, line 15

Namespace

Drupal\twig_extender
View source
class TwigExtenderService extends TwigExtension {

  /**
   * Construtor.
   */
  public function __construct(RendererInterface $renderer, UrlGeneratorInterface $url_generator, ThemeManagerInterface $theme_manager, DateFormatterInterface $date_formatter, TwigPluginManagerInterface $manager) {
    parent::__construct($renderer, $url_generator, $theme_manager, $date_formatter);
    $this->pluginManager = $manager;
    $this->plugins = $this->pluginManager
      ->getDefinitions();
  }

  /**
   * Load all function plugins.
   */
  public function getFunctions() {
    $functions = parent::getFunctions();
    foreach ($this->plugins as $id => $plugin) {
      $plugin = $this->pluginManager
        ->createInstance($id, $plugin);
      if ($plugin
        ->getType() != 'function') {
        continue;
      }
      $functions[] = $plugin
        ->register();
    }
    return $functions;
  }

  /**
   * Load all filter plugins.
   */
  public function getFilters() {
    $filters = parent::getFilters();
    foreach ($this->plugins as $id => $plugin) {
      $plugin = $this->pluginManager
        ->createInstance($id);
      if ($plugin
        ->getType() != 'filter') {
        continue;
      }
      $filters[] = $plugin
        ->register();
    }
    return $filters;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TwigExtenderService::getFilters public function Load all filter plugins. Overrides TwigExtension::getFilters
TwigExtenderService::getFunctions public function Load all function plugins. Overrides TwigExtension::getFunctions
TwigExtenderService::__construct public function Construtor. Overrides TwigExtension::__construct
TwigExtension::$dateFormatter protected property The date formatter.
TwigExtension::$fileUrlGenerator protected property The file URL generator.
TwigExtension::$renderer protected property The renderer.
TwigExtension::$themeManager protected property The theme manager.
TwigExtension::$urlGenerator protected property The URL generator.
TwigExtension::attachLibrary public function Attaches an asset library to the template, and hence to the response.
TwigExtension::bubbleArgMetadata protected function Bubbles Twig template argument's cacheability & attachment metadata.
TwigExtension::createAttribute public function Creates an Attribute object.
TwigExtension::escapeFilter public function Overrides twig_escape_filter().
TwigExtension::escapePlaceholder public function Provides a placeholder wrapper around ::escapeFilter.
TwigExtension::getActiveTheme public function Gets the name of the active theme.
TwigExtension::getActiveThemePath public function Gets the path of the active theme.
TwigExtension::getLink public function Gets a rendered link from a url object.
TwigExtension::getName public function
TwigExtension::getNodeVisitors public function
TwigExtension::getPath public function Generates a URL path given a route name and parameters.
TwigExtension::getTokenParsers public function
TwigExtension::getUrl public function Generates an absolute URL given a route name and parameters.
TwigExtension::isUrlGenerationSafe public function Determines at compile time whether the generated URL will be safe.
TwigExtension::renderVar public function Wrapper around render() for twig printed output.
TwigExtension::safeJoin public function Joins several strings together safely.
TwigExtension::withoutFilter public function Removes child elements from a copy of the original array.