From f48a56cd148da5667f592e5bd47cc442e2151316 Mon Sep 17 00:00:00 2001 From: hideki_okajima Date: Tue, 6 Apr 2021 09:16:14 +0900 Subject: [PATCH 1/2] =?UTF-8?q?meta=E3=82=BF=E3=82=B0=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=81=AE=20Symfony4.4=20=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Eccube/Tests/Web/TopControllerTest.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/Eccube/Tests/Web/TopControllerTest.php b/tests/Eccube/Tests/Web/TopControllerTest.php index f0c4b2b2459..84aa235a315 100644 --- a/tests/Eccube/Tests/Web/TopControllerTest.php +++ b/tests/Eccube/Tests/Web/TopControllerTest.php @@ -13,9 +13,10 @@ namespace Eccube\Tests\Web; +use Eccube\Entity\BaseInfo; +use Eccube\Entity\Page; use Eccube\Repository\BaseInfoRepository; use Eccube\Repository\PageRepository; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; class TopControllerTest extends AbstractWebTestCase { @@ -39,11 +40,15 @@ public function testMetaTags() { // description を設定 $description = 'あのイーハトーヴォのすきとおった風、夏でも底に冷たさをもつ青いそら、うつくしい森で飾られたモリーオ市、郊外のぎらぎらひかる草の波。'; - $page = $this->container->get(PageRepository::class)->getByUrl('homepage'); + /** @var PageRepository $pageRepository */ + $pageRepository = $this->entityManager->getRepository(Page::class); + $page = $pageRepository->getByUrl('homepage'); $page->setDescription($description); $this->entityManager->flush(); - $shopName = $this->container->get(BaseInfoRepository::class)->get()->getShopName(); + /** @var BaseInfoRepository $baseInfoRepository */ + $baseInfoRepository = $this->entityManager->getRepository(BaseInfo::class); + $shopName = $baseInfoRepository->get()->getShopName(); $expected_desc = mb_substr($description, 0, 120, 'utf-8'); $crawler = $this->client->request('GET', $this->generateUrl('homepage')); From 37b6aea4211a1ff988b5a477341c8f0060c71821 Mon Sep 17 00:00:00 2001 From: "h.matsuo" Date: Tue, 6 Jul 2021 12:21:53 +0900 Subject: [PATCH 2/2] =?UTF-8?q?meta=E3=81=AE=E5=87=BA=E3=81=97=E5=88=86?= =?UTF-8?q?=E3=81=91=E3=81=AE=E5=88=A4=E5=AE=9A=E6=96=B9=E6=B3=95=E3=82=92?= =?UTF-8?q?=E3=80=81=E3=83=AB=E3=83=BC=E3=83=86=E3=82=A3=E3=83=B3=E3=82=B0?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../template/default/default_frame.twig | 6 +++--- src/Eccube/Resource/template/default/meta.twig | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Eccube/Resource/template/default/default_frame.twig b/src/Eccube/Resource/template/default/default_frame.twig index 677a2cf8e59..3740db911a1 100644 --- a/src/Eccube/Resource/template/default/default_frame.twig +++ b/src/Eccube/Resource/template/default/default_frame.twig @@ -17,15 +17,15 @@ file that was distributed with this source code. {{ BaseInfo.shop_name }}{% if subtitle is defined and subtitle is not empty %} / {{ subtitle }}{% elseif title is defined and title is not empty %} / {{ title }}{% endif %} {% if Page.meta_tags is not empty %} {{ include(template_from_string(Page.meta_tags)) }} + {% if Page.description is not empty %} + + {% endif %} {% else %} {{ include('meta.twig') }} {% endif %} {% if Page.author is not empty %} {% endif %} - {% if Page.description is not empty %} - - {% endif %} {% if Page.keyword is not empty %} {% endif %} diff --git a/src/Eccube/Resource/template/default/meta.twig b/src/Eccube/Resource/template/default/meta.twig index 0a7f0edae01..0806af01c41 100644 --- a/src/Eccube/Resource/template/default/meta.twig +++ b/src/Eccube/Resource/template/default/meta.twig @@ -1,4 +1,4 @@ -{% if Product is defined %} +{% if app.request.get('_route') == 'product_detail' %} {% set meta_og_type = "og:product" %} {% set meta_description = Product.description_list | default(Product.description_detail) | default(Page.description) %} {% set meta_canonical = url('product_detail', {'id': Product.id}) %} @@ -8,17 +8,17 @@ -{% elseif Category is defined %} - {% set meta_og_type = 'article' %} - {% set meta_description = Page.description %} +{% elseif app.request.get('_route') == 'product_list' %} {% set meta_canonical = url('product_list', {'category_id': Category.id|default(null)}) %} -{% elseif Page is defined %} - {% set meta_og_type = (app.request.get('_route') == 'homepage') ? 'website' : 'article' %} - {% set meta_description = Page.description %} +{% elseif app.request.get('_route') == 'homepage' %} + {% set meta_og_type = 'website' %} + {% set meta_canonical = url('homepage') %} {% endif %} - + + -{% if meta_description|default() %} +{% set meta_description = meta_description | default(Page.description) %} +{% if meta_description %} {% endif %}