Problem/Motivation
When enabling translation with Scheduler enabled, the site may throw an error:
Warning: Undefined array key "translatable" in _scheduler_translation_validate() (line 732 of .../docroot/modules/contrib/scheduler/scheduler.module)
This seems to be due to an assumption that the translatable option will exist when it may not. This seems identical to the issue in #3315873: Unhandled Warning: Undefined array key "translatable".
Steps to reproduce
Enable translation on a site with Scheduler already installed:
- Add a new language: /admin/config/regional/language (take FR as example)
- Enable content translation for some content types and check "Show language selector on create and edit pages" on: /admin/config/regional/content-language
- Observe the changes are not saved and there is an error in the log.
Proposed resolution
Check if $options['translatable'] exists before using it.
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork scheduler-3446881
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
froboyComment #4
podarokcan ne merged/tagged
Comment #6
jschref commentedThis fix works for me. Thank you. :)
Comment #7
jonathan1055 commentedJSchref, did you mean to erase the issue summary?
I need to check the steps to reproduce, and it would be good to have test coverage for this, as clearly there are some incorrect assumptions in the code.
Comment #8
jonathan1055 commentedI have reverted JSchref erasing of the issue summary.
I followed the 'steps to reproduce' but could not get the error. Specifically what I did was
I am not saying that there is no problem, it is just that there must be something else in your set-up which is causing this error. I need to understand what is causing the problem and replicate it, before committing any fix.
Comment #9
jonathan1055 commentedOn #3493930: Undefined array key "translatable" in _scheduler_translation_validate() (line 732 of modules/contrib/scheduler/scheduler.module) I was able to replicate the error, the key difference is that Language needs to be installed but not Content Translation.
Steps to reproduce
I am going to see if I can add some simple test coverage for this.
Comment #10
jonathan1055 commentedI have added a simple test to make sure the Content Language form can be saved even when the Translation module is not enabled.
https://git.drupalcode.org/project/scheduler/-/pipelines/393018
The "test only changes" job shows that we do now have coverage for this, because the new test fails when the fix is reverted.
Comment #11
c.lompole commentedI continue to get the same warning with the test scenario initially mentioned in the description of this issue. I'm using version 2.2.1 and I'm getting the following error:
Error message:
Warning: Undefined array key "translatable" in _scheduler_translation_validate() (line 753 of modules/contrib/scheduler/scheduler.module).
I created a local patch by replacing this condition:
if ($options['translatable'] && ($enabled['publish_on'] || $enabled['unpublish_on'])) {with:
if (isset($options['translatable']) && ($enabled['publish_on'] || $enabled['unpublish_on'])) {This checks if the "translatable" key exists before accessing it.
Comment #13
jonathan1055 commentedThanks @c.lompole
The change that you suggest was already done in MR140 bu this has not been merged yet. I think also that we still need to check that
$options['translatable']is true, not justisset(), because isset() gives a positive even when $options['translatable'] is set to false. However, I have used your idea of isset() because this is preferrable to array_key_exists()All tests pass, and the new test correctly fails in 'test-only changes'
https://git.drupalcode.org/project/scheduler/-/jobs/5828567#L584
Thanks everyone, merged and fixed.
Comment #16
jonathan1055 commentedAlso fixed in 8.x-1.x