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

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

Open
cole007 opened this issue Oct 24, 2019 · 4 comments
Open

Comments

@cole007
Copy link

cole007 commented Oct 24, 2019

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
@nstCactus
Copy link
Contributor

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

@idawgik
Copy link

idawgik commented May 7, 2020

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?

@LizZerrG
Copy link

LizZerrG commented Jun 30, 2020

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

@Anubarak
Copy link

Anubarak commented Apr 3, 2024

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

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

5 participants