class Typography

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Theme/Plugin/DesignTokenValue/Typography.php \Drupal\Core\Theme\Plugin\DesignTokenValue\Typography

Typography design token value.

Attributes

#[DesignTokenValue(id: 'typography', label: new TranslatableMarkup('Typography'))]

Hierarchy

Expanded class hierarchy of Typography

2 files declare their use of Typography
DesignTokenValuePluginManagerKernelTest.php in core/tests/Drupal/KernelTests/Core/Theme/DesignToken/DesignTokenValuePluginManagerKernelTest.php
TypographyTest.php in core/tests/Drupal/Tests/Core/Theme/DesignToken/Plugin/TypographyTest.php
6 string references to 'Typography'
core.design_token_values.schema.yml in core/config/schema/core.design_token_values.schema.yml
core/config/schema/core.design_token_values.schema.yml
DesignTokenConfigEntityKernelTest::testConfigSchema in core/tests/Drupal/KernelTests/Core/Theme/DesignToken/DesignTokenConfigEntityKernelTest.php
Tests config schema.
DesignTokenPluginManagerKernelTest::testDetectedPlugins in core/tests/Drupal/KernelTests/Core/Theme/DesignToken/DesignTokenPluginManagerKernelTest.php
Tests that plugins can be provided by YAML files.
DesignTokenValuePluginManagerKernelTest::testDetectedPlugins in core/tests/Drupal/KernelTests/Core/Theme/DesignToken/DesignTokenValuePluginManagerKernelTest.php
Tests detected plugins provided by Core.
DesignTokenValuePluginManagerKernelTest::testDetectedPlugins in core/tests/Drupal/KernelTests/Core/Theme/DesignToken/DesignTokenValuePluginManagerKernelTest.php
Tests detected plugins provided by Core.

... See full list

File

core/lib/Drupal/Core/Theme/Plugin/DesignTokenValue/Typography.php, line 16

Namespace

Drupal\Core\Theme\Plugin\DesignTokenValue
View source
class Typography extends DesignTokenValuePluginBase {
  
  /**
   * The typography's properties.
   *
   * @var array|string[]
   */
  protected array $properties = [
    'fontFamily' => 'fontFamily',
    'fontSize' => 'dimension',
    'fontWeight' => 'fontWeight',
    'letterSpacing' => 'dimension',
    'lineHeight' => 'number',
  ];
  
  /**
   * The typography's font.
   */
  protected FontFamily $fontFamily;
  
  /**
   * The size of the typography.
   */
  protected Dimension $fontSize;
  
  /**
   * The weight of the typography.
   */
  protected FontWeight $fontWeight;
  
  /**
   * The horizontal spacing between characters.
   */
  protected Dimension $letterSpacing;
  
  /**
   * The vertical spacing between lines of typography.
   */
  protected Number $lineHeight;
  public function __construct(array $configuration, $plugin_id, $plugin_definition, #[Autowire(service: 'plugin.manager.design_token_value')] protected DesignTokenValuePluginManagerInterface $designTokenValuePluginManager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
  }
  
  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() : array {
    return [
      'fontFamily' => [],
      'fontSize' => [
        'value' => 0,
        'unit' => 'px',
      ],
      'fontWeight' => '',
      'letterSpacing' => [
        'value' => 0,
        'unit' => 'px',
      ],
      'lineHeight' => 0,
    ] + parent::defaultConfiguration();
  }
  
  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) : static {
    parent::setConfiguration($configuration);
    foreach ($this->properties as $property => $type) {
      $propertyConfig = static::prepareConfiguration($this->configuration[$property]);
      $this->{$property} = $this->designTokenValuePluginManager
        ->createInstance($type, $propertyConfig);
    }
    return $this;
  }
  
  /**
   * {@inheritdoc}
   */
  public function toDtcg() : mixed {
    $data = [];
    foreach ($this->properties as $property => $type) {
      $data[$property] = $this->{$property}
        ->toDtcg();
    }
    return $data;
  }
  
  /**
   * {@inheritdoc}
   */
  public function toCss() : string {
    // letterSpacing is not allowed in the font shortcut.
    return implode(' ', [
      $this->fontWeight
        ->toCss(),
      $this->fontSize
        ->toCss() . '/' . $this->lineHeight
        ->toCss(),
      $this->fontFamily
        ->toCss(),
    ]);
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
AutowiredInstanceTrait::createInstanceAutowired public static function Instantiates a new instance of the implementing class using autowiring.
AutowiredInstanceTrait::getAutowireArguments private static function Resolves arguments for a method using autowiring.
ConfigurableTrait::$configuration protected property Configuration information passed into the plugin.
ConfigurableTrait::getConfiguration public function Gets this plugin's configuration. 3
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
DesignTokenValuePluginBase::prepareConfiguration public static function Prepares configuration for plugin creation. Overrides DesignTokenValueInterface::prepareConfiguration
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin ID.
PluginBase::create public static function Instantiates a new instance of the implementing class using autowiring. 70
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin ID of the plugin instance. Overrides PluginInspectionInterface::getPluginId
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. 1
Typography::$fontFamily protected property The typography's font.
Typography::$fontSize protected property The size of the typography.
Typography::$fontWeight protected property The weight of the typography.
Typography::$letterSpacing protected property The horizontal spacing between characters.
Typography::$lineHeight protected property The vertical spacing between lines of typography.
Typography::$properties protected property The typography's properties.
Typography::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableTrait::defaultConfiguration
Typography::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableTrait::setConfiguration
Typography::toCss public function Exports as CSS value. Overrides DesignTokenValueInterface::toCss
Typography::toDtcg public function Exports as DTCG. Overrides DesignTokenValueInterface::toDtcg
Typography::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides ConfigurablePluginBase::__construct

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.