vendor/pimcore/pimcore/models/DataObject/ClassDefinition/Data/Extension/Text.php line 37

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\DataObject\ClassDefinition\Data\Extension;
  15. use Pimcore\Model;
  16. trait Text
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function checkValidity($data, $omitMandatoryCheck = false, $params = [])
  22. {
  23. if (!$omitMandatoryCheck && $this->getMandatory() && $this->isEmpty($data)) {
  24. throw new Model\Element\ValidationException('Empty mandatory field [ ' . $this->getName() . ' ]');
  25. }
  26. }
  27. /**
  28. * @param string|null $data
  29. *
  30. * @return bool
  31. */
  32. public function isEmpty($data)
  33. {
  34. return strlen($data) < 1;
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function isDiffChangeAllowed($object, $params = [])
  40. {
  41. return true;
  42. }
  43. /**
  44. * @see Data::getVersionPreview
  45. *
  46. * @param string $data
  47. * @param null|Model\DataObject\AbstractObject $object
  48. * @param array $params
  49. *
  50. * @return string
  51. */
  52. public function getVersionPreview($data, $object = null, $params = [])
  53. {
  54. return htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
  55. }
  56. }