Problem / Motivation

  • Drupal 9.0.6 (stable)
  • PHP 7.4
  • Scheduler 1.3
  • Scheduler content moderation integration 1.3
  • Install in different language (DE/DK/etc.) without English

When editing a node with scheduler enabled, I get the following Warnings & Notices:

Notice: Undefined offset: 0 in scheduler_content_moderation_integration_scheduler_hide_publish_on_field() (line 213 of modules/contrib/scheduler_content_moderation_integration/scheduler_content_moderation_integration.module).
scheduler_content_moderation_integration_scheduler_hide_publish_on_field(Array, Object, Object) (Line: 89)
scheduler_form_node_form_alter(Array, Object, 'node_tender_edit_form') (Line: 539)
Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object, 'node_tender_edit_form') (Line: 838)

Notice: Trying to access array offset on value of type null in scheduler_content_moderation_integration_scheduler_hide_publish_on_field() (line 213 of modules/contrib/scheduler_content_moderation_integration/scheduler_content_moderation_integration.module).
scheduler_content_moderation_integration_scheduler_hide_publish_on_field(Array, Object, Object) (Line: 89)
scheduler_form_node_form_alter(Array, Object, 'node_tender_edit_form') (Line: 539)

Warning: array_diff_key(): Expected parameter 1 to be an array, null given in scheduler_content_moderation_integration_scheduler_hide_publish_on_field() (line 213 of modules/contrib/scheduler_content_moderation_integration/scheduler_content_moderation_integration.module).
scheduler_content_moderation_integration_scheduler_hide_publish_on_field(Array, Object, Object) (Line: 89)
scheduler_form_node_form_alter(Array, Object, 'node_tender_edit_form') (Line: 539)

Warning: count(): Parameter must be an array or an object that implements Countable in scheduler_content_moderation_integration_scheduler_hide_publish_on_field() (line 214 of modules/contrib/scheduler_content_moderation_integration/scheduler_content_moderation_integration.module).
scheduler_content_moderation_integration_scheduler_hide_publish_on_field(Array, Object, Object) (Line: 89)
scheduler_form_node_form_alter(Array, Object, 'node_tender_edit_form') (Line: 539)
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

thetailwind created an issue. See original summary.

s_bhandari’s picture

Not able to reproduce the issue for the same version. Could you please help to give some more details or steps in order to replicate the same?

Thanks.

vuil’s picture

Issue summary: View changes
vuil’s picture

Title: count(): Parameter must be an array or an object that implements Countable in scheduler_content_moderation_integration_scheduler_hide_publish_on_field() » Drupal 9 & PHP 7.4 - PHP Warnings & Notices
Issue summary: View changes
Issue tags: +Drupal 9 compatibility, +PHP 7.4
vuil’s picture

Issue summary: View changes
vuil’s picture

Issue summary: View changes
mohit.bansal623’s picture

Status: Active » Needs review
StatusFileSize
new1.64 KB
vuil’s picture

Status: Needs review » Needs work

But that hide the form... :(

I see that the required:

$form['unpublish_state']['widget'][0]['#options']

exists (without [0]) as $form['unpublish_state']['widget']['#options'].

So, I recommend to replace the following:

$form['publish_state']['widget'][0]['#options']
$form['unpublish_state']['widget'][0]['#options']

with:

$form['publish_state']['widget'][0]['#options'] ?? $form['publish_state']['widget']['#options']
$form['unpublish_state']['widget'][0]['#options'] ?? $form['unpublish_state']['widget']['#options']

in "scheduler_content_moderation_integration.module" file.

And it works for me.

mohit.bansal623’s picture

StatusFileSize
new1.63 KB
mohit.bansal623’s picture

Status: Needs work » Needs review
vuil’s picture

StatusFileSize
new1.48 KB

I post the patch which I mentioned in comment #8

The patch is for the latest 1.3 stable version.

vuil’s picture

Version: 8.x-1.3 » 8.x-1.x-dev
StatusFileSize
new1.48 KB

I also created the same patch (#11) but for the latest 8.x-1.x-dev branch.

keescornelisse’s picture

Patch #12 works for me!

wells’s picture

Status: Needs review » Reviewed & tested by the community

Tested and working in Drupal 9.3.5 and PHP 8.0 as well.

In that environment and with content translation enabled a TypeError is thrown when attempting to edit content. This appears to be a duplicate of what is reported in #3157530: array_diff_key(): Expected parameter 1 to be an array, null given in scheduler_content_moderation_integration_scheduler_hide_publish_on_field() and the patch in #12 fixes it.

wells’s picture

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

  • smustgrave committed 4c9f82c on 8.x-1.x
    Issue #3157531: Drupal 9 & PHP 7.4 - PHP Warnings & Notices
    
smustgrave’s picture

Status: Reviewed & tested by the community » Fixed
jonathan1055’s picture

Title: Drupal 9 & PHP 7.4 - PHP Warnings & Notices » Undefined offset: 0 in hook_hide_publish_on_field()

Changed title to be more explicit about the actual fix.

jonathan1055’s picture

Issue summary: View changes

Remove unnecessary log output, so we can see more easily what the problem was.

Status: Fixed » Closed (fixed)

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