stacks-8.x-1.x-dev/src/TwigExtension/GetThemePath.php

src/TwigExtension/GetThemePath.php
<?php

namespace Drupal\stacks\TwigExtension;

use Drupal\stacks\Widget\WidgetTemplates;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

/**
 * Class GetThemePath.
 * @package Drupal\stacks\TwigExtension
 */
class GetThemePath extends AbstractExtension {

  /**
   * Generates a list of all Twig filters that this extension defines.
   */
  public function getFilters() {
    return [
      new TwigFilter('getStacksPath', [$this, 'getStacksPath']),
    ];
  }

  /**
   * Gets a unique identifier for this Twig extension.
   */
  public function getName() {
    return 'stacks_getthemepath.twig_extension';
  }

  /**
   * Takes a path and returns the absolute path to include the file. This file
   * needs to be in the stacks directory of your frontend theme.
   *
   * @param $path string: The path of the file in the theme we want to return.
   * @return string: Absolute path to this file.
   */
  public function getStacksPath($path) {
    // Get the path to the frontend theme.
    $frontend_theme = WidgetTemplates::templateDir();

    // Return correct path to include this file.
    return '/' . $frontend_theme . '/' . $path;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc