Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slug localisation is always reset to true when updating blueprint #7082

Closed
tao opened this issue Nov 18, 2022 · 6 comments · Fixed by #7087
Closed

Slug localisation is always reset to true when updating blueprint #7082

tao opened this issue Nov 18, 2022 · 6 comments · Fixed by #7087

Comments

@tao
Copy link
Contributor

tao commented Nov 18, 2022

Bug description

Everytime you save a Blueprint, it sets the slug localizable property to true, so even if you manually update the blueprint and set localizable: false when the save the blueprint again it'll overwrite it.

Screenshot 2022-11-18 at 16 35 38

Here you can see the slug field was not localizable, and the Vue devtools reflect that.

Screenshot 2022-11-18 at 16 39 10

Above you can see the PATCH request, and the localizable field is still false.

Screenshot 2022-11-18 at 16 37 04

Now, when you view the blueprint or reload the page it says the localizable field is true.

How to reproduce

Change the blueprint field localizable: false and save the blueprint in the Control Panel.

Logs

No response

Environment

Environment
Laravel Version: 9.24.0
PHP Version: 8.0.24
Composer Version: 2.0.11
Environment: local
Debug Mode: ENABLED
URL: localhost
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: pusher
Cache: statamic
Database: sqlite
Logs: stack / single
Mail: smtp
Queue: sync
Scout: elasticsearch
Session: file

Statamic
Addons: 3
Antlers: runtime
Version: 3.3.28 PRO

Statamic Addons
statamic/collaboration: 0.4.0
statamic/ssg: 1.2.0

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

runtime (new)

Additional details

Related to Make multisite great again.

@tao
Copy link
Contributor Author

tao commented Nov 18, 2022

By the time the code reaches the BlueprintRepository::save($this) line of code, the localizable field is no longer included if it's false, it's only included in the data if localizable: true

https://github.com/statamic/cms/blob/3.3/src/Fields/Blueprint.php#L410

With localizable: true the data in $this looks like this, you can see the field localizable exists.

      "sidebar" => array:2 [
        "display" => "Sidebar"
        "fields" => array:2 [
          0 => array:2 [
            "handle" => "slug"
            "field" => array:5 [
              "type" => "slug"
              "localizable" => true
              "generate" => false
            ]
          ]
        ]

With localizable: false on the frontend the data in $this looks like, it's missing... so when you try write the field it must default back to true.

      "sidebar" => array:2 [
        "display" => "Sidebar"
        "fields" => array:2 [
          0 => array:2 [
            "handle" => "slug"
            "field" => array:4 [
              "type" => "slug"
              "generate" => false
            ]
          ]
        ]

So the field needs to be included even if the value is false.

@tao
Copy link
Contributor Author

tao commented Nov 18, 2022

The bug is in this line which unsets the localizable field: https://github.com/statamic/cms/blob/3.3/src/Fields/FieldTransformer.php#L35

If you uncomment that then it works fine... is there a purpose for why that line was added initially that we need to work around?

@jasonvarga
Copy link
Member

That'd be so that you don't get localizable: false in the yaml, because it's the default state. Same as if it were just not there at all.

There's no harm in it being there, though, if removing the line of code is the solution.

@tao
Copy link
Contributor Author

tao commented Nov 18, 2022

Maybe we can check if localizable: true exists in the blueprint and only include localizable: false if necessary to overcome this bug? Or maybe easier to check if multisite is enabled and then include it by default.

@tao
Copy link
Contributor Author

tao commented Nov 18, 2022

The problem for me is anytime the blueprint updates for any reason it overwrites localizable, then I have to manually update every yaml file on my server again... so I can't give editors on the website access to the blueprints yet.

@tao
Copy link
Contributor Author

tao commented Nov 19, 2022

I made a pull request to detect if it's multi-site and allow the variable to be false. This change won't affect blueprints without multisite. I also found the slug field defaults to localizable: true even if multi-site is not enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants