Number.php

Same filename in this branch
  1. 11.x core/lib/Drupal/Core/Render/Element/Number.php
  2. 11.x core/lib/Drupal/Component/Utility/Number.php
Same filename and directory in other branches
  1. 10 core/lib/Drupal/Core/Render/Element/Number.php
  2. 10 core/lib/Drupal/Component/Utility/Number.php
  3. 9 core/lib/Drupal/Core/Render/Element/Number.php
  4. 9 core/lib/Drupal/Component/Utility/Number.php
  5. 8.9.x core/lib/Drupal/Core/Render/Element/Number.php
  6. 8.9.x core/lib/Drupal/Component/Utility/Number.php
  7. main core/lib/Drupal/Core/Render/Element/Number.php
  8. main core/lib/Drupal/Component/Utility/Number.php

Namespace

Drupal\Core\Theme\Plugin\DesignTokenValue

File

core/lib/Drupal/Core/Theme/Plugin/DesignTokenValue/Number.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Core\Theme\Plugin\DesignTokenValue;

use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Theme\DesignToken\Attribute\DesignTokenValue;
use Drupal\Core\Theme\DesignToken\DesignTokenValuePluginBase;

/**
 * Number design token value.
 */
class Number extends DesignTokenValuePluginBase {
  
  /**
   * Numbers can be positive, negative and have fractions.
   */
  protected int|float $value;
  
  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() : array {
    return [
      'value' => 0,
    ] + parent::defaultConfiguration();
  }
  
  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) : static {
    parent::setConfiguration($configuration);
    $this->value = $this->configuration['value'];
    return $this;
  }
  
  /**
   * {@inheritdoc}
   */
  public function toDtcg() : mixed {
    return $this->value;
  }
  
  /**
   * {@inheritdoc}
   */
  public function toCss() : string {
    return (string) $this->value;
  }

}

Classes

Title Deprecated Summary
Number Number design token value.

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