Problem/Motivation

When you hide the time element, the default time setting is ignored. The saved value is current hour / minute. The core code ignores the time input if the element is set to 'none'.

Steps to reproduce

Configure a default time and alter the element to set the #date_time_element to 'none'.

Proposed resolution

Temporarily change the time element to 'time' so the given input is correctly stored.

Issue fork scheduler-3175184

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

nils.destoop created an issue. See original summary.

nils.destoop’s picture

Status: Active » Needs review
StatusFileSize
new947 bytes

Following patch fixes the issue.

jonathan1055’s picture

Hi nils.destoop,

Thanks for reporting this and for the patch. Did you hide the field with a hook_form_alter() or via a UI ? Can you share precisely how you achieved it.

Also we need an additional test within SchedulerDefaultTimeTest to demonstrate the problem, and then show that it is fixed by your patch. Can you write that? If not, I can.

Jonathan

nils.destoop’s picture

Idd, the form element was altered in a form alter:

  if (isset($form['publish_on'])) {
    $form['publish_on']['widget'][0]['value']['#date_time_element'] = 'none';
    $form['unpublish_on']['widget'][0]['value']['#date_time_element'] = 'none';
  }

For te test, we will probably need a separate test module that adds the form alter.

jonathan1055’s picture

Title: Default time fails if the date_time_element is set to none » Default time is not set correctly if the time element is hidden
Issue summary: View changes
StatusFileSize
new10.16 KB

Here's a patch which adds a new test to cover this problem. I added a new scheduler_extras test module which has the hook_form_node_form_alter() to hide the time elements as described in #4. So this patch should fail.

Status: Needs review » Needs work

The last submitted patch, 6: 3175184-6.default-time-hidden-test-only.patch, failed testing. View results

jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new12.64 KB

As intended, we get the error The text "Hidden Time Elements jcQibHiq is scheduled to be published Monday, November 16, 2020 - 06:30 and unpublished Tuesday, November 17, 2020 - 06:30" was not found anywhere in the text of the current page.. Here's a patch with the new test and the fixed widget as per patch #2

jonathan1055’s picture

StatusFileSize
new12.64 KB

Cancelled as the one critical line was commented out. Correct patch is #9

  • jonathan1055 committed 09c5506 on 8.x-1.x
    Issue #3175184 Default time not set when time element is hidden
    
jonathan1055’s picture

Status: Needs review » Fixed

Thanks @nils.destoop for reporting this and for providing the code fix. I used the new Merge Request function, and let the commit message take its default value. I now see that this did not include you as an author, sorry about that.

I think that when this issue is marked as fixed, you should get an 'issue' credit, even though I cannot now change the git commit to give you a 'commit' credit.

Status: Fixed » Closed (fixed)

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