Publish status and unpublish status field weights reset when schedule settings are editted

Created on 6 June 2023, almost 2 years ago

Problem/Motivation

When scheduler settings are editted, the publish_state form widget resets to a weight of 53 and the unpublish_state form widget resets to a weight of 55 on the entity form display.

Steps to reproduce

  • Install and enable scheduler and scheduler content moderation integration.
  • On a content type that has moderation states enabled, save the entity form display with the scheduler fields in the order you desire.
  • Save the entity settings with or without a change to the scheduler fields.
  • Go back to the entity form display and view sort weights.

Proposed resolution

These weights seem to be set as the default in scheduler_content_moderation_integration.module starting around line 409, but unlike Scheduler, it's not checking to see if the value was set as a default and is resetting the hardcoded weights on every save.

To match the code in scheduler, $form_state->getValue('scheduler_publish_enable') needs to be changed to !$form['scheduler']['publish']['scheduler_publish_enable']['#default_value'] so that the widget doesn't reset to the default every time.

Merge request is forthcoming.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States joshuami Portland, OR

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @joshuami
  • Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update almost 2 years ago
    Not currently mergeable.
  • @joshuami opened merge request.
  • πŸ‡ΊπŸ‡ΈUnited States joshuami Portland, OR

    I need to spend a bit of time figuring out how to actually create a merge request in an issue. Adding a patch for now.

  • Status changed to RTBC almost 2 years ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update almost 2 years ago
    51 pass
  • πŸ‡ΊπŸ‡ΈUnited States pcate

    Ran into this same issue. Steps to reproduce were accurate and patch resolves issue.

  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Patch no longer applies to 2.x so wonder if this is still an issue there?

  • Assigned to joshuami
  • πŸ‡ΊπŸ‡ΈUnited States joshuami Portland, OR

    It's still needed. Just needs a reroll. #3359796: Skip form displays that don't exist. β†’ added some lines above the function the patch was updating. I'll see if I can get a new patch posted today or tomorrow.

  • πŸ‡ΊπŸ‡ΈUnited States joshuami Portland, OR

    And here we go. New patch with new line numbers.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    51 pass
  • πŸ‡ΊπŸ‡ΈUnited States joshuami Portland, OR
  • First commit to issue fork.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    51 pass
  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    I have sorted out the MR branch, cherry-picked the missing commits that have been made to 2.x since this issue was opened, then added the changes in the new patch from joshuami in #7

    Do we have any test coverage for these forms?

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    I think that the test failures in the GitLab pipeline (which run D10) are unrelated to this chnage. I have raised #3390920: Replace assert[Not]Equals() in tests β†’ to deal with that problem.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    51 pass
  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    I have fixed #3390920: Remove markup in assertEquals() and fix strToLower NULL deprecations β†’ so this MR pipeline now passes green. We do not have any test coverage for this though.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    51 pass
  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Will admit a lot of the modules I have don't have test case (I know terrible practice!) but since this project does have tests think we should add one for this issue.

  • πŸ‡ΊπŸ‡ΈUnited States joshuami Portland, OR

    In a project using this patch, we just discovered an edge case that wasn't covered when scheduling media. It only occurs when creating new media, but the publish status sort weight changes back to 53 when the error is triggered before the media entity is saved. I can't reproduce this for content entities, so it may be an issue upstream in core media. I'll try an dig into this a little more as time permits.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Fixes will need to be against 3.0.x

  • First commit to issue fork.
  • Pipeline finished with Success
    6 months ago
    Total: 331s
    #314150
  • πŸ‡ΊπŸ‡ΈUnited States capysara

    Created a MR against 3.0.x and hiding the previous branches.

    This patch still works on on 3.0.3. I didn't make any updates.

    #14 still has an open question.
    Still needs test coverage, per #13.

  • πŸ‡ΊπŸ‡ΈUnited States capysara

    capysara β†’ changed the visibility of the branch 3365161-publish-status-and to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States capysara

    capysara β†’ changed the visibility of the branch 3.0.x to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States capysara

    capysara β†’ changed the visibility of the branch 3365161-publish-status-and-patch-3ac7 to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States pcate

    Per #13 β†’ I added a functional test to confirm the field weight reset fix.

    Branch seems to have failing tests but don't appear to be related.

  • πŸ‡ΊπŸ‡ΈUnited States pcate
  • Pipeline finished with Failed
    6 months ago
    #331548
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Just re-ran the 3.0.x pipeline and minus some phpcs for use statements the pipeline tests are green. So these failures may be legit.

  • πŸ‡ΊπŸ‡ΈUnited States pcate

    @smustgrave I went ahead and tried running all the module tests locally with the latest 3.x dev branch. The LayoutBuilderTest functional test always failed for me, and all the other tests passed, with and without this issue's MR changes added. The new FormDisplayWeightTest test always passed for me with the MR changed applied.

    Below is the error from the failing LayoutBuilderTest test. I get the same error when I ran just the LayoutBuilderTest test by itself.

    Testing /var/www/html/docroot/modules/contrib/scheduler_content_moderation_integration
    ....................E...............................              52 / 52 (100%)
    
    Time: 06:39.901, Memory: 8.00 MB
    
    There was 1 error:
    
    1) Drupal\Tests\scheduler_content_moderation_integration\Functional\LayoutBuilderTest::testLayoutBuilder
    Behat\Mink\Exception\ExpectationException: Current response status code is 500, but 200 expected.
    
    /var/www/html/vendor/behat/mink/src/WebAssert.php:888
    /var/www/html/vendor/behat/mink/src/WebAssert.php:145
    /var/www/html/docroot/modules/contrib/scheduler_content_moderation_integration/tests/src/Functional/LayoutBuilderTest.php:44
    /var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:729
    
    ERRORS!
    Tests: 52, Assertions: 1356, Errors: 1.
    

    I did also got the following deprecation notice when running the tests:

    Remaining self deprecation notices (1)
    
      1x: system_time_zones() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. This function is no longer used in Drupal core. Use \Drupal\Core\Datetime\TimeZoneFormHelper::getOptionsList(), \Drupal\Core\Datetime\TimeZoneFormHelper::getOptionsListByRegion() or \DateTimeZone::listIdentifiers() instead. See https://www.drupal.org/node/3023528
        1x in LayoutBuilderTest::testLayoutBuilder from Drupal\Tests\scheduler_content_moderation_integration\Functional
    

    Would a test fail because of the deprecation notice?

    I ran all the modules tests about a half-dozen times with the same results.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    That’s odd? I merged in an issue yesterday which ran the pipeline probably 3-5 times no issue

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    The failing test may be caused by the Twig version, the composer job log shows twig/twig (v3.14.1) which has a timeout problem, and woud cause the problem of not finding expected elements on the form. The previous pipeline on this MR had (v3.14.0) which does not have the problem. However, jobs today should be using v3.14.2 which was released yesterday to fix the problem. Is this project locked to twig 3.14.1 ? πŸ’¬ Updating phpstan and twig via Composer generates a blank page when editing a node Active has the background.

  • πŸ‡ΊπŸ‡ΈUnited States pcate

    The failing test may be caused by the Twig version, the composer job log shows twig/twig (v3.14.1) which has a timeout problem, and woud cause the problem of not finding expected elements on the form. The previous pipeline on this MR had (v3.14.0) which does not have the problem.

    Yeah, looks like that was the problem. I re-ran the composer build stage and that installed twig/twig (v3.14.2). Tests seem to be passing now.

  • πŸ‡ΊπŸ‡ΈUnited States pcate
Production build 0.71.5 2024