mplodowski / seomanager-plugin-public

https://octobercms.com/plugin/renatio-seomanager
https://octobercms.com/plugin/renatio-seomanager
4 stars 1 forks source link

Custom model implementation not working without Translations #24

Closed b8ne closed 2 years ago

b8ne commented 2 years ago

Describe the bug I am implementing SeoModel on a custom blog model. After upgrade to v3 and October v2 I can no longer save new custom models, and getting an error "Unexpected type of array when attempting to save attribute "translatable", try adding it to the $jsonable property". Noting I have also ran both migration and patches for v3 upgrade. It looks like the SEO behaviour is adding 'translatable'

To Reproduce Steps to reproduce the behavior:

  1. $implement '@Renatio.SeoManager.Behaviors.SeoModel' as per docs on custom model.
  2. Do not have Rainlab.Translatable running/installed.
  3. Attempt to create and save a new custom model.
  4. See error

Expected behavior The model should be created successfully.

October version v2.1.28

Plugin version v3.1.0

Additional context Adding the below to my model solves the issue. I assume a check that Rainlab.Translatable is running needs to be added before adding the translatable attribute to the model.

  protected $jsonable = ['translatable'];
  public function beforeSave()
    {
        unset($this->translatable);
    }
mplodowski commented 2 years ago

Hi,

I couldn't replicate this issue on latest October v2.1.31. I tested on PHP 7.4 and 8.0.

I added check for RainLab.Translate in code, that should fix your issue.

Please upgrade to version 3.1.2 and let me know if this works.

b8ne commented 2 years ago

Thanks mate, yeah the update works. Perhaps there were more edge cases causing it to break on my end, but the Translate check appears to solve it. Cheers!