Admin_ObjectController::addAction PHP Метод

addAction() публичный Метод

public addAction ( )
    public function addAction()
    {
        $success = false;
        $className = "Pimcore\\Model\\Object\\" . ucfirst($this->getParam("className"));
        $parent = Object::getById($this->getParam("parentId"));
        $message = "";
        if ($parent->isAllowed("create")) {
            $intendedPath = $parent->getRealFullPath() . "/" . $this->getParam("key");
            if (!Object\Service::pathExists($intendedPath)) {
                $object = \Pimcore::getDiContainer()->make($className);
                if ($object instanceof Object\Concrete) {
                    $object->setOmitMandatoryCheck(true);
                    // allow to save the object although there are mandatory fields
                }
                if ($this->getParam("variantViaTree")) {
                    $parentId = $this->getParam("parentId");
                    $parent = Object::getById($parentId);
                    $object->setClassId($parent->getClass()->getId());
                } else {
                    $object->setClassId($this->getParam("classId"));
                }
                $object->setClassName($this->getParam("className"));
                $object->setParentId($this->getParam("parentId"));
                $object->setKey($this->getParam("key"));
                $object->setCreationDate(time());
                $object->setUserOwner($this->getUser()->getId());
                $object->setUserModification($this->getUser()->getId());
                $object->setPublished(false);
                if ($this->getParam("objecttype") == Object\AbstractObject::OBJECT_TYPE_OBJECT || $this->getParam("objecttype") == Object\AbstractObject::OBJECT_TYPE_VARIANT) {
                    $object->setType($this->getParam("objecttype"));
                }
                try {
                    $object->save();
                    $success = true;
                } catch (\Exception $e) {
                    $this->_helper->json(["success" => false, "message" => $e->getMessage()]);
                }
            } else {
                $message = "prevented creating object because object with same path+key already exists";
                Logger::debug($message);
            }
        } else {
            $message = "prevented adding object because of missing permissions";
            Logger::debug($message);
        }
        if ($success) {
            $this->_helper->json(["success" => $success, "id" => $object->getId(), "type" => $object->getType(), "message" => $message]);
        } else {
            $this->_helper->json(["success" => $success, "message" => $message]);
        }
    }