You are here

class File in Bamboo Twig 8.3

Same name and namespace in other branches
  1. 8.5 bamboo_twig_file/src/TwigExtension/File.php \Drupal\bamboo_twig_file\TwigExtension\File
  2. 8.2 bamboo_twig_file/src/TwigExtension/File.php \Drupal\bamboo_twig_file\TwigExtension\File
  3. 8.4 bamboo_twig_file/src/TwigExtension/File.php \Drupal\bamboo_twig_file\TwigExtension\File

Provides a 'File' Twig Extensions.

Hierarchy

  • class \Drupal\bamboo_twig\TwigExtension\TwigExtensionBase extends \Drupal\bamboo_twig\TwigExtension\Twig_Extension uses \Symfony\Component\DependencyInjection\ContainerAwareTrait
    • class \Drupal\bamboo_twig_file\TwigExtension\File

Expanded class hierarchy of File

1 string reference to 'File'
bamboo_twig_file.services.yml in bamboo_twig_file/bamboo_twig_file.services.yml
bamboo_twig_file/bamboo_twig_file.services.yml
1 service uses File
bamboo_twig_file.twig.file in bamboo_twig_file/bamboo_twig_file.services.yml
Drupal\bamboo_twig_file\TwigExtension\File

File

bamboo_twig_file/src/TwigExtension/File.php, line 10

Namespace

Drupal\bamboo_twig_file\TwigExtension
View source
class File extends TwigExtensionBase {

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

  /**
   * List of all Twig functions.
   */
  public function getFunctions() {
    return [
      new \Twig_SimpleFunction('bamboo_file_url_absolute', [
        $this,
        'urlAbsolute',
      ]),
    ];
  }

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

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

  /**
   * Creates a web-accessible URL for a stream to an external or local file.
   *
   * @param string $uri
   *   The URI to a file for which we need an external URL,
   *   or the path to a shipped file.
   *
   * @return string
   *   A string containing a URL that may be used to access the file.
   *   If the provided string already contains a preceding 'http',
   *   'https', or '/', nothing is done and the same string is returned.
   *   If a stream wrapper could not be found to generate an external URL,
   *   then FALSE is returned
   */
  public function urlAbsolute($uri) {
    return file_create_url($uri);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
File::extensionGuesser public function Render a custom date format with Twig.
File::getFilters public function List of all Twig functions.
File::getFunctions public function List of all Twig functions.
File::getName public function Unique identifier for this Twig extension. Overrides TwigExtensionBase::getName
File::urlAbsolute public function Creates a web-accessible URL for a stream to an external or local file.
TwigExtensionBase::getBlockStorage protected function Return the block storage.
TwigExtensionBase::getConfigFactory protected function Provides an interface for a configuration object factory.
TwigExtensionBase::getCurrentRouteMatch protected function Return the current route match.
TwigExtensionBase::getCurrentUser protected function Lazy loading for the Drupal current user account proxy.
TwigExtensionBase::getDateFormatter protected function Provides a service to handle various date related functionality.
TwigExtensionBase::getEntityTypeManager protected function Lazy loading for the Drupal entity type manager.
TwigExtensionBase::getExtensionGuesser protected function Return a singleton mime type to file extension guesser.
TwigExtensionBase::getFieldTypeManager protected function Return the factory for image objects.
TwigExtensionBase::getFileStorage protected function Return the file storage.
TwigExtensionBase::getFileSystemObject protected function Provides helpers to operate on files and stream wrappers.
TwigExtensionBase::getFormBuilder protected function Provides an interface for form building and processing.
TwigExtensionBase::getImageFactory protected function Return the factory for image objects.
TwigExtensionBase::getImageStyleStorage protected function Provides an interface defining an image style.
TwigExtensionBase::getLanguageManager protected function Returns the language manager service.
TwigExtensionBase::getMenuLinkTree protected function Interface for loading, transforming and rendering menu link trees.
TwigExtensionBase::getPluginManagerBlock protected function Manages discovery and instantiation of block plugins.
TwigExtensionBase::getSettingsSingleton protected function Read only settings singleton.
TwigExtensionBase::getStateFactory protected function The state storage service.
TwigExtensionBase::getToken protected function Return the token service.
TwigExtensionBase::getUserStorage protected function Return the user storage.