Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7065 Allow page.main.title block to decide if title should be translated #11709

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@
</arguments>
</block>
</referenceContainer>
<referenceBlock name="page.main.title">
<arguments>
<argument name="id" xsi:type="string">page-title-heading</argument>
<argument name="add_base_attribute_aria" xsi:type="string">page-title-heading toolbar-amount</argument>
</arguments>
<block class="Magento\Catalog\Block\Category\Rss\Link" name="rss.link" template="Magento_Catalog::category/rss.phtml"/>
</referenceBlock>
<referenceContainer name="columns.top">
<block class="Magento\Theme\Block\Html\RawTitle" name="page.main.title" template="Magento_Theme::html/title.phtml" before="-">
<arguments>
<argument name="id" xsi:type="string">page-title-heading</argument>
<argument name="add_base_attribute_aria" xsi:type="string">page-title-heading toolbar-amount</argument>
</arguments>
<block class="Magento\Catalog\Block\Category\Rss\Link" name="rss.link" template="Magento_Catalog::category/rss.phtml"/>
</block>
</referenceContainer>
</body>
</page>
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
<referenceBlock name="head.components">
<block class="Magento\Framework\View\Element\Js\Components" name="checkout_page_head_components" template="Magento_Catalog::js/components.phtml"/>
</referenceBlock>
<referenceBlock name="page.main.title">
<arguments>
<argument name="css_class" xsi:type="string">product</argument>
<argument name="add_base_attribute" xsi:type="string">itemprop="name"</argument>
</arguments>
</referenceBlock>
<referenceContainer name="columns.top">
<block class="Magento\Theme\Block\Html\RawTitle" name="page.main.title" template="Magento_Theme::html/title.phtml" before="-">
<arguments>
<argument name="css_class" xsi:type="string">product</argument>
<argument name="add_base_attribute" xsi:type="string">itemprop="name"</argument>
</arguments>
</block>
</referenceContainer>
<referenceBlock name="root">
<arguments>
<argument name="add_attribute" xsi:type="string">itemscope itemtype="http://schema.org/Product"</argument>
Expand Down
63 changes: 63 additions & 0 deletions app/code/Magento/Theme/Block/Html/RawTitle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Theme\Block\Html;

use Magento\Framework\View\Element\Template;

/**
* Html page raw title block
*
* @method $this setTitleId($titleId)
* @method $this setTitleClass($titleClass)
* @method string getTitleId()
* @method string getTitleClass()
*/
class RawTitle extends Template
{
/**
* Own page title to display on the page
*
* @var string
*/
private $pageTitle;

/**
* Provide own page title or pick it from Head Block
*
* @return string
*/
public function getPageTitle()
{
if (!empty($this->pageTitle)) {
return $this->pageTitle;
}
return $this->pageConfig->getTitle()->getShort();
}

/**
* Provide own page content heading
*
* @return string
*/
public function getPageHeading()
{
if (!empty($this->pageTitle)) {
return $this->pageTitle;
}
return $this->pageConfig->getTitle()->getShortHeading();
}

/**
* Set own page title
*
* @param string $pageTitle
* @return void
*/
public function setPageTitle($pageTitle)
{
$this->pageTitle = $pageTitle;
}
}
113 changes: 113 additions & 0 deletions app/code/Magento/Theme/Test/Unit/Block/Html/RawTitleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Theme\Test\Unit\Block\Html;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;

class RawTitleTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ObjectManagerHelper
*/
protected $objectManagerHelper;

/**
* @var \Magento\Framework\View\Page\Config|\PHPUnit_Framework_MockObject_MockObject
*/
protected $pageConfigMock;

/**
* @var \Magento\Framework\View\Page\Title|\PHPUnit_Framework_MockObject_MockObject
*/
protected $pageTitleMock;

/**
* @var \Magento\Theme\Block\Html\RawTitle
*/
protected $rawHtmlTitle;

/**
* @return void
*/
protected function setUp()
{
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->pageConfigMock = $this->createMock(\Magento\Framework\View\Page\Config::class);
$this->pageTitleMock = $this->createMock(\Magento\Framework\View\Page\Title::class);

$context = $this->objectManagerHelper->getObject(
\Magento\Framework\View\Element\Template\Context::class,
['pageConfig' => $this->pageConfigMock]
);

$this->rawHtmlTitle = $this->objectManagerHelper->getObject(
\Magento\Theme\Block\Html\RawTitle::class,
['context' => $context]
);
}

/**
* @return void
*/
public function testGetPageTitleWithSetPageTitle()
{
$title = 'some title';

$this->rawHtmlTitle->setPageTitle($title);
$this->pageConfigMock->expects($this->never())
->method('getTitle');

$this->assertEquals($title, $this->rawHtmlTitle->getPageTitle());
}

/**
* @return void
*/
public function testGetPageTitle()
{
$title = 'some title';

$this->pageTitleMock->expects($this->once())
->method('getShort')
->willReturn($title);
$this->pageConfigMock->expects($this->once())
->method('getTitle')
->willReturn($this->pageTitleMock);

$this->assertEquals($title, $this->rawHtmlTitle->getPageTitle());
}

/**
* @return void
*/
public function testGetPageHeadingWithSetPageTitle()
{
$title = 'some title';

$this->rawHtmlTitle->setPageTitle($title);
$this->pageConfigMock->expects($this->never())
->method('getTitle');

$this->assertEquals($title, $this->rawHtmlTitle->getPageHeading());
}

/**
* @return void
*/
public function testGetPageHeading()
{
$title = 'some title';

$this->pageTitleMock->expects($this->once())
->method('getShortHeading')
->willReturn($title);
$this->pageConfigMock->expects($this->once())
->method('getTitle')
->willReturn($this->pageTitleMock);

$this->assertEquals($title, $this->rawHtmlTitle->getPageHeading());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
// @codingStandardsIgnoreFile

/**
* @var $block \Magento\Theme\Block\Html\Title
* @var $block \Magento\Theme\Block\Html\Title|\Magento\Theme\Block\Html\RawTitle
*/
$cssClass = $block->getCssClass() ? ' ' . $block->getCssClass() : '';
$title = '';
if (trim($block->getPageHeading())) {
$title = '<span class="base" data-ui-id="page-title-wrapper" ' . $block->getAddBaseAttribute() . '>'
$title = '<span class="base" data-ui-id="page-title-wrapper" ' . $block->getAddBaseAttribute() . '>'
. $block->escapeHtml($block->getPageHeading()) . '</span>';
}
?>
Expand Down