Yoast / Yoast-SEO-for-TYPO3

Yoast SEO plugin for TYPO3
Other
51 stars 56 forks source link

Attempt to generate preview URL for new records #574

Open peterkraume opened 4 months ago

peterkraume commented 4 months ago

Please give us a description of what happened.

I'm using the RecordUtility to add Yoast SEO fields to a custom table:

<?php

use YoastSeoForTypo3\YoastSeo\Utility\RecordUtility;

RecordUtility::configureForRecord('tx_foo_domain_model_usedhall')
    ->setGetParameters([
        ['tx_foo_detail', 'usedhall'],
    ])
    ->setTitleField('seo_title')
    ->setGeneratePageTitle(true)
    ->setDescriptionField('metadescription')
    ->setAddDescriptionField(true)
    ->setFieldsPosition('after:image_hint');

When I'm in an empty sys folder and try to create a new record, I directly end up with this error message:

(1/1) #1476107295 TYPO3\CMS\Core\Error\Exception PHP Warning: Trying to access array offset on value of type null in yoast_seo/Classes/Form/Element/SnippetPreview.php line 202

I debugged the SnippetPreview a little bit and it seem that the wrong record is queried: https://github.com/Yoast/Yoast-SEO-for-TYPO3/blob/c1e4ae93d7de523696a5d94cad19154237813e27/Classes/Form/Element/SnippetPreview.php#L171 In my case, the both parameters where the table name specified above and as $recordId the uid of my sys_folder was used.

Long story short: I think the main problem is, that EXT:yoast_seo tries to generate a preview URL for not yet existing record which doesn't make sense at all.

How can we reproduce this behavior?

  1. use RecordUtility::configureForRecord() for a custom table
  2. create an empty sys_folder
  3. create a new record of the above mentioned type

Technical info