class FontWeight

Font weight design token value.

Attributes

#[DesignTokenValue(id: 'fontWeight', label: new TranslatableMarkup('Font weight'))]

Hierarchy

Expanded class hierarchy of FontWeight

4 files declare their use of FontWeight
DesignTokenPluginManagerTest.php in core/tests/Drupal/Tests/Core/Theme/DesignToken/DesignTokenPluginManagerTest.php
DesignTokenValuePluginManagerKernelTest.php in core/tests/Drupal/KernelTests/Core/Theme/DesignToken/DesignTokenValuePluginManagerKernelTest.php
FontWeightTest.php in core/tests/Drupal/Tests/Core/Theme/DesignToken/Plugin/FontWeightTest.php
TypographyTest.php in core/tests/Drupal/Tests/Core/Theme/DesignToken/Plugin/TypographyTest.php
15 string references to 'FontWeight'
DesignTokenConfigEntityKernelTest::testConfigSchema in core/tests/Drupal/KernelTests/Core/Theme/DesignToken/DesignTokenConfigEntityKernelTest.php
Tests config schema.
DesignTokenConfigEntityKernelTest::testInvalidConfigSchema in core/tests/Drupal/KernelTests/Core/Theme/DesignToken/DesignTokenConfigEntityKernelTest.php
Tests invalid config schema.
DesignTokenPluginManagerKernelTest::testDetectedPlugins in core/tests/Drupal/KernelTests/Core/Theme/DesignToken/DesignTokenPluginManagerKernelTest.php
Tests that plugins can be provided by YAML files.
DesignTokenPluginManagerTest::getValuePlugins in core/tests/Drupal/Tests/Core/Theme/DesignToken/DesignTokenPluginManagerTest.php
Fake Design token value plugin instances.
DesignTokenPluginManagerTest::providerExtractDefinitions in core/tests/Drupal/Tests/Core/Theme/DesignToken/DesignTokenPluginManagerTest.php
Data provider for ::testExtractDefinitions().

... See full list

File

core/lib/Drupal/Core/Theme/Plugin/DesignTokenValue/FontWeight.php, line 15

Namespace

Drupal\Core\Theme\Plugin\DesignTokenValue
View source
class FontWeight extends DesignTokenValuePluginBase {
  
  /**
   * The font weight value.
   */
  protected int $value;
  
  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() : array {
    return [
      // 0 is not an authorized value, this forces to set an authorized value.
'value' => 0,
    ] + parent::defaultConfiguration();
  }
  
  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) : static {
    parent::setConfiguration($configuration);
    if ($this->configuration['value'] instanceof FontWeightAlias) {
      $this->value = $this->configuration['value']
        ->value();
      return $this;
    }
    if (is_string($this->configuration['value'])) {
      $this->value = FontWeightAlias::from($this->configuration['value'])
        ->value();
      return $this;
    }
    $this->value = (int) $this->configuration['value'];
    return $this;
  }
  
  /**
   * {@inheritdoc}
   */
  public function toDtcg() : mixed {
    return $this->value;
  }
  
  /**
   * {@inheritdoc}
   */
  public function toCss() : string {
    return (string) $this->value;
  }

}

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