"Published" checkbox is always checked even if the entity is not

Created on 29 January 2025, 5 months ago

Overview

While working on โœจ [PP-1] Connect "new page" with API to create new pages Postponed I noticed the published checkbox is always checked. Even though the entity is not.

Proposed resolution

Probably due to "0" string value. The value is status[value]:"0".

User interface changes

๐Ÿ› Bug report
Status

Active

Version

0.0

Component

Page builder

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States mglaman WI, USA

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

Merge Requests

Comments & Activities

  • Issue created by @mglaman
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mglaman WI, USA
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia roshni upadhyay

    roshni upadhyay โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia roshni upadhyay

    The issue with the API is that when a node is updated, the updated content is not reflected in the API response. Instead, the API continues to return the old data. This problem occurs because the following code retrieves data from the auto-save manager, which may not have the latest changes:

    if ($body = $this->autoSaveManager->getAutoSaveData($entity)) {
        ['layout' => $layout, 'model' => $model, 'entity_form_fields' => $entity_form_fields] = $body;
    }
    
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia roshni upadhyay

    roshni upadhyay โ†’ changed the visibility of the branch 3503199-published-checkbox-is to hidden.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia roshni upadhyay

    roshni upadhyay โ†’ changed the visibility of the branch 3503199-published-checkbox-is to hidden.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia roshni upadhyay

    roshni upadhyay โ†’ changed the visibility of the branch 3503199-published-checkbox-is to active.

  • Pipeline finished with Failed
    4 months ago
    Total: 1198s
    #421013
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Debugged this.

    #5 is inaccurate AFAICT.

    Debugging trail

    1. Create a fresh node with status: false. Say, node 4.
    2. Load it in Experience Builder at /xb/node/4/editor. Observe that the toggle is toggled on.
    3. Put a breakpoint in the code that generates this form: \Drupal\experience_builder\Controller\EntityFormController::form(). Observe this is the return value:

      Most importantly: #value === FALSE.
    4. In \Drupal\Core\Render\Element\Checkbox::preRenderCheckbox(), that's still the case.
    5. โš ๏ธ However, that maps the #return_value Form API property to the value attribute:
      Element::setAttributes($element, ['id', 'name', '#return_value' => 'value']);
      

      which results in

    6. Look at the corresponding FE code: /ui/src/components/form/components/drupal/DrupalToggle.tsx. It contains this:
        <Toggle
          checked={!!attributes?.value}
      

      โ€ฆ which appears accurate but isn't. The value attribute for <input type="checkbox"> is very interesting ๐Ÿคช, see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox....

      So AFAICT the problem lies in DrupalToggle, which was introduced in ๐Ÿ“Œ Split form components into `Drupal`-prefixed behavioral wrappers and presentational components Needs work .

    Looking at /node/<nid>/edit
    • checked "published" checkbox: <input data-drupal-selector="edit-status-value" type="checkbox" id="edit-status-value" name="status[value]" value="1" class="form-checkbox form-boolean form-boolean--type-checkbox">
    • unchecked "published" checkbox:
      <input data-drupal-selector="edit-status-value" type="checkbox" id="edit-status-value" name="status[value]" value="1" checked="checked" class="form-checkbox form-boolean form-boolean--type-checkbox">
      

    ๐Ÿ‘† That's the markup being generated outside of XB. That's the starting point for things we do on top.

    Tentative conclusion: needs only front-end changes?

    So AFAICT updating DrupalToggle should work? But

    -    checked={!!attributes?.value}
    +    checked={!!attributes?.checked}
    

    didn't do the trick ๐Ÿ˜…

    I'm getting lost between:

    1. ui/src/components/form/components/Checkbox.tsx
    2. ui/src/components/form/components/drupal/DrupalInput.tsx
    3. ui/src/components/form/components/Toggle.tsx
    4. ui/src/components/form/components/drupal/DrupalToggle.tsx

    โ€ฆ because all four of those (!!!) are dealing with the checked attribute ๐Ÿ˜… AFAICT only the last 2 are relevant. I changed both like indicated above, without success.

    I've done the due diligence, and think it's now down to somebody who knows the Semi-Coupled theme engine well enough to finish it up. It probably takes them only minutes given the digging I've done so far ๐Ÿคž

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia swarad07 Navi Mumbai, India
    -    checked={!!attributes?.value}
    +    checked={!!attributes?.checked}
    

    That should be the way, as the correct attribute to check should be `checked` and not `value`

    However, the other issue seems to be that the `attributes.checked` is coming as `true` always.

    I am guessing somewhere in the flow that the `value` parameter of `1` is getting associated with the `checked` HTML attribute as `true`.

    Needs further digging.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands balintbrews Amsterdam, NL

    I made an update to the DrupalToggle component in โœจ Defining props for code components Active , then @jessebaker pointed me at this issue.

    Can someone, please, help me with steps to reproduce? We have solid investigation bits by Wim in #10 โ†’ , but I'm having a hard time to see how to actually reproduce the problem โ€” unless it went away. (At the time of writing this comment, โœจ Defining props for code components Active is not in, but I don't think that will fix this anyway.)

  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland lauriii Finland

    @balintbrews Added steps to the IS ๐Ÿ˜Š

  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland lauriii Finland

    Adding a gif

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Added STR for using article nodes.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia roshni upadhyay

    I have made some changes in ui/src/components/form/components/inputBehaviors.tsx which resolved the checkbox issue Still we have issue with moving a node from published to draft state. Need to check the checkbox value for onChange event as when we change any content it makes the checkbox published and also update the node status.

  • Pipeline finished with Failed
    4 months ago
    Total: 1130s
    #424039
  • Pipeline finished with Failed
    4 months ago
    Total: 1159s
    #424498
  • First commit to issue fork.
  • Pipeline finished with Skipped
    4 months ago
    #430773
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom jessebaker

    Thanks, merged!

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

Production build 0.71.5 2024