abstract class AttributeValueBase

Defines the base class for an attribute type.

Hierarchy

Expanded class hierarchy of AttributeValueBase

See also

Drupal\Core\Template\Attribute

File

drupal/core/lib/Drupal/Core/Template/AttributeValueBase.php, line 15
Definition of Drupal\Core\Template\AttributeValueBase.

Namespace

Drupal\Core\Template
View source
abstract class AttributeValueBase {

  /**
   * Whether this attribute hsa been printed already.
   *
   * @var bool
   */
  protected $printed = FALSE;

  /**
   * The value itself.
   *
   * @var mixed
   */
  protected $value;

  /**
   * The name of the value.
   *
   * @var mixed
   */
  protected $name;

  /**
   * Constructs a \Drupal\Core\Template\AttributeValueBase object.
   */
  public function __construct($name, $value) {
    $this->name = $name;
    $this->value = $value;
  }

  /**
   * Returns a string representation of the attribute.
   *
   * While __toString only returns the value in a string form, render()
   * contains the name of the attribute as well.
   *
   * @return string
   *   The string representation of the attribute.
   */
  public function render() {
    return $this->name . '="' . $this . '"';
  }

  /**
   * Whether this attribute hsa been printed already.
   *
   * @return bool
   *   TRUE if this attribute has been printed, FALSE otherwise.
   */
  public function printed() {
    return $this->printed;
  }

  /**
   * Implements the magic __toString() method.
   */
  abstract function __toString();

}

Members

Namesort descending Modifiers Type Description Overrides
AttributeValueBase::$name protected property The name of the value.
AttributeValueBase::$printed protected property Whether this attribute hsa been printed already.
AttributeValueBase::$value protected property The value itself.
AttributeValueBase::printed public function Whether this attribute hsa been printed already.
AttributeValueBase::render public function Returns a string representation of the attribute. 1
AttributeValueBase::__construct public function Constructs a \Drupal\Core\Template\AttributeValueBase object.
AttributeValueBase::__toString abstract function Implements the magic __toString() method. 3