vendor/pimcore/pimcore/models/Document/Editable/Textarea.php line 23

Open in your IDE?
  1. <?php
  2. /**
  3. * Pimcore
  4. *
  5. * This source file is available under two different licenses:
  6. * - GNU General Public License version 3 (GPLv3)
  7. * - Pimcore Commercial License (PCL)
  8. * Full copyright and license information is available in
  9. * LICENSE.md which is distributed with this source code.
  10. *
  11. * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12. * @license http://www.pimcore.org/license GPLv3 and PCL
  13. */
  14. namespace Pimcore\Model\Document\Editable;
  15. use Pimcore\Model;
  16. /**
  17. * @method \Pimcore\Model\Document\Editable\Dao getDao()
  18. */
  19. class Textarea extends Model\Document\Editable implements EditmodeDataInterface
  20. {
  21. /**
  22. * Contains the text
  23. *
  24. * @internal
  25. *
  26. * @var string|null
  27. */
  28. protected $text;
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function getType()
  33. {
  34. return 'textarea';
  35. }
  36. /**
  37. * @return mixed
  38. */
  39. public function getData()
  40. {
  41. return $this->text;
  42. }
  43. /**
  44. * @return string
  45. */
  46. public function getText()
  47. {
  48. return $this->getData();
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function frontend()
  54. {
  55. $config = $this->getConfig();
  56. $text = $this->text;
  57. if (!isset($config['htmlspecialchars']) || $config['htmlspecialchars'] !== false) {
  58. $text = htmlspecialchars($this->text);
  59. }
  60. if (isset($config['nl2br']) && $config['nl2br']) {
  61. $text = nl2br($text);
  62. }
  63. return $text;
  64. }
  65. /**
  66. * @return string
  67. */
  68. public function getDataEditmode() /** : mixed */
  69. {
  70. return htmlentities($this->text);
  71. }
  72. /**
  73. * {@inheritdoc}
  74. */
  75. public function setDataFromResource($data)
  76. {
  77. $this->text = $data;
  78. return $this;
  79. }
  80. /**
  81. * {@inheritdoc}
  82. */
  83. public function setDataFromEditmode($data)
  84. {
  85. $data = html_entity_decode($data, ENT_HTML5); // this is because the input is now an div contenteditable -> therefore in entities
  86. $this->text = $data;
  87. return $this;
  88. }
  89. /**
  90. * {@inheritdoc}
  91. */
  92. public function isEmpty()
  93. {
  94. return empty($this->text);
  95. }
  96. }