Eccube\Controller\Admin\Content\BlockController::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);
        $Block = $app['eccube.repository.block']->findOrCreate($id, $DeviceType);
        if (!$Block) {
            throw new NotFoundHttpException();
        }
        $builder = $app['form.factory']->createBuilder('block', $Block);
        $html = '';
        $previous_filename = null;
        $deletable = $Block->getDeletableFlg();
        if ($id) {
            // テンプレートファイルの取得
            $previous_filename = $Block->getFileName();
            $file = $app['eccube.repository.block']->getReadTemplateFile($previous_filename, $deletable);
            $html = $file['tpl_data'];
        }
        $event = new EventArgs(array('builder' => $builder, 'DeviceType' => $DeviceType, 'Block' => $Block, 'html' => $html), $request);
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CONTENT_BLOCK_EDIT_INITIALIZE, $event);
        $html = $event->getArgument('html');
        $form = $builder->getForm();
        $form->get('block_html')->setData($html);
        if ($app['request']->getMethod() === 'POST') {
            $form->handleRequest($app['request']);
            if ($form->isValid()) {
                $Block = $form->getData();
                // DB登録
                $app['orm.em']->persist($Block);
                $app['orm.em']->flush();
                // ファイル生成・更新
                $tplDir = $app['config']['block_realdir'];
                $filePath = $tplDir . '/' . $Block->getFileName() . '.twig';
                $fs = new Filesystem();
                $blockData = $form->get('block_html')->getData();
                $blockData = Str::convertLineFeed($blockData);
                $fs->dumpFile($filePath, $blockData);
                // 更新でファイル名を変更した場合、以前のファイルを削除
                if ($Block->getFileName() != $previous_filename && !is_null($previous_filename)) {
                    $oldFilePath = $tplDir . '/' . $previous_filename . '.twig';
                    if ($fs->exists($oldFilePath)) {
                        $fs->remove($oldFilePath);
                    }
                }
                \Eccube\Util\Cache::clear($app, false);
                $event = new EventArgs(array('form' => $form, 'Block' => $Block), $request);
                $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CONTENT_BLOCK_EDIT_COMPLETE, $event);
                $app->addSuccess('admin.register.complete', 'admin');
                return $app->redirect($app->url('admin_content_block_edit', array('id' => $Block->getId())));
            }
        }
        return $app->render('Content/block_edit.twig', array('form' => $form->createView(), 'block_id' => $id, 'deletable' => $deletable));
    }
BlockController