You are here

class Files in Bamboo Twig 8

Provides a 'Files' Twig Extensions.

Hierarchy

  • class \Drupal\bamboo_twig_files\TwigExtension\Files extends \Drupal\bamboo_twig_files\TwigExtension\Twig_Extension

Expanded class hierarchy of Files

1 string reference to 'Files'
bamboo_twig_files.services.yml in bamboo_twig_files/bamboo_twig_files.services.yml
bamboo_twig_files/bamboo_twig_files.services.yml
1 service uses Files
bamboo_twig_files.twig.files in bamboo_twig_files/bamboo_twig_files.services.yml
Drupal\bamboo_twig_files\TwigExtension\Files

File

bamboo_twig_files/src/TwigExtension/Files.php, line 10

Namespace

Drupal\bamboo_twig_files\TwigExtension
View source
class Files extends \Twig_Extension {

  /**
   * List of all Twig functions.
   */
  public function getFunctions() {
    return [
      new \Twig_SimpleFunction('theme_url', [
        $this,
        'themeUrl',
      ], [
        'is_safe' => [
          'html',
        ],
      ]),
    ];
  }

  /**
   * List of all Twig functions.
   */
  public function getFilters() {
    return [
      new \Twig_SimpleFilter('extension_guesser', [
        $this,
        'extensionGuesser',
      ]),
    ];
  }

  /**
   * Unique identifier for this Twig extension.
   */
  public function getName() {
    return 'bamboo_twig.twig.files';
  }

  /**
   * Render a custom date format with Twig.
   *
   * Use the internal helper "format_date" to render the date
   * using the current language for texts.
   */
  public static function extensionGuesser($mime_type) {
    $guesser = ExtensionGuesser::getInstance();
    return $guesser
      ->guess($mime_type);
  }

  /**
   * Generate an absolute url to the given theme.
   *
   * @param string $theme
   *   Theme name.
   * @param string $file
   *   File path from theme root.
   *
   * @return string
   *   Absolute url to the given file in the theme.
   */
  public static function themeUrl($theme, $file) {
    return file_create_url(drupal_get_path('theme', $theme) . '/' . $file);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Files::extensionGuesser public static function Render a custom date format with Twig.
Files::getFilters public function List of all Twig functions.
Files::getFunctions public function List of all Twig functions.
Files::getName public function Unique identifier for this Twig extension.
Files::themeUrl public static function Generate an absolute url to the given theme.