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

[Craft 5] getElementProfile helper doesn't account for Matrix blocks with their own URI (there's no associated section handle) #85

Closed
kylecotter opened this issue Apr 5, 2024 · 1 comment

Comments

@kylecotter
Copy link

Hi!

Craft 5 lets matrix blocks have their own URIs. With this type of setup the resulting matrix block element doesn't have a "section" associated with it, and therefore no handle for this line to grab.

This results in the hook 'seomateMeta' erroring.

To reproduce:

  1. Create a section (and entry type for section) as normal
  2. Create a matrix field that has uris (in our case the uri was {owner.uri}/{type|kebab})
  3. Add matrix field to the entry type of the section
  4. Create a new entry in the section, and a new block in the matrix field
  5. Attempt to view the URL of the matrix block
  6. Should get an error

Full stacktrace below:

yii\base\ErrorException: Attempt to read property "handle" on null in /var/www/vendor/vaersaagod/seomate/src/helpers/SEOMateHelper.php:62
Stack trace:
#0 /var/www/vendor/craftcms/cms/src/web/ErrorHandler.php(79): yii\base\ErrorHandler->handleError(2, 'Attempt to read...', '/var/www/vendor...', 62)
#1 /var/www/vendor/vaersaagod/seomate/src/helpers/SEOMateHelper.php(62): craft\web\ErrorHandler->handleError(2, 'Attempt to read...', '/var/www/vendor...', 62)
#2 /var/www/vendor/vaersaagod/seomate/src/services/MetaService.php(125): vaersaagod\seomate\helpers\SEOMateHelper::getElementProfile(Object(craft\elements\Entry), Object(vaersaagod\seomate\models\Settings))
#3 /var/www/vendor/vaersaagod/seomate/src/services/MetaService.php(61): vaersaagod\seomate\services\MetaService->getElementMeta(Object(craft\elements\Entry), NULL)
#4 /var/www/vendor/vaersaagod/seomate/src/SEOMate.php(247): vaersaagod\seomate\services\MetaService->getContextMeta(Array)
#5 /var/www/vendor/craftcms/cms/src/web/View.php(1831): vaersaagod\seomate\SEOMate->onRegisterMetaHook(Array, false)
#6 /var/www/storage/runtime/compiled_templates/9e/9ef05cfb0c6438422fd138c0bfa70380.php(95): craft\web\View->invokeHook('seomateMeta', Array)
#7 /var/www/vendor/twig/twig/src/Template.php(394): __TwigTemplate_cd2f788e69f9551e40346365bc91c19b->doDisplay(Array, Array)
#8 /var/www/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#9 /var/www/storage/runtime/compiled_templates/60/601e724698f128ab02bfcf5295dbdcbb.php(49): Twig\Template->display(Array, Array)
#10 /var/www/vendor/twig/twig/src/Template.php(394): __TwigTemplate_10140b5ee18c9f9052c53d8a1af8551f->doDisplay(Array, Array)
#11 /var/www/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#12 /var/www/storage/runtime/compiled_templates/c6/c6394570d6a51b1671a6b3c7dd95be2a.php(54): Twig\Template->display(Array, Array)
#13 /var/www/vendor/twig/twig/src/Template.php(394): __TwigTemplate_fb80e86ec89ec8fa618cad7cf6ec31bb->doDisplay(Array, Array)
#14 /var/www/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#15 /var/www/storage/runtime/compiled_templates/7b/7b55256df7370eb565c593066cadbe02.php(47): Twig\Template->display(Array, Array)
#16 /var/www/vendor/twig/twig/src/Template.php(394): __TwigTemplate_85bae3ae8bc4cfe91cebe835d8f2fb4d->doDisplay(Array, Array)
#17 /var/www/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#18 /var/www/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->display(Array, Array)
#19 /var/www/storage/runtime/compiled_templates/42/429ea6192f92143f727bf4451145f17b.php(49): Twig\TemplateWrapper->display(Array, Array)
#20 /var/www/vendor/twig/twig/src/Template.php(394): __TwigTemplate_c064079ff4b4a08ae5dbbf7064a1e824->doDisplay(Array, Array)
#21 /var/www/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#22 /var/www/vendor/twig/twig/src/Template.php(379): Twig\Template->display(Array)
#23 /var/www/vendor/twig/twig/src/TemplateWrapper.php(38): Twig\Template->render(Array)
#24 /var/www/vendor/twig/twig/src/Environment.php(280): Twig\TemplateWrapper->render(Array)
#25 /var/www/vendor/craftcms/cms/src/web/View.php(482): Twig\Environment->render('_entries', Array)
#26 /var/www/vendor/craftcms/cms/src/web/View.php(535): craft\web\View->renderTemplate('_entries', Array)
#27 /var/www/vendor/craftcms/cms/src/web/TemplateResponseFormatter.php(57): craft\web\View->renderPageTemplate('_entries', Array, 'site')
#28 /var/www/vendor/yiisoft/yii2/web/Response.php(1100): craft\web\TemplateResponseFormatter->format(Object(craft\web\Response))
#29 /var/www/vendor/craftcms/cms/src/web/Response.php(337): yii\web\Response->prepare()
#30 /var/www/vendor/yiisoft/yii2/web/Response.php(340): craft\web\Response->prepare()
#31 /var/www/vendor/yiisoft/yii2/base/Application.php(390): yii\web\Response->send()
#32 /var/www/web/index.php(12): yii\base\Application->run()
#33 {main}

Thanks!

@mmikkel
Copy link
Member

mmikkel commented Apr 6, 2024

Thanks a lot for reporting that! I just tagged SEOMate v. 3.0.0-beta.5, which should resolve the issue.

Additionally, this prodded me to finish implementing a feature that goes nicely with Craft 5's decoupled entry types and Matrix entrification: the ability to be more specific when mapping field profiles to elements via context prefixes such as "section:news" or "entryType:listPage". Read more about that here!

(...this new feature also means that SEOMate now gives you the ability to map field profiles to nested Matrix entry types).

@mmikkel mmikkel closed this as completed Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants