The following notice Notice: Undefined index: unpublish_on in scheduler_form_node_form_alter() (line 181 of modules/contrib/scheduler/scheduler.module appears when setting the view mode of a publish or unpublish field in the form display to disabled.

(The scheduler fields can be disabled via Edit content type -> manage form display -> drag unpublish_on into 'disabled' section)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

captainpants created an issue. See original summary.

captainpants’s picture

nlisgo’s picture

Assigned: Unassigned » nlisgo
Issue tags: +Needs reroll
nlisgo’s picture

Assigned: nlisgo » Unassigned
Status: Active » Needs review
Issue tags: -Needs reroll
FileSize
2.3 KB
asherry’s picture

The solution in #4 gets rid of the error, but the form elements are still being populated. It seems like it'd be better to just skip the entire form_alter altogether if either of the elements are hidden.

I'm attaching a patch that will just simply bail if the components aren't displayed. At the very least an easier way to get the display info is:

$display = $form_state->getFormObject()->getFormDisplay($form_state);

And then you can check each component with:

$display->getComponent('unpublish_on');

or...

$display->getComponent('publish_on');

Status: Needs review » Needs work

The last submitted patch, 5: 2983667.patch, failed testing. View results

asherry’s picture

FileSize
725 bytes

Sorry I had a typo, here is the right patch.

asherry’s picture

Status: Needs work » Needs review
mpp’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

jonathan1055’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for the work and the patch. However, are you sure that it is correct to bail out with an OR test? That means if either of the components are not displayed we process no further.

We also need test coverage for this.

nlisgo’s picture

Issue tags: +Needs tests
jonathan1055’s picture

Title: Notice: Undefined index: unpublish_on in scheduler_form_node_form_alter() (line 181 of modules/contrib/scheduler/scheduler.module » Disabling a scheduler field gives undefined index: unpublish_on in scheduler_form_node_form_alter()
Issue summary: View changes
Status: Needs work » Needs review
FileSize
4.14 KB

Here is patch which adds a test to make sure that a disabled scheduler field is not displayed, that the non-disabled field is still displayed, and that the undefined index error does not occur. This will fail because this patch only includes the new test, and not any code fix from scheduler_form_node_form_alter().

I am also attempting, via a change to the newly added drupalci.yml, to only run this one test class. This might need a re-run if I have not got the syntax right.

Status: Needs review » Needs work

The last submitted patch, 12: 2983667-12.test-disbaled-fields.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jonathan1055’s picture

Status: Needs work » Needs review
FileSize
3.76 KB

No tests were run because the class name is case-sensitive:
Drupal\Tests\scheduler\functional\SchedulerFieldsDisplayTest
should have been
Drupal\Tests\scheduler\Functional\SchedulerFieldsDisplayTest

Status: Needs review » Needs work

The last submitted patch, 14: 2983667-14.test-disbaled-fields.patch, failed testing. View results

jonathan1055’s picture

Status: Needs work » Needs review
FileSize
4.47 KB

Good. Just the single test class ran, and we got the required error as expected:

There was 1 error:
1) Drupal\Tests\scheduler\Functional\SchedulerFieldsDisplayTest::testDisabledFields
Exception: Notice: Undefined index: publish_on
scheduler_form_node_form_alter()() (Line: 181)

Here is the new test, with the added change from #7. As I mentioned in #10 I don't think this will solve the problem properly.

Status: Needs review » Needs work

The last submitted patch, 16: 2983667-16.test-disbaled-fields.patch, failed testing. View results

jonathan1055’s picture

Status: Needs work » Needs review
FileSize
6.63 KB

We can't just bail out at the top if either of the fields are disabled. We can bail out if both are disabled, but need to cater for the case when one is and one is not.

jonathan1055’s picture

That's good. Now, just to check the complete test run.

If anyone would like to test this patch, you will need to download the latest dev, as there have been other recent changes. When done please mark the issue RTBC then I will commit it.

Jonathan

jonathan1055’s picture

Issue tags: -Needs tests
FileSize
6.13 KB

... and without the coding standards warnings

thalles’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
188.77 KB

Works for me!

thalles’s picture

  • jonathan1055 committed 944c06d on 8.x-1.x
    Issue #2983667 by jonathan1055, asherry, captainpants, nlisgo: Disabling...
jonathan1055’s picture

Status: Reviewed & tested by the community » Fixed

Fixed and committed. Thanks everyone.

Status: Fixed » Closed (fixed)

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

jonathan1055’s picture

I had a request from a user who is running Scheduler 1.0 (not the dev version) and would like to apply this fix. So here is a modified patch which applies to 8.x-1.0. It just fixes scheduler.module, there was no need to add the new test to this patch.