Pimcore\Model\Document\Tag::factory PHP Method

factory() public static method

public static factory ( $type, $name, $documentId, null $config = null, null $controller = null, null $view = null, null $editmode = null ) : mixed
$type
$name
$documentId
$config null
$controller null
$view null
$editmode null
return mixed
    public static function factory($type, $name, $documentId, $config = null, $controller = null, $view = null, $editmode = null)
    {
        $tagClass = "\\Pimcore\\Model\\Document\\Tag\\" . ucfirst($type);
        // this is the fallback for custom document tags using prefixes
        // so we need to check if the class exists first
        if (!\Pimcore\Tool::classExists($tagClass)) {
            $oldStyleClass = "\\Document_Tag_" . ucfirst($type);
            if (\Pimcore\Tool::classExists($oldStyleClass)) {
                $tagClass = $oldStyleClass;
            }
        }
        $tag = new $tagClass();
        $tag->setName($name);
        $tag->setDocumentId($documentId);
        $tag->setController($controller);
        $tag->setView($view);
        $tag->setEditmode($editmode);
        $tag->setOptions($config);
        return $tag;
    }

Usage Example

示例#1
0
 /**
  * @param $type
  * @param $realName
  * @param array $options
  * @return Model\Document\Tag
  */
 public function tag($type, $realName, $options = array())
 {
     $type = strtolower($type);
     $document = $this->document;
     $name = Model\Document\Tag::buildTagName($type, $realName, $document);
     try {
         if ($document instanceof Model\Document\PageSnippet) {
             $tag = $document->getElement($name);
             if ($tag instanceof Model\Document\Tag && $tag->getType() == $type) {
                 // call the load() method if it exists to reinitialize the data (eg. from serializing, ...)
                 if (method_exists($tag, "load")) {
                     $tag->load();
                 }
                 // set view & controller, editmode
                 $tag->setController($this->controller);
                 $tag->setView($this);
                 $tag->setEditmode($this->editmode);
                 $tag->setOptions($options);
             } else {
                 $tag = Model\Document\Tag::factory($type, $name, $document->getId(), $options, $this->controller, $this, $this->editmode);
                 $document->setElement($name, $tag);
             }
             // set the real name of this editable, without the prefixes and suffixes from blocks and areablocks
             $tag->setRealName($realName);
         }
         return $tag;
     } catch (\Exception $e) {
         \Logger::warning($e);
     }
 }
All Usage Examples Of Pimcore\Model\Document\Tag::factory