Bug #89165
closed
Metatags set with metatag manager registry wont be rendered if a plugin action is uncached
Added by Daniel Dorndorf about 5 years ago.
Updated over 4 years ago.
Description
I got the issue that the meta tags I set via the new meta tag api in my controller were not set.
There seems to be an Issue when the action is uncached and a proper instantiating of the page renderer using the added metatags etc.
I wasn't able to find out more details yet, I may edit this later, but maybe this gives someone a direction to the location of the problem.
Greetings
Daniel
- Project changed from 9 to TYPO3 Core
- TYPO3 Version set to 10
Hi Daniel,
In my own setup I don't have any problems with this. So I do have some questions for you:
- Which version of TYPO3 do you use?
- Do you have a snippet of the code that is setting your metatag by the API?
- Is it a metatag that is also set by other plugins or by page settings?
Thanks,
Richard
- Status changed from New to Needs Feedback
Hi Richard,
I'm using TYPO3 9.5.10
I created a MetaTagService which gets the MetaTagManagerRegistry via inject method (but I also tried it manually with the ObjectManager):
/**
* @var \TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry
*/
protected $metaTagManagerRegistry;
/**
* @param \TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry $metaTagManagerRegistry
*/
public function injectMetaTagManagerRegistry(MetaTagManagerRegistry $metaTagManagerRegistry)
{
$this->metaTagManagerRegistry = $metaTagManagerRegistry;
}
Example for "description"-Tag:
$this->metaTagManagerRegistry->getManagerForProperty('description')->addProperty('description', $description, [], true);
In an uncached action the MetaTagManagers properties in the page renderer wont be replaced, the value set by the page settings will be used.
For me it seems like something with the singleton instance isn't working properly, because in my understanding the MetaTagManagerRegistry in the PageRenderer and in my service should be the same object, but they are not.
Greetings
Daniel
Can you try it like:
$metaTagManagerRegistry = GeneralUtility::makeInstance(MetaTagManagerRegistry::class);
$ogMetaTagManager = $metaTagManagerRegistry->getManagerForProperty('og:title');
$ogMetaTagManager->addProperty('og:title', 'Entry from uncached plugin', [], true);
This works for me even on mixed pages. On mixed pages the uncached plugin will always overrule the other cached data.
It worked... but why?
Is there enough time or operations between calling the constructor and the action using the registry, that there's a difference?
(I also instanciated the registry via GeneralUtility but in the constructor)
Maybe I'm lacking knowledge about singleton instances and the core, or is there an issue deep down the rabbit hole?
Even with GeneralUtility you had this problem? Maybe something was wrong with the injection? Should work as far as I know.
I have no hooks or anything special, just moved everything in a service class and used dependency injection
- Status changed from Needs Feedback to Closed
Just tried to reproduce the issue and failed to do so, worked for me both with DI and with GeneralUtility. I'm going to close the issue - please report back if it happens again - ideally with an example extension / code.
Also available in: Atom
PDF