/** * Render the admin form of a widget, if present. * * @param CmsBlock $block Block Entity * @return string Rendered HTML */ public function renderBlockAdminForm(CmsBlock $block) { $widget = WidgetFactory::factory($block); $widget->adminForm(); $adminFormElement = 'Cms.Design/default_admin_form'; if ($this->_View->elementExists($widget->getViewFolderPath() . 'admin_form')) { $adminFormElement = $widget->getViewFolderPath() . 'admin_form'; } $viewVars = Hash::merge(['widget' => $widget, 'block' => $block], $widget->viewVars); return $this->_View->element($adminFormElement, $viewVars); }
/** * Dialog for editing a block * * @param string $id Entity ID * @return void */ public function edit($id = null) { $cmsBlock = $this->CmsBlocks->get($id); $widget = WidgetFactory::factory($cmsBlock); if ($widget->getFullIdentifier() == 'App.FileDownload') { $this->eventManager()->off($this->Csrf); } if ($this->request->is(['patch', 'post', 'put'])) { $cmsBlock = $this->CmsBlocks->patchEntity($cmsBlock, $this->request->data); if ($this->CmsBlocks->save($cmsBlock)) { $this->FrontendBridge->setJson('success', true); } else { $this->Flash->error(__('forms.data_not_saved')); } } $this->set(compact('cmsBlock', 'widget')); $this->FrontendBridge->setJson(compact('cmsBlock')); }
/** * Render the block * * @param Request $request Request * @param View $view Optional View Instance for rendering. * @return string Rendered HTML */ public function render(Request $request, View $view = null) { $widget = WidgetFactory::factory($this); return $widget->render($request, $view); }