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

Unable to render page when 'meta title' page config param is set #2956

Closed
OlegIvan0v opened this issue Jan 11, 2016 · 8 comments
Closed

Unable to render page when 'meta title' page config param is set #2956

OlegIvan0v opened this issue Jan 11, 2016 · 8 comments
Assignees
Labels
Area: Frontend bug report Fixed in 2.1.x The issue has been fixed in 2.1 release line Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@OlegIvan0v
Copy link

OlegIvan0v commented Jan 11, 2016

Preconditions

  1. Magento 2

Steps to reproduce

  1. Create a custom module with following controller:
use Magento\Framework\View\Result\PageFactory;

class SomeAction extends \Magento\Framework\App\Action\Action
{
    /**
     * @var PageFactory
     */
    protected $resultPageFactory;

    public function __construct(
        Context $context,
        PageFactory $resultPageFactory
    ) {
        parent::__construct($context);
        $this->resultPageFactory = $resultPageFactory;
    }

    public function execute()
    {
        /** $resultPage @var \Magento\Framework\View\Result\Page */
        $resultPage = $this->resultPageFactory->create();
        $resultPage->getConfig()->setMetadata('title', 'some meta title');
        return $resultPage;
    }
}
  1. Open the created controller on storefront.

Expected result

Page is opened, its source contains <meta name="title" content="some meta title">

Actulal result

Error message: "Recoverable Error: Object of class Magento\Framework\View\Page\Title could not be converted to string..."

Additional info: the reason in that page config renderer tries to use page title object as meta title content (in \Magento\Framework\View\Page\Config\Renderer::processMetadataContent()).

@ghost
Copy link

ghost commented Jan 11, 2016

Not sure if I would expect that getMetadata(); sets the title. Maybe it is omitted in the metadata array for a special purpose?
I cannot think of any but I have not much SEO knowledge :)
I'm just using $resultPage->getConfig()->getTitle()->set("FOO"); to set the title which works fine

@OlegIvan0v
Copy link
Author

The problem is that we cannot set meta title of page using \Magento\Framework\View\Page\Config::setMetadata():

<meta name="title" content="Page title">

It's not related to page title:

<title>Page title</title>

We can set any other meta data, but not 'meta title' because during processing of meta data content magento invokes getter method of \Magento\Framework\View\Page\Config, which for 'title' data will be \Magento\Framework\View\Page\Config::getTitle(), which returns \Magento\Framework\View\Page\Title object, that is not converted to string.
This problem can be solved by specifying preference of \Magento\Framework\View\Page\Config\RendererInterface, but on my opinion we must be able to specify any meta content using default renderer class \Magento\Framework\View\Page\Config\Renderer.

@shiftedreality
Copy link
Member

Correct way to setup title was specified by @xhallix

$resultPage->getConfig()->getTitle()->set("FOO");

But current behavior looks like issue. Setting metadata should have the same result for any meta name.

Created ticket MAGETWO-47807

@victorgugo victorgugo added bug report Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development labels Jan 13, 2016
@vkorotun vkorotun removed the PS label Aug 4, 2016
@magento-engcom-team magento-engcom-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report Area: Frontend Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Sep 11, 2017
@slackerzz
Copy link
Member

any news about MAGETWO-47807?

@magento-engcom-team magento-engcom-team added 2.1.x Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Nov 27, 2017
@magento-engcom-team
Copy link
Contributor

@volnnn, thank you for your report.
We've created internal ticket(s) MAGETWO-84539 to track progress on the issue.

rainashikha added a commit to rainashikha/magento2 that referenced this issue May 19, 2018
magento#2956

Fixed. Added a check to to see if returned content is object or not. As objects will never be converted to string and will throw error for str_replace at line 125
@magento-engcom-team
Copy link
Contributor

Hi @volnnn. Thank you for your report.
The issue has been fixed in #11368 by @slackerzz in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

@sidolov
Copy link
Contributor

sidolov commented Jul 21, 2018

Hi @volnnn. Thank you for your report.
The issue has been fixed in #16948 by @ronak2ram in 2.1-develop branch
Related commit(s):

The fix will be available with the upcoming 2.1.15 release.

magento-engcom-team pushed a commit that referenced this issue Aug 3, 2018
[TSG] Backporting for 2.2 (pr37) (2.2.7)
@ishakhsuvarov
Copy link
Contributor

@volnnn We are closing this ticket now, as issue has been fixed in 2.1, 2.2 and 2.3.

Commits for 2.1 and 2.3 are linked in the comments above, for 2.2 reference would be #16333 and #15532

Thanks

@ishakhsuvarov ishakhsuvarov added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Aug 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Frontend bug report Fixed in 2.1.x The issue has been fixed in 2.1 release line Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests