seo icon indicating copy to clipboard operation
seo copied to clipboard

Error if some entry types in section not supporting SEO but others are

Open cole007 opened this issue 6 years ago • 4 comments

Description

Have an issue where if I have a section (in this case a structure) and some of the entry types have an SEO field (eg the default entry type) but others do not then if I change the entry type to the latter I get an Unknown Error occurred. flash error.

Steps to reproduce

  1. Create structure/section with more than one entry type
  2. Apply SEO field to default type but not other
  3. Create entry but change entry type to one without an SEO field
  4. Start creating a title for that field

A simple solution can be made in checking the SeoController to i. check if $element is an object and ii. the seoHandle property exists, for example:

Was:

return $this->asJson($element->$seoHandle->titleAsTokens);

Fix:

if (is_object($element) && property_exists($element, $seoHandle)) return $this->asJson($element->$seoHandle->titleAsTokens);
else return $this->asJson([]);

Source: src/controllers/SeoController.php: 81

Additional info

  • Craft version: 3.3.11
  • SEO version: 3.6.2
  • PHP version: 7.1.30
  • Database driver & version: MySQL 5.7.26

cole007 avatar Oct 24 '19 13:10 cole007

I have the same problem in a section having 2 entry types, both of them having SEO fields but these 2 fields don't have the same name :

Section Entry type handle SEO field handle
Products products productSeo
Products productCategories productCategorySeo

nstCactus avatar Nov 29 '19 10:11 nstCactus

I'm having a similar issue. Channel section with 2 entry types. Both have the same SEO field assigned.

I'm attempting to change the entry type of an existing entry from one to the other, and getting this error. Applying this fix helps, although don't like having a manual change that can be overwritten with an upgrade. Any chance of this being applied to an update for the plugin?

idawgik avatar May 07 '20 20:05 idawgik

Same problem here! Getting an "Trying to get property 'titleAsTokens' of non-object" error when switching between Entry types. Please fix this.

Additional info Craft version: 3.4.25 SEO version: 3.6.5.2

LizZerrG avatar Jun 30 '20 11:06 LizZerrG

Would you merge a pull request to fix this issue? Not sure why there is still no fix to be honest.

Since you properly set all parameters in your controller you basically only need to check if the entry type has the field in it's layout

https://github.com/ethercreative/seo/blob/v5-dev/src/controllers/SeoController.php#L86

Anubarak avatar Apr 03 '24 09:04 Anubarak