vendor/pimcore/pimcore/models/Document/Editable/Multiselect.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 Multiselect extends Model\Document\Editable implements EditmodeDataInterface
  21. {
  22.     /**
  23.      * Contains the current selected values
  24.      *
  25.      * @internal
  26.      *
  27.      */
  28.     protected array $values = [];
  29.     public function getType(): string
  30.     {
  31.         return 'multiselect';
  32.     }
  33.     public function getData(): mixed
  34.     {
  35.         return $this->values;
  36.     }
  37.     public function getValues(): array
  38.     {
  39.         return $this->getData();
  40.     }
  41.     public function frontend()
  42.     {
  43.         return implode(','$this->values);
  44.     }
  45.     public function getDataEditmode(): array
  46.     {
  47.         return $this->values;
  48.     }
  49.     public function setDataFromResource(mixed $data): static
  50.     {
  51.         $this->values \Pimcore\Tool\Serialize::unserialize($data);
  52.         return $this;
  53.     }
  54.     public function setDataFromEditmode(mixed $data): static
  55.     {
  56.         if (empty($data)) {
  57.             $this->values = [];
  58.         } elseif (is_string($data)) {
  59.             $this->values explode(','$data);
  60.         } elseif (is_array($data)) {
  61.             $this->values $data;
  62.         }
  63.         return $this;
  64.     }
  65.     public function isEmpty(): bool
  66.     {
  67.         return empty($this->values);
  68.     }
  69. }