Text.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\Element;
  7. /**
  8. * Class Text
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class Text extends \Magento\Framework\View\Element\AbstractBlock
  14. {
  15. /**
  16. * Set text data
  17. *
  18. * @param string $text
  19. * @return $this
  20. */
  21. public function setText($text)
  22. {
  23. $this->setData('text', $text);
  24. return $this;
  25. }
  26. /**
  27. * Retrieve text data
  28. *
  29. * @return string
  30. */
  31. public function getText()
  32. {
  33. return $this->getData('text');
  34. }
  35. /**
  36. * Append text before|after existing text data
  37. *
  38. * @param string $text
  39. * @param bool $before
  40. * @return void
  41. */
  42. public function addText($text, $before = false)
  43. {
  44. if ($before) {
  45. $this->setText($text . $this->getText());
  46. } else {
  47. $this->setText($this->getText() . $text);
  48. }
  49. }
  50. /**
  51. * Render html output
  52. *
  53. * @return string
  54. */
  55. protected function _toHtml()
  56. {
  57. if (!$this->_beforeToHtml()) {
  58. return '';
  59. }
  60. return $this->getText();
  61. }
  62. }