You are here

class ThemeCompilerTargetContext in Theme Compiler 8

The context used to define common interface parameters for a theme compiler.

Hierarchy

Expanded class hierarchy of ThemeCompilerTargetContext

2 files declare their use of ThemeCompilerTargetContext
RouteHelper.php in src/Routing/RouteHelper.php
ThemeCompilerController.php in src/Controller/ThemeCompilerController.php

File

src/Plugin/ThemeCompilerTargetContext.php, line 8

Namespace

Drupal\theme_compiler\Plugin
View source
class ThemeCompilerTargetContext {

  /**
   * The fully-qualified method name used as the compiler route destination.
   *
   * @var string
   */
  protected $compiler;

  /**
   * An array of compiler plugin target configuration options.
   *
   * @var array
   */
  protected $options;

  /**
   * The theme-relative file system path to use for the compiler target.
   *
   * @var string
   */
  protected $target;

  /**
   * The machine name of the theme to which this context belongs.
   *
   * @var string
   */
  protected $theme;

  /**
   * Constructs a ThemeCompilerTargetContext.
   *
   * @param string $compiler
   *   The machine name of the compiler plugin to use.
   * @param string $theme
   *   The machine name of the theme to which this context should belong.
   * @param string $target
   *   The theme-relative file system path to use for the compiler target.
   * @param array $options
   *   An array of compiler plugin target configuration options.
   */
  public function __construct(string $compiler, string $theme, string $target, array $options) {
    $this->compiler = $compiler;
    $this->options = $options;
    $this->target = ltrim($target, '/');
    $this->theme = $theme;
  }

  /**
   * Get the compiler for this context.
   *
   * @return string
   *   The machine name of the compiler plugin to use.
   */
  public function getCompiler() {
    return $this->compiler;
  }

  /**
   * Get the options for this context.
   *
   * @return array
   *   An array of compiler plugin target configuration options.
   */
  public function getOptions() {
    return $this->options;
  }

  /**
   * Get the theme for this context.
   *
   * @return string
   *   The machine name of the theme to which this context belongs.
   */
  public function getTheme() {
    return $this->theme;
  }

  /**
   * Get the Uniform Resource Identifier path prefix for this context's theme.
   *
   * The output of this method is used to build Drupal route paths to files
   * within this context's theme.
   *
   * @return string
   *   The Uniform Resource Identifier path prefix for this context's theme.
   */
  public function getThemeUriPrefix() {
    return '/' . drupal_get_path('theme', $this->theme);
  }

  /**
   * Get the target for this context.
   *
   * @return string
   *   The theme-relative file system path to use for the compiler target.
   */
  public function getTarget() {
    return $this->target;
  }

  /**
   * Compute a hash of the target for canonical identification purposes.
   *
   * @return string
   *   An identifier for the target of this context.
   */
  public function getTargetId() {
    return hash('sha256', $this
      ->getTargetUri());
  }

  /**
   * Get the Uniform Resource Identifier path for this context's theme target.
   *
   * This method builds the target URI using the theme URI prefix and the
   * theme-relative file system path used to represent the compiler target.
   *
   * @return string
   *   The Uniform Resource Identifier path for this context's theme target.
   */
  public function getTargetUri() {
    return $this
      ->getThemeUriPrefix() . '/' . $this->target;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ThemeCompilerTargetContext::$compiler protected property The fully-qualified method name used as the compiler route destination.
ThemeCompilerTargetContext::$options protected property An array of compiler plugin target configuration options.
ThemeCompilerTargetContext::$target protected property The theme-relative file system path to use for the compiler target.
ThemeCompilerTargetContext::$theme protected property The machine name of the theme to which this context belongs.
ThemeCompilerTargetContext::getCompiler public function Get the compiler for this context.
ThemeCompilerTargetContext::getOptions public function Get the options for this context.
ThemeCompilerTargetContext::getTarget public function Get the target for this context.
ThemeCompilerTargetContext::getTargetId public function Compute a hash of the target for canonical identification purposes.
ThemeCompilerTargetContext::getTargetUri public function Get the Uniform Resource Identifier path for this context's theme target.
ThemeCompilerTargetContext::getTheme public function Get the theme for this context.
ThemeCompilerTargetContext::getThemeUriPrefix public function Get the Uniform Resource Identifier path prefix for this context's theme.
ThemeCompilerTargetContext::__construct public function Constructs a ThemeCompilerTargetContext.