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

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