vendor/pimcore/pimcore/models/Document/Editable.php line 623

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 Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  * @category   Pimcore
  12.  * @package    Document
  13.  *
  14.  * @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  15.  * @license    http://www.pimcore.org/license     GPLv3 and PEL
  16.  */
  17. namespace Pimcore\Model\Document;
  18. use Pimcore\Document\Editable\Block\BlockName;
  19. use Pimcore\Document\Editable\Block\BlockState;
  20. use Pimcore\Document\Editable\Block\BlockStateStack;
  21. use Pimcore\Document\Tag\NamingStrategy\NamingStrategyInterface;
  22. use Pimcore\Event\DocumentEvents;
  23. use Pimcore\Event\Model\Document\EditableNameEvent;
  24. use Pimcore\Logger;
  25. use Pimcore\Model;
  26. use Pimcore\Model\Document;
  27. use Pimcore\Model\Document\Targeting\TargetingDocumentInterface;
  28. use Pimcore\Model\Webservice;
  29. use Pimcore\Templating\Model\ViewModel;
  30. use Pimcore\Templating\Model\ViewModelInterface;
  31. use Pimcore\Tool\HtmlUtils;
  32. /**
  33.  * @method \Pimcore\Model\Document\Editable\Dao getDao()
  34.  * @method void save()
  35.  * @method void delete()
  36.  */
  37. abstract class Editable extends Model\AbstractModel implements Model\Document\Editable\EditableInterface
  38. {
  39.     /**
  40.      * Options of the current tag, can contain some configurations for the editmode, or the thumbnail name, ...
  41.      *
  42.      * @var array
  43.      *
  44.      * @deprecated will be removed in Pimcore 10. use $config instead
  45.      */
  46.     protected $options;
  47.     /**
  48.      * Contains some configurations for the editmode, or the thumbnail name, ...
  49.      *
  50.      * @var array
  51.      */
  52.     protected $config;
  53.     /**
  54.      * @var string
  55.      */
  56.     protected $name;
  57.     /**
  58.      * Contains the real name of the editable without the prefixes and suffixes
  59.      * which are generated automatically by blocks and areablocks
  60.      *
  61.      * @var string
  62.      */
  63.     protected $realName;
  64.     /**
  65.      * Contains parent hierarchy names (used when building elements inside a block/areablock hierarchy)
  66.      *
  67.      * @var array
  68.      */
  69.     private $parentBlockNames = [];
  70.     /**
  71.      * Element belongs to the ID of the document
  72.      *
  73.      * @var int
  74.      */
  75.     protected $documentId;
  76.     /**
  77.      * Element belongs to the document
  78.      *
  79.      * @var Document\PageSnippet|null
  80.      */
  81.     protected $document;
  82.     /**
  83.      * @deprecated Unused - will be removed in Pimcore 10.0
  84.      *
  85.      * @var string|null
  86.      */
  87.     protected $controller;
  88.     /**
  89.      * @var ViewModelInterface|null
  90.      *
  91.      * @deprecated
  92.      */
  93.     protected $view;
  94.     /**
  95.      * In Editmode or not
  96.      *
  97.      * @var bool
  98.      */
  99.     protected $editmode;
  100.     /**
  101.      * @var bool
  102.      */
  103.     protected $inherited false;
  104.     public function __construct()
  105.     {
  106.         $this->options = & $this->config;
  107.     }
  108.     /**
  109.      * @var string
  110.      */
  111.     protected $inDialogBox null;
  112.     /**
  113.      * @deprecated Will be removed in Pimcore, use EditableLoader instead
  114.      *
  115.      * @param string $type
  116.      * @param string $name
  117.      * @param int $documentId
  118.      * @param array|null $config
  119.      * @param string|null $controller
  120.      * @param ViewModel|null $view
  121.      * @param bool|null $editmode
  122.      *
  123.      * @return Editable
  124.      */
  125.     public static function factory($type$name$documentId$config null$controller null$view null$editmode null)
  126.     {
  127.         $loader = \Pimcore::getContainer()->get(Document\Editable\Loader\EditableLoader::class);
  128.         /** @var Editable $editable */
  129.         $editable $loader->build($type);
  130.         $editable->setName($name);
  131.         $editable->setDocumentId($documentId);
  132.         $editable->setController($controller);
  133.         if (!$view) {
  134.             // needed for the RESTImporter. For areabricks define a default implementation. Otherwise cannot find a tag handler.
  135.             $view = new ViewModel();
  136.         }
  137.         $editable->setView($view);
  138.         $editable->setEditmode($editmode);
  139.         $editable->setConfig($config);
  140.         return $editable;
  141.     }
  142.     /**
  143.      * @return string|void
  144.      *
  145.      * @throws \Exception
  146.      */
  147.     public function admin()
  148.     {
  149.         $options $this->getEditmodeOptions();
  150.         $code $this->outputEditmodeOptions($optionstrue);
  151.         $attributes $this->getEditmodeElementAttributes($options);
  152.         $attributeString HtmlUtils::assembleAttributeString($attributes);
  153.         $htmlContainerCode = ('<div ' $attributeString '></div>');
  154.         if ($this->isInDialogBox()) {
  155.             $htmlContainerCode $this->wrapEditmodeContainerCodeForDialogBox($attributes['id'], $htmlContainerCode);
  156.         }
  157.         $code .= $htmlContainerCode;
  158.         return $code;
  159.     }
  160.     /**
  161.      * @param string $id
  162.      * @param string $code
  163.      *
  164.      * @return string
  165.      */
  166.     protected function wrapEditmodeContainerCodeForDialogBox(string $idstring $code): string
  167.     {
  168.         $code '<template id="template__' $id '">' $code '</template>';
  169.         return $code;
  170.     }
  171.     /**
  172.      * Builds options passed to editmode frontend as JSON config
  173.      *
  174.      * @return array
  175.      */
  176.     protected function getEditmodeOptions(): array
  177.     {
  178.         $options = [
  179.             // we don't use : and . in IDs (although it's allowed in HTML spec)
  180.             // because they are used in CSS syntax and therefore can't be used in querySelector()
  181.             'id' => 'pimcore_editable_' str_replace([':''.'], '_'$this->getName()),
  182.             'name' => $this->getName(),
  183.             'realName' => $this->getRealName(),
  184.             'config' => $this->getConfig(),
  185.             'data' => $this->getEditmodeData(),
  186.             'type' => $this->getType(),
  187.             'inherited' => $this->getInherited(),
  188.             'inDialogBox' => $this->getInDialogBox(),
  189.         ];
  190.         return $options;
  191.     }
  192.     /**
  193.      * Builds data used for editmode
  194.      *
  195.      * @return mixed
  196.      */
  197.     protected function getEditmodeData()
  198.     {
  199.         // get configuration data for admin
  200.         if (method_exists($this'getDataEditmode')) {
  201.             $data $this->getDataEditmode();
  202.         } else {
  203.             $data $this->getData();
  204.         }
  205.         return $data;
  206.     }
  207.     /**
  208.      * Builds attributes used on the editmode HTML element
  209.      *
  210.      * @param array $options
  211.      *
  212.      * @return array
  213.      */
  214.     protected function getEditmodeElementAttributes(array $options): array
  215.     {
  216.         if (!isset($options['id'])) {
  217.             throw new \RuntimeException(sprintf('Expected an "id" option to be set on the "%s" editable options array'$this->getName()));
  218.         }
  219.         $attributes array_merge($this->getEditmodeBlockStateAttributes(), [
  220.             'id' => $options['id'],
  221.             'class' => implode(' '$this->getEditmodeElementClasses()),
  222.         ]);
  223.         return $attributes;
  224.     }
  225.     protected function getEditmodeBlockStateAttributes(): array
  226.     {
  227.         $blockState $this->getBlockState();
  228.         $blockNames array_map(function (BlockName $blockName) {
  229.             return $blockName->getRealName();
  230.         }, $blockState->getBlocks());
  231.         $attributes = [
  232.             'data-name' => $this->getName(),
  233.             'data-real-name' => $this->getRealName(),
  234.             'data-type' => $this->getType(),
  235.             'data-block-names' => implode(', '$blockNames),
  236.             'data-block-indexes' => implode(', '$blockState->getIndexes()),
  237.         ];
  238.         return $attributes;
  239.     }
  240.     /**
  241.      * Builds classes used on the editmode HTML element
  242.      *
  243.      * @return array
  244.      */
  245.     protected function getEditmodeElementClasses(): array
  246.     {
  247.         $classes = [
  248.             'pimcore_editable',
  249.             'pimcore_tag_' $this->getType(),
  250.             'pimcore_editable_' $this->getType(),
  251.         ];
  252.         $editableConfig $this->getConfig();
  253.         if (isset($editableConfig['class'])) {
  254.             if (is_array($editableConfig['class'])) {
  255.                 $classes array_merge($classes$editableConfig['class']);
  256.             } else {
  257.                 $classes[] = (string)$editableConfig['class'];
  258.             }
  259.         }
  260.         return $classes;
  261.     }
  262.     /**
  263.      * Sends data to the output stream
  264.      *
  265.      * @param string $value
  266.      */
  267.     protected function outputEditmode($value)
  268.     {
  269.         if ($this->getEditmode()) {
  270.             echo $value "\n";
  271.         }
  272.     }
  273.     /**
  274.      * Push editmode options into the JS config array
  275.      *
  276.      * @param array $options
  277.      * @param bool $return
  278.      *
  279.      * @return string|void
  280.      */
  281.     protected function outputEditmodeOptions(array $options$return false)
  282.     {
  283.         // filter all non-scalar values before we pass them to the config object (JSON)
  284.         $clean = function ($value) use (&$clean) {
  285.             if (is_array($value)) {
  286.                 foreach ($value as &$item) {
  287.                     $item $clean($item);
  288.                 }
  289.             } elseif (!is_scalar($value)) {
  290.                 $value null;
  291.             }
  292.             return $value;
  293.         };
  294.         $options $clean($options);
  295.         $code '
  296.             <script>
  297.                 editableDefinitions.push(' json_encode($optionsJSON_PRETTY_PRINT) . ');
  298.             </script>
  299.         ';
  300.         if (json_last_error()) {
  301.             throw new \Exception('json encode failed: ' json_last_error_msg());
  302.         }
  303.         if ($return) {
  304.             return $code;
  305.         }
  306.         $this->outputEditmode($code);
  307.         return;
  308.     }
  309.     /**
  310.      * @return mixed
  311.      */
  312.     public function getValue()
  313.     {
  314.         return $this->getData();
  315.     }
  316.     /**
  317.      * @return string
  318.      */
  319.     public function getName()
  320.     {
  321.         return $this->name;
  322.     }
  323.     /**
  324.      * @param string $name
  325.      *
  326.      * @return $this
  327.      */
  328.     public function setName($name)
  329.     {
  330.         $this->name $name;
  331.         return $this;
  332.     }
  333.     /**
  334.      * @param int $id
  335.      *
  336.      * @return $this
  337.      */
  338.     public function setDocumentId($id)
  339.     {
  340.         $this->documentId = (int) $id;
  341.         if ($this->document instanceof PageSnippet && $this->document->getId() !== $this->documentId) {
  342.             $this->document null;
  343.         }
  344.         return $this;
  345.     }
  346.     /**
  347.      * @return int
  348.      */
  349.     public function getDocumentId()
  350.     {
  351.         return $this->documentId;
  352.     }
  353.     /**
  354.      * @param Document\PageSnippet $document
  355.      *
  356.      * @return $this
  357.      */
  358.     public function setDocument(Document\PageSnippet $document)
  359.     {
  360.         $this->document $document;
  361.         $this->documentId = (int) $document->getId();
  362.         return $this;
  363.     }
  364.     /**
  365.      * @return Document\PageSnippet
  366.      */
  367.     public function getDocument()
  368.     {
  369.         if (!$this->document) {
  370.             $this->document Document\PageSnippet::getById($this->documentId);
  371.         }
  372.         return $this->document;
  373.     }
  374.     /**
  375.      * @return array
  376.      *
  377.      * @deprecated will be removed in Pimcore 10. Use getConfig() instead.
  378.      */
  379.     public function getOptions()
  380.     {
  381.         return $this->getConfig();
  382.     }
  383.     /**
  384.      * @param array $options
  385.      *
  386.      * @return $this
  387.      *
  388.      * @deprecated will be removed in Pimcore 10. Use setConfig() instead.
  389.      */
  390.     public function setOptions($options)
  391.     {
  392.         return $this->setConfig($options);
  393.     }
  394.     /**
  395.      * @return array
  396.      */
  397.     public function getConfig()
  398.     {
  399.         return is_array($this->config) ? $this->config : [];
  400.     }
  401.     /**
  402.      * @param array $config
  403.      *
  404.      * @return $this
  405.      */
  406.     public function setConfig($config)
  407.     {
  408.         $this->config $config;
  409.         return $this;
  410.     }
  411.     /**
  412.      * @param string $name
  413.      * @param mixed $value
  414.      *
  415.      * @return self
  416.      */
  417.     public function addConfig(string $name$value): self
  418.     {
  419.         if (!is_array($this->config)) {
  420.             $this->config = [];
  421.         }
  422.         $this->config[$name] = $value;
  423.         return $this;
  424.     }
  425.     /**
  426.      * @deprecated
  427.      *
  428.      * @param string $name
  429.      * @param mixed $value
  430.      *
  431.      * @return self
  432.      */
  433.     public function setOption(string $name$value): self
  434.     {
  435.         if (!is_array($this->options)) {
  436.             $this->options = [];
  437.         }
  438.         $this->options[$name] = $value;
  439.         return $this;
  440.     }
  441.     /**
  442.      * @deprecated
  443.      *
  444.      * @param string|null $controller
  445.      *
  446.      * @return $this
  447.      */
  448.     public function setController($controller)
  449.     {
  450.         $this->controller $controller;
  451.         return $this;
  452.     }
  453.     /**
  454.      * @deprecated
  455.      *
  456.      * @return string|null
  457.      */
  458.     public function getController()
  459.     {
  460.         return $this->controller;
  461.     }
  462.     /**
  463.      * @param ViewModelInterface $view
  464.      *
  465.      * @return $this
  466.      *
  467.      * @deprecated
  468.      */
  469.     public function setView($view)
  470.     {
  471.         $this->view $view;
  472.         return $this;
  473.     }
  474.     /**
  475.      * @return ViewModelInterface
  476.      *
  477.      * @deprecated
  478.      */
  479.     public function getView()
  480.     {
  481.         return $this->view;
  482.     }
  483.     /**
  484.      * @return string
  485.      */
  486.     public function getRealName()
  487.     {
  488.         return $this->realName;
  489.     }
  490.     /**
  491.      * @param string $realName
  492.      */
  493.     public function setRealName($realName)
  494.     {
  495.         $this->realName $realName;
  496.     }
  497.     final public function setParentBlockNames($parentNames)
  498.     {
  499.         if (is_array($parentNames)) {
  500.             // unfortunately we cannot make a type hint here, because of compatibility reasons
  501.             // old versions where 'parentBlockNames' was not excluded in __sleep() have still this property
  502.             // in the serialized data, and mostly with the value NULL, on restore this would lead to an error
  503.             $this->parentBlockNames $parentNames;
  504.         }
  505.     }
  506.     final public function getParentBlockNames(): array
  507.     {
  508.         return $this->parentBlockNames;
  509.     }
  510.     /**
  511.      * Returns only the properties which should be serialized
  512.      *
  513.      * @return array
  514.      */
  515.     public function __sleep()
  516.     {
  517.         $finalVars = [];
  518.         $parentVars parent::__sleep();
  519.         $blockedVars = ['controller''view''editmode''options''config''parentBlockNames''document'];
  520.         foreach ($parentVars as $key) {
  521.             if (!in_array($key$blockedVars)) {
  522.                 $finalVars[] = $key;
  523.             }
  524.         }
  525.         return $finalVars;
  526.     }
  527.     public function __clone()
  528.     {
  529.         parent::__clone();
  530.         $this->view null;
  531.         $this->document null;
  532.     }
  533.     /**
  534.      * direct output to the frontend
  535.      *
  536.      * @return string
  537.      */
  538.     public function render()
  539.     {
  540.         if ($this->editmode) {
  541.             return $this->admin();
  542.         }
  543.         return $this->frontend();
  544.     }
  545.     /**
  546.      * direct output to the frontend
  547.      *
  548.      * @return string
  549.      */
  550.     public function __toString()
  551.     {
  552.         $result '';
  553.         try {
  554.             $result $this->render();
  555.         } catch (\Throwable $e) {
  556.             if (\Pimcore::inDebugMode()) {
  557.                 // the __toString method isn't allowed to throw exceptions
  558.                 $result '<b style="color:#f00">' $e->getMessage().'</b><br/>'.$e->getTraceAsString();
  559.                 return $result;
  560.             }
  561.             Logger::error('toString() returned an exception: {exception}', [
  562.                 'exception' => $e,
  563.             ]);
  564.             return '';
  565.         }
  566.         if (is_string($result) || is_numeric($result)) {
  567.             // we have to cast to string, because int/float is not auto-converted and throws an exception
  568.             return (string) $result;
  569.         }
  570.         return '';
  571.     }
  572.     /**
  573.      * @return bool
  574.      */
  575.     public function getEditmode()
  576.     {
  577.         return $this->editmode;
  578.     }
  579.     /**
  580.      * @param bool $editmode
  581.      *
  582.      * @return $this
  583.      */
  584.     public function setEditmode($editmode)
  585.     {
  586.         $this->editmode = (bool) $editmode;
  587.         return $this;
  588.     }
  589.     /**
  590.      * @return mixed
  591.      */
  592.     public function getDataForResource()
  593.     {
  594.         $this->checkValidity();
  595.         return $this->getData();
  596.     }
  597.     /**
  598.      * @param Model\Document\PageSnippet $ownerDocument
  599.      * @param array $tags
  600.      *
  601.      * @return array
  602.      */
  603.     public function getCacheTags($ownerDocument$tags = [])
  604.     {
  605.         return $tags;
  606.     }
  607.     /**
  608.      * This is a dummy and is mostly implemented by relation types
  609.      */
  610.     public function resolveDependencies()
  611.     {
  612.         return [];
  613.     }
  614.     /**
  615.      * Receives a standard class object from webservice import and fills the current editable's data
  616.      *
  617.      * @abstract
  618.      *
  619.      * @deprecated
  620.      *
  621.      * @param Webservice\Data\Document\Element $wsElement
  622.      * @param Model\Document\PageSnippet $document
  623.      * @param array $params
  624.      * @param Model\Webservice\IdMapperInterface|null $idMapper
  625.      */
  626.     public function getFromWebserviceImport($wsElement$document null$params = [], $idMapper null)
  627.     {
  628.     }
  629.     /**
  630.      * Returns the current editable's data for web service export
  631.      *
  632.      * @deprecated
  633.      *
  634.      * @param Model\Document\PageSnippet|null $document
  635.      * @param array $params
  636.      * @abstract
  637.      *
  638.      * @return mixed
  639.      */
  640.     public function getForWebserviceExport($document null$params = [])
  641.     {
  642.         $keys get_object_vars($this);
  643.         $el = [];
  644.         foreach ($keys as $key => $value) {
  645.             if ($value instanceof Model\Element\ElementInterface) {
  646.                 $value $value->getId();
  647.             }
  648.             $className Webservice\Data\Mapper::findWebserviceClass($value'out');
  649.             $el[$key] = Webservice\Data\Mapper::map($value$className'out');
  650.         }
  651.         unset($el['dao']);
  652.         unset($el['documentId']);
  653.         unset($el['document']);
  654.         unset($el['controller']);
  655.         unset($el['view']);
  656.         unset($el['editmode']);
  657.         $el Webservice\Data\Mapper::toObject($el);
  658.         return $el;
  659.     }
  660.     /**
  661.      * @return bool
  662.      */
  663.     public function checkValidity()
  664.     {
  665.         return true;
  666.     }
  667.     /**
  668.      * @param bool $inherited
  669.      *
  670.      * @return $this
  671.      */
  672.     public function setInherited($inherited)
  673.     {
  674.         $this->inherited $inherited;
  675.         return $this;
  676.     }
  677.     /**
  678.      * @return bool
  679.      */
  680.     public function getInherited()
  681.     {
  682.         return $this->inherited;
  683.     }
  684.     /**
  685.      * TODO inject block state via DI
  686.      *
  687.      * @return BlockState
  688.      */
  689.     protected function getBlockState(): BlockState
  690.     {
  691.         return \Pimcore::getContainer()->get(BlockStateStack::class)->getCurrentState();
  692.     }
  693.     /**
  694.      * Builds a tag name for an editable, taking current
  695.      * block state (block, index) and targeting into account.
  696.      *
  697.      * @param string $type
  698.      * @param string $name
  699.      * @param Document|null $document
  700.      *
  701.      * @return string
  702.      *
  703.      * @throws \Exception
  704.      *
  705.      * @deprecated since v6.8 and will be removed in Pimcore 10. use buildEditableName() instead
  706.      */
  707.     public static function buildTagName(string $typestring $nameDocument $document null)
  708.     {
  709.         return self::buildEditableName($type$name$document);
  710.     }
  711.     /**
  712.      * Builds an editable name for an editable, taking current
  713.      * block state (block, index) and targeting into account.
  714.      *
  715.      * @param string $type
  716.      * @param string $name
  717.      * @param Document|null $document
  718.      *
  719.      * @return string
  720.      *
  721.      * @throws \Exception
  722.      */
  723.     public static function buildEditableName(string $typestring $nameDocument $document null)
  724.     {
  725.         // do NOT allow dots (.) and colons (:) here as they act as delimiters
  726.         // for block hierarchy in the new naming scheme (see #1467)!
  727.         if (!preg_match("@^[a-zA-Z0-9\-_]+$@"$name)) {
  728.             throw new \InvalidArgumentException(
  729.                 'Only valid CSS class selectors are allowed as the name for an editable (which is basically [a-zA-Z0-9\-_]+). Your name was: ' $name
  730.             );
  731.         }
  732.         // @todo add document-id to registry key | for example for embeded snippets
  733.         // set suffixes if the editable is inside a block
  734.         $container = \Pimcore::getContainer();
  735.         $blockState $container->get(BlockStateStack::class)->getCurrentState();
  736.         /**
  737.          * @var NamingStrategyInterface
  738.          */
  739.         $namingStrategy $container->get('pimcore.document.tag.naming.strategy');
  740.         // if element not nested inside a hierarchical element (e.g. block), add the
  741.         // targeting prefix if configured on the document. hasBlocks() determines if
  742.         // there are any parent blocks for the current element
  743.         $targetGroupEditableName null;
  744.         if ($document && $document instanceof TargetingDocumentInterface) {
  745.             $targetGroupEditableName $document->getTargetGroupEditableName($name);
  746.             if (!$blockState->hasBlocks()) {
  747.                 $name $targetGroupEditableName;
  748.             }
  749.         }
  750.         $editableName $namingStrategy->buildTagName($name$type$blockState$targetGroupEditableName);
  751.         $event = new EditableNameEvent($type$name$blockState$editableName$document);
  752.         \Pimcore::getEventDispatcher()->dispatch(DocumentEvents::EDITABLE_NAME$event);
  753.         $editableName $event->getEditableName();
  754.         if (strlen($editableName) > 750) {
  755.             throw new \Exception(sprintf(
  756.                 'Composite name for editable "%s" is longer than 750 characters. Use shorter names for your editables or reduce amount of nesting levels. Name is: %s',
  757.                 $name,
  758.                 $editableName
  759.             ));
  760.         }
  761.         return $editableName;
  762.     }
  763.     /**
  764.      * This is a wrapper around \Pimcore\Document\Tag\NamingStrategy\NamingStrategyInterface::buildChildElementTagName()
  765.      * which will be exclusively used by Pimcore 10 to build the name of an editable. Use that if you want to support both v6.9 and v10
  766.      *
  767.      * @param string $name
  768.      * @param string $type
  769.      * @param array $parentBlockNames
  770.      * @param int $index
  771.      *
  772.      * @return string
  773.      *
  774.      * @throws \Exception
  775.      */
  776.     public static function buildChildEditableName(string $namestring $type, array $parentBlockNamesint $index): string
  777.     {
  778.         /**
  779.          * @var NamingStrategyInterface $namingStrategy
  780.          */
  781.         $namingStrategy = \Pimcore::getContainer()->get('pimcore.document.tag.naming.strategy');
  782.         return $namingStrategy->buildChildElementTagName($name$type$parentBlockNames$index);
  783.     }
  784.     /**
  785.      * @param string $name
  786.      * @param Document $document
  787.      *
  788.      * @return string
  789.      *
  790.      * @deprecated since v6.8 and will be removed in Pimcore 10. Use buildEditableRealName() instead
  791.      */
  792.     public static function buildTagRealName(string $nameDocument $document): string
  793.     {
  794.         return self::buildEditableRealName($name$document);
  795.     }
  796.     /**
  797.      * @param string $name
  798.      * @param Document $document
  799.      *
  800.      * @return string
  801.      */
  802.     public static function buildEditableRealName(string $nameDocument $document): string
  803.     {
  804.         $blockState = \Pimcore::getContainer()->get(BlockStateStack::class)->getCurrentState();
  805.         // if element not nested inside a hierarchical element (e.g. block), add the
  806.         // targeting prefix if configured on the document. hasBlocks() determines if
  807.         // there are any parent blocks for the current element
  808.         if ($document instanceof TargetingDocumentInterface && !$blockState->hasBlocks()) {
  809.             $name $document->getTargetGroupEditableName($name);
  810.         }
  811.         return $name;
  812.     }
  813.     /**
  814.      * @deprecated
  815.      *
  816.      * @param array|object $data
  817.      *
  818.      * @return object
  819.      */
  820.     public function sanitizeWebserviceData($data)
  821.     {
  822.         if (is_array($data)) {
  823.             $data = (object) $data;
  824.         }
  825.         return $data;
  826.     }
  827.     /**
  828.      * @return bool
  829.      */
  830.     public function isInDialogBox(): bool
  831.     {
  832.         return (bool) $this->inDialogBox;
  833.     }
  834.     /**
  835.      * @return string|null
  836.      */
  837.     public function getInDialogBox(): ?string
  838.     {
  839.         return $this->inDialogBox;
  840.     }
  841.     /**
  842.      * @param string|null $inDialogBox
  843.      *
  844.      * @return $this
  845.      */
  846.     public function setInDialogBox(?string $inDialogBox): self
  847.     {
  848.         $this->inDialogBox $inDialogBox;
  849.         return $this;
  850.     }
  851. }
  852. class_alias(Editable::class, 'Pimcore\Model\Document\Tag');