/** * 管理画面:カテゴリ登録画面に, カテゴリコンテンツのフォームを追加する. * * @param EventArgs $event */ public function onAdminProductCategoryFormInitialize(EventArgs $event) { log_info('CategoryContent admin.product.category.index.initialize start'); /* @var Category $TargetCategory */ $TargetCategory = $event->getArgument('TargetCategory'); $id = $TargetCategory->getId(); $CategoryContent = null; if ($id) { // カテゴリ編集時は初期値を取得 $CategoryContent = $this->app['eccube.plugin.category_content.repository.category_content']->find($id); } // カテゴリ新規登録またはコンテンツが未登録の場合 if (!$CategoryContent) { $CategoryContent = new CategoryContent(); } // フォームの追加 /** @var FormInterface $builder */ $builder = $event->getArgument('builder'); $builder->add(self::CATEGORY_CONTENT_TEXTAREA_NAME, 'textarea', array('required' => false, 'label' => false, 'mapped' => false, 'constraints' => array(new Assert\Length(array('max' => $this->app['config']['category_text_area_len']))), 'attr' => array('maxlength' => $this->app['config']['category_text_area_len'], 'placeholder' => $this->app->trans('admin.plugin.category.content')))); // 初期値を設定 $builder->get(self::CATEGORY_CONTENT_TEXTAREA_NAME)->setData($CategoryContent->getContent()); log_info('CategoryContent admin.product.category.index.initialize end'); }
/** * 管理画面:カテゴリ登録画面に, カテゴリコンテンツのフォームを追加する. * * @param EventArgs $event */ public function onFormInitializeAdminProductCategory(EventArgs $event) { /** @var Category $target_category */ $TargetCategory = $event->getArgument('TargetCategory'); $id = $TargetCategory->getId(); $CategoryContent = null; if ($id) { // カテゴリ編集時は初期値を取得 $CategoryContent = $this->app['category_content.repository.category_content']->find($id); } // カテゴリ新規登録またはコンテンツが未登録の場合 if (is_null($CategoryContent)) { $CategoryContent = new CategoryContent(); } // フォームの追加 /** @var FormInterface $builder */ $builder = $event->getArgument('builder'); $builder->add(self::CATEGORY_CONTENT_TEXTAREA_NAME, 'textarea', array('required' => false, 'label' => false, 'mapped' => false, 'attr' => array('placeholder' => 'コンテンツを入力してください(HTMLタグ使用可)'))); // 初期値を設定 $builder->get(self::CATEGORY_CONTENT_TEXTAREA_NAME)->setData($CategoryContent->getContent()); }
/** * onRenderAdminProductCategoryEditBefore. * * @param FilterResponseEvent $event */ public function onRenderAdminProductCategoryEditBefore(FilterResponseEvent $event) { log_info('CategoryContent eccube.event.render.admin_product_category_edit.before start'); $app = $this->app; $request = $event->getRequest(); $response = $event->getResponse(); $id = $request->attributes->get('id'); $CategoryContent = null; if ($id) { $CategoryContent = $app['eccube.plugin.category_content.repository.category_content']->find($id); } if (!$CategoryContent) { $CategoryContent = new CategoryContent(); } // DomCrawlerにHTMLを食わせる $html = $response->getContent(); $crawler = new Crawler($html); $form = $app['form.factory']->createBuilder('admin_category')->getForm(); $form['content']->setData($CategoryContent->getContent()); $form->handleRequest($request); $twig = $app->renderView('CategoryContent/Resource/template/admin/category.twig', array('form' => $form->createView())); $oldCrawler = $crawler->filter('form')->first(); // DomCrawlerからHTMLを吐き出す $html = $crawler->html(); $oldHtml = ''; $newHtml = ''; if (count($oldCrawler) > 0) { $oldHtml = $oldCrawler->html(); $newHtml = $oldHtml . $twig; } $html = str_replace($oldHtml, $newHtml, $html); $response->setContent($html); $event->setResponse($response); log_info('CategoryContent eccube.event.render.admin_product_category_edit.before end'); }