vendor/pimcore/pimcore/models/Document/Editable/Input.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 Input extends Model\Document\Editable implements EditmodeDataInterface
  20. {
  21. /**
  22. * Contains the text for this element
  23. *
  24. * @internal
  25. *
  26. * @var string
  27. */
  28. protected $text = '';
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function getType()
  33. {
  34. return 'input';
  35. }
  36. /**
  37. * {@inheritdoc}
  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. return $text;
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function getDataEditmode() /** : mixed */
  66. {
  67. return htmlentities($this->text);
  68. }
  69. /**
  70. * {@inheritdoc}
  71. */
  72. public function setDataFromResource($data)
  73. {
  74. $this->text = $data;
  75. return $this;
  76. }
  77. /**
  78. * {@inheritdoc}
  79. */
  80. public function setDataFromEditmode($data)
  81. {
  82. $data = html_entity_decode($data, ENT_HTML5); // this is because the input is now an div contenteditable -> therefore in entities
  83. $this->text = $data;
  84. return $this;
  85. }
  86. /**
  87. * {@inheritdoc}
  88. */
  89. public function isEmpty()
  90. {
  91. return !(bool) strlen($this->text);
  92. }
  93. }