The calculated machine is not synced when the source value is defined and the machine name is empty.

Created on 4 April 2024, about 1 year ago

Problem/Motivation

The calculated machine is not synced when the source value is defined and the machine name is empty.

Steps to reproduce

  • Create a form using the below elements.
  • Notice how the machine is set and correct
  • Change the title and machine name is not updated.
    $form['id'] = [
      '#type' => 'machine_name',
      '#default_value' => $webform->id(),
      '#machine_name' => ['source' => ['title']],
    ];
    $form['title'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Title'),
      '#default_value' => 'A default title',
      '#id' => 'title',
    ];

Proposed resolution

Adjust the machine_name.js to properly sync the calculated machine name,

Remaining tasks

Determine a solution
Create MR
Commit MR

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

πŸ› Bug report
Status

Active

Version

10.2 ✨

Component
FormΒ  β†’

Last updated 3 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

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

Merge Requests

Comments & Activities

  • Issue created by @jrockowitz
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    I created an MR. I don't do any core development, so forgive me if I do something wrong.

    The fix could be as simple as looking at the initial machine name and not the calculated machine name.

    In 10.1.x, the code worked because the machine was being calculated via transliterate Ajax request which would set the target value after the event handler was initialized.

    https://git.drupalcode.org/project/drupal/-/blob/10.2.x/core/misc/machin...
    https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/misc/machin...

    I hope this helps.

  • Pipeline finished with Success
    about 1 year ago
    Total: 478s
    #138035
  • Status changed to Needs work 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States xjm

    Thanks @jrockowitz! The only thing is that we need the MR to be created against 11.x, since issues are committed there first and then backported. Trying to switch the target branch can get really messy, so sometimes it's best to close the previous MR and re-create it against 11.x with a cherry-pick or whatever.

    This also seems like a bug that should get some FunctionalJS test coverage, if it's a JS bug.

    Thanks!

  • First commit to issue fork.
  • Merge request !11423Update machine name β†’ (Open) created by dcam
  • Pipeline finished with Failed
    3 months ago
    Total: 462s
    #443684
  • πŸ‡ΊπŸ‡ΈUnited States dcam

    I added an assertion to MachineNameTest in a new D11 branch. I haven't added the fix created by @jrockowitz yet. That new assertion failed as expected. I'll commit the fix and see what happens.

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

    Added info to the steps to reproduce. This is reproducible out-of-the-box with one of core's testing modules.

  • Pipeline finished with Success
    3 months ago
    Total: 863s
    #443689
  • πŸ‡ΊπŸ‡ΈUnited States dcam

    dcam β†’ changed the visibility of the branch 3438739-calculated-machine-name to hidden.

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

    Manually tested this following the steps.

    Went to /form-test/machine-name
    Changed the label and machine name did not change
    Applying the MR and repeating
    The machine name is changing

    Summary seems to match the solution and has test coverage.

    LGTM

  • πŸ‡³πŸ‡ΏNew Zealand quietone
  • Status changed to Closed: works as designed 15 days ago
  • πŸ‡«πŸ‡·France nod_ Lille

    This is a feature, not a bug.

    Check out the 3 lines of comments just before the code change:

    // Preview the machine name in realtime when the human-readable name
    // changes, but only if there is no machine name yet; i.e., only upon
    // initial creation, not when editing.

    You want to be able to change the label without changing the machine name. Happens all the time that some vocabulary is renamed to be clearer to end-users but you want to keep the machine name to not mess with config export and custom code.

Production build 0.71.5 2024