From 4615fd5cf33558761ccd95ba49bac22ee7ab182c Mon Sep 17 00:00:00 2001 From: sakaguchi Date: Wed, 2 Dec 2026 11:31:34 +0900 Subject: [PATCH] =?UTF-8?q?fix=20#4696=20=E3=80=90=E3=82=B7=E3=82=B9?= =?UTF-8?q?=E3=83=86=E3=83=A0=E3=80=91=E3=82=AB=E3=83=8E=E3=83=8B=E3=82=AB?= =?UTF-8?q?=E3=83=AB=E3=82=BF=E3=82=B0=E3=82=92=E5=87=BA=E5=8A=9B=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=81=A8=E3=80=81=E3=83=86=E3=83=B3=E3=83=97=E3=83=AC?= =?UTF-8?q?=E3=83=BC=E3=83=88=E3=81=A7=20meta=20=E3=83=96=E3=83=AD?= =?UTF-8?q?=E3=83=83=E3=82=AF=E3=81=AB=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=9F?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E3=81=8C=E6=B6=88=E3=81=88=E3=82=8B=E5=95=8F?= =?UTF-8?q?=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/View/Helper/BcBaserHelper.php | 6 +++--- .../View/Helper/BcBaserHelperTest.php | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/plugins/baser-core/src/View/Helper/BcBaserHelper.php b/plugins/baser-core/src/View/Helper/BcBaserHelper.php index 0ba0e73080..df5aa223e0 100755 --- a/plugins/baser-core/src/View/Helper/BcBaserHelper.php +++ b/plugins/baser-core/src/View/Helper/BcBaserHelper.php @@ -2603,7 +2603,7 @@ public function setCanonicalUrl() return; } if ($canonicalUrl) { - $this->_View->assign('meta', + $this->_View->append('meta', $this->BcHtml->meta('canonical', $this->getUrl($canonicalUrl, true), [ @@ -2637,7 +2637,7 @@ public function setCanonicalUrl() $url = preg_replace('/\.html$/', '', $url); $url = preg_replace('/\/page:1$/', '', $url); $url = preg_replace('/\\/index$/', '/', $url); - $view->assign('meta', + $view->append('meta', $this->BcHtml->meta('canonical', $this->getUrl($url, true), [ @@ -2671,7 +2671,7 @@ public function setAlternateUrl() $request->getAttribute('currentSite')->id )])); - $view->assign('meta', + $view->append('meta', $this->BcHtml->meta('alternate', null, [ diff --git a/plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php b/plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php index 4f127511d4..0faf9c234c 100644 --- a/plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php +++ b/plugins/baser-core/tests/TestCase/View/Helper/BcBaserHelperTest.php @@ -2293,6 +2293,27 @@ public function testSetCanonicalUrl($siteId, $url, $expected, $canonicalUrl = nu $this->assertEquals($expected, $this->BcBaser->getView()->fetch('meta')); } + /** + * testSetCanonicalUrl + * テンプレートで meta ブロックに追加した内容が、カノニカルタグの出力で消えないこと + */ + public function testSetCanonicalUrlKeepsMetaBlock() + { + $this->loadFixtureScenario(InitAppScenario::class); + ContentFactory::make([ + 'site_id' => 1, + 'url' => '/' + ])->persist(); + $view = $this->BcBaser->getView(); + $view->setRequest($this->getRequest('/')); + $view->assign('meta', ''); + $this->BcBaser->setCanonicalUrl(); + $this->assertEquals( + '', + $view->fetch('meta') + ); + } + public static function setCanonicalUrlDataProvider() { return [