/** * @Fraym\Annotation\Route("/fraym/dynamic-template/inline-editor-save", name="dynamicTemplateSaveInlineEditor", permission={"\Fraym\User\User"="isAdmin"}) */ public function saveDynamicTemplateInline() { $blockId = $this->request->post('blockId'); // Convert int key to string $configField = json_decode(json_encode((object) $this->request->post('config')), true); // Get the block element $block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($blockId); // Read the xml config from the block $configXml = $this->blockParser->getXmlObjectFromString($this->blockParser->wrapBlockConfig($block)); $config = unserialize($configXml->dynamicTemplateConfig); $config = json_decode(json_encode($config), true); $newConfig = array_replace_recursive($config, $configField); // Create the new config xml date $configXml->dynamicTemplateConfig = serialize($newConfig); $newConfig = $this->blockParser->getBlockConfig($this->blockParser->removeXmlHeader($configXml->asXML())); // Save changes to new change set $changeSet = $this->dynamicTemplate->createChangeSet($block, $newConfig); $this->response->sendAsJson(['blockId' => $block->id, 'data' => $this->blockController->prepareBlockOutput($changeSet)]); }
/** * Save the block configuration received by the client. * * @return bool */ public function saveBlockConfig() { $blockConfigGP = $this->request->getGPAsObject(); $validate = $this->validation->setData($blockConfigGP); $validate->addRule('id', 'numeric')->addRule('menuId', 'numeric')->addRule('contentId', 'notEmpty'); $block = false; $menuItemTranslation = null; if (($result = $validate->check()) === true) { $extension = $this->db->getRepository('\\Fraym\\Block\\Entity\\BlockExtension')->findOneById($blockConfigGP->id); $menu = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($blockConfigGP->menuId); $menuItemTranslation = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItemTranslation')->findOneById($blockConfigGP->menuTranslationId); if (isset($blockConfigGP->currentBlockId)) { $block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($blockConfigGP->currentBlockId); } if ($extension) { if ($block) { $newBlock = new BlockXML(); $newBlock->init($block->config); } else { $newBlock = new BlockXML(); } if (isset($blockConfigGP->excludedDevices)) { $newBlock->setExcludedDevices($blockConfigGP->excludedDevices); } if (isset($blockConfigGP->permissions)) { $newBlock->setPermissions($blockConfigGP->permissions); } $newBlock->setActive($blockConfigGP->active); $newBlock->setCache($blockConfigGP->cache); $newBlock->setMethod($extension->execMethod); $newBlock->setClass($extension->class); if (!empty($blockConfigGP->startDate)) { $date = new \DateTime(date('Y-m-d H:i:s', strtotime($blockConfigGP->startDate))); $newBlock->setStartDate($date); } if (!empty($blockConfigGP->endDate)) { $date = new \DateTime(date('Y-m-d H:i:s', strtotime($blockConfigGP->endDate))); $newBlock->setEndDate($date); } if ($blockConfigGP->template == 'custom') { $newBlock->setTemplate($blockConfigGP->templateContent); $newBlock->setTemplateType('string'); } elseif (empty($blockConfigGP->template)) { $newBlock->setTemplate($blockConfigGP->templateFile); $newBlock->setTemplateType('file'); } else { $newBlock->setTemplateType($blockConfigGP->template); } $saveMethod = $extension->saveMethod; $instance = $this->serviceLocator->get($extension->class); if (empty($block)) { $block = new \Fraym\Block\Entity\Block(); } $blockCount = count($this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findByContentId($blockConfigGP->contentId)); $block->contentId = $blockConfigGP->contentId; $block->position = $block->position ? $block->position : $blockCount; $block->menuItem = isset($blockConfigGP->menu) && $blockConfigGP->menu == '1' ? null : $menu; $block->site = $menu->site; $block->menuItemTranslation = $blockConfigGP->menuTranslation === 'current' ? $menuItemTranslation : null; $block->extension = $extension; $this->db->persist($block); $this->db->flush(); /** * Set configuration for the block output */ $this->locale->setLocale($menuItemTranslation->locale->id); $this->route->setCurrentMenuItem($menu); $this->route->setCurrentMenuItemTranslation($menuItemTranslation); /** * Extension event callback */ if (method_exists($instance, $saveMethod)) { $newBlock = $instance->{$saveMethod}($block->id, $newBlock); } $blockConfig = $this->blockParser->getBlockConfig((string) $newBlock); $block->config = $blockConfig; $this->db->flush(); /** * Save block in history */ if (isset($blockConfigGP->currentBlockId)) { $this->block->saveHistory($block, 'edited'); } else { $this->block->saveHistory($block, 'added'); } $data = $this->prepareBlockOutput($block); $this->response->sendAsJson(array('data' => $data, 'blockId' => $block->id)); } } $this->response->sendAsJson(array('error' => $result)); }