AttributeValueBase.php

Definition of Drupal\Core\Template\AttributeValueBase.

Namespace

Drupal\Core\Template

File

drupal/core/lib/Drupal/Core/Template/AttributeValueBase.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of Drupal\Core\Template\AttributeValueBase.
  5. */
  6. namespace Drupal\Core\Template;
  7. /**
  8. * Defines the base class for an attribute type.
  9. *
  10. * @see Drupal\Core\Template\Attribute
  11. */
  12. abstract class AttributeValueBase {
  13. /**
  14. * Whether this attribute hsa been printed already.
  15. *
  16. * @var bool
  17. */
  18. protected $printed = FALSE;
  19. /**
  20. * The value itself.
  21. *
  22. * @var mixed
  23. */
  24. protected $value;
  25. /**
  26. * The name of the value.
  27. *
  28. * @var mixed
  29. */
  30. protected $name;
  31. /**
  32. * Constructs a \Drupal\Core\Template\AttributeValueBase object.
  33. */
  34. public function __construct($name, $value) {
  35. $this->name = $name;
  36. $this->value = $value;
  37. }
  38. /**
  39. * Returns a string representation of the attribute.
  40. *
  41. * While __toString only returns the value in a string form, render()
  42. * contains the name of the attribute as well.
  43. *
  44. * @return string
  45. * The string representation of the attribute.
  46. */
  47. public function render() {
  48. return $this->name . '="' . $this . '"';
  49. }
  50. /**
  51. * Whether this attribute hsa been printed already.
  52. *
  53. * @return bool
  54. * TRUE if this attribute has been printed, FALSE otherwise.
  55. */
  56. public function printed() {
  57. return $this->printed;
  58. }
  59. /**
  60. * Implements the magic __toString() method.
  61. */
  62. abstract function __toString();
  63. }

Classes

Namesort descending Description
AttributeValueBase Defines the base class for an attribute type.