Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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)
Comment | File | Size | Author |
---|---|---|---|
#21 | img-test-01-2983667.png | 188.77 KB | thalles |
#20 | 2983667-20.test-disbaled-fields.patch | 6.13 KB | jonathan1055 |
|
Comments
Comment #2
captainpants CreditAttribution: captainpants commentedHere's a patch file that solves the issue.
Comment #3
nlisgo CreditAttribution: nlisgo commentedComment #4
nlisgo CreditAttribution: nlisgo commentedComment #5
asherry CreditAttribution: asherry at Aten Design Group for Richland Library commentedThe 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:
And then you can check each component with:
or...
Comment #7
asherry CreditAttribution: asherry at Aten Design Group for Richland Library commentedSorry I had a typo, here is the right patch.
Comment #8
asherry CreditAttribution: asherry at Aten Design Group for Richland Library commentedComment #9
mpp CreditAttribution: mpp at District09 for District09 commentedThanks!
Comment #10
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThanks 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.
Comment #11
nlisgo CreditAttribution: nlisgo commentedComment #12
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedHere 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.
Comment #14
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedNo tests were run because the class name is case-sensitive:
Drupal\Tests\scheduler\functional\SchedulerFieldsDisplayTest
should have been
Drupal\Tests\scheduler\Functional\SchedulerFieldsDisplayTest
Comment #16
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedGood. Just the single test class ran, and we got the required error as expected:
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.
Comment #18
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedWe 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.
Comment #19
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThat'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
Comment #20
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commented... and without the coding standards warnings
Comment #21
thallesWorks for me!
Comment #22
thallesComment #24
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedFixed and committed. Thanks everyone.
Comment #26
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedI 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.