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

Command icon 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

froboy created an issue. See original summary.

froboy’s picture

Issue summary: View changes
Status: Active » Needs review
podarok’s picture

Status: Needs review » Reviewed & tested by the community

can ne merged/tagged

jonathan1055 made their first commit to this issue’s fork.

jschref’s picture

Issue summary: View changes

This fix works for me. Thank you. :)

jonathan1055’s picture

JSchref, 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.

jonathan1055’s picture

Status: Reviewed & tested by the community » Needs work

I 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

  1. Enable Scheduler
  2. Enable "Content Translation" core module
  3. Add a new language via /admin/config/regional/language (Config -> Region and Language -> Language )
  4. Enable a content type for translation of content (via Content type -> edit -> language settings -> tick both chekcboxes "Show language selector on create and edit pages" and "enable translation"
  5. Save is OK, no error
  6. Or if you enable you enable translation on admin/config/regional/content-language (Config -> Region and Language -> Content language and translation) - there is still no problem and no error on save

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.

jonathan1055’s picture

On #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

  1. Enable the core Language module but not Content Translation
  2. Enable the Scheduler module.
  3. Go to /admin/config/regional/content-language (Config -> Region and Language -> Content language and translation)
  4. Save

I am going to see if I can add some simple test coverage for this.

jonathan1055’s picture

Title: Unhandled Warning: Undefined array key "translatable" » Undefined array key "translatable" when Language is enabled but not Content Translation
Status: Needs work » Needs review

I 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.

c.lompole’s picture

I 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.

  • jonathan1055 committed 4b43b34d on 2.x authored by froboy
    Issue #3446881: Undefined array key "translatable" when Language is...
jonathan1055’s picture

Status: Needs review » Fixed

Thanks @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 just isset(), 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.

  • jonathan1055 committed 0a555aca on 8.x-1.x
    Issue #3446881 by jonathan1055, froboy, c.lompole, podarok, jschref:...
jonathan1055’s picture

Also fixed in 8.x-1.x

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.