Eccube\Controller\Admin\Content\PageController::edit PHP Метод

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

public edit ( Application $app, Request $request, $id = null )
$app Eccube\Application
$request Symfony\Component\HttpFoundation\Request
    public function edit(Application $app, Request $request, $id = null)
    {
        $DeviceType = $app['eccube.repository.master.device_type']->find(DeviceType::DEVICE_TYPE_PC);
        $PageLayout = $app['eccube.repository.page_layout']->findOrCreate($id, $DeviceType);
        $editable = true;
        $builder = $app['form.factory']->createBuilder('main_edit', $PageLayout);
        $event = new EventArgs(array('builder' => $builder, 'DeviceType' => $DeviceType, 'PageLayout' => $PageLayout), $request);
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CONTENT_PAGE_EDIT_INITIALIZE, $event);
        $form = $builder->getForm();
        // 更新時
        $fileName = null;
        if ($id) {
            // 編集不可ページはURL、ページ名、ファイル名を保持
            if ($PageLayout->getEditFlg() == PageLayout::EDIT_FLG_DEFAULT) {
                $editable = false;
                $PrevPageLayout = clone $PageLayout;
            }
            // テンプレートファイルの取得
            $file = $app['eccube.repository.page_layout']->getReadTemplateFile($PageLayout->getFileName(), $editable);
            $form->get('tpl_data')->setData($file['tpl_data']);
            $fileName = $PageLayout->getFileName();
        }
        if ('POST' === $app['request']->getMethod()) {
            $form->handleRequest($app['request']);
            if ($form->isValid()) {
                $PageLayout = $form->getData();
                if (!$editable) {
                    $PageLayout->setUrl($PrevPageLayout->getUrl())->setFileName($PrevPageLayout->getFileName())->setName($PrevPageLayout->getName());
                }
                // DB登録
                $app['orm.em']->persist($PageLayout);
                $app['orm.em']->flush();
                // ファイル生成・更新
                $templatePath = $app['eccube.repository.page_layout']->getWriteTemplatePath($editable);
                $filePath = $templatePath . '/' . $PageLayout->getFileName() . '.twig';
                $fs = new Filesystem();
                $pageData = $form->get('tpl_data')->getData();
                $pageData = Str::convertLineFeed($pageData);
                $fs->dumpFile($filePath, $pageData);
                // 更新でファイル名を変更した場合、以前のファイルを削除
                if ($PageLayout->getFileName() != $fileName && !is_null($fileName)) {
                    $oldFilePath = $templatePath . '/' . $fileName . '.twig';
                    if ($fs->exists($oldFilePath)) {
                        $fs->remove($oldFilePath);
                    }
                }
                $event = new EventArgs(array('form' => $form, 'PageLayout' => $PageLayout, 'templatePath' => $templatePath, 'filePath' => $filePath), $request);
                $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CONTENT_PAGE_EDIT_COMPLETE, $event);
                $app->addSuccess('admin.register.complete', 'admin');
                // twig キャッシュの削除.
                $finder = Finder::create()->in($app['config']['root_dir'] . '/app/cache/twig');
                $fs->remove($finder);
                return $app->redirect($app->url('admin_content_page_edit', array('id' => $PageLayout->getId())));
            }
        }
        $templatePath = $app['eccube.repository.page_layout']->getWriteTemplatePath($editable);
        return $app->render('Content/page_edit.twig', array('form' => $form->createView(), 'page_id' => $PageLayout->getId(), 'editable' => $editable, 'template_path' => $templatePath));
    }