Eccube\Controller\Admin\Product\ClassNameController::index PHP Method

index() public method

public index ( Application $app, Request $request, $id = null )
$app Eccube\Application
$request Symfony\Component\HttpFoundation\Request
    public function index(Application $app, Request $request, $id = null)
    {
        if ($id) {
            $TargetClassName = $app['eccube.repository.class_name']->find($id);
            if (!$TargetClassName) {
                throw new NotFoundHttpException('商品規格が存在しません');
            }
        } else {
            $TargetClassName = new \Eccube\Entity\ClassName();
        }
        $builder = $app['form.factory']->createBuilder('admin_class_name', $TargetClassName);
        $event = new EventArgs(array('builder' => $builder, 'TargetClassName' => $TargetClassName), $request);
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_CLASS_NAME_INDEX_INITIALIZE, $event);
        $form = $builder->getForm();
        if ($request->getMethod() === 'POST') {
            $form->handleRequest($request);
            if ($form->isValid()) {
                log_info('商品規格登録開始', array($id));
                $status = $app['eccube.repository.class_name']->save($TargetClassName);
                if ($status) {
                    log_info('商品規格登録完了', array($id));
                    $event = new EventArgs(array('form' => $form, 'TargetClassName' => $TargetClassName), $request);
                    $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_CLASS_NAME_INDEX_COMPLETE, $event);
                    $app->addSuccess('admin.class_name.save.complete', 'admin');
                    return $app->redirect($app->url('admin_product_class_name'));
                } else {
                    log_info('商品規格登録エラー', array($id));
                    $app->addError('admin.class_name.save.error', 'admin');
                }
            }
        }
        $ClassNames = $app['eccube.repository.class_name']->getList();
        return $app->render('Product/class_name.twig', array('form' => $form->createView(), 'ClassNames' => $ClassNames, 'TargetClassName' => $TargetClassName));
    }
ClassNameController