statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
3.7k stars 508 forks source link

Child pages with multiple language "URL IS ALREADY TAKEN" #8328

Open JesperFiltenborg opened 1 year ago

JesperFiltenborg commented 1 year ago

Bug description

I created a child page in 2 languages, and got the error "URL IS ALREADY TAKEN" on the second language. I expected it to return something like "parent page missing language {$site}".

How to reproduce

Create a top-level page with slug: "test-af-already-taken" in the primary site/locale Create a top-level page with slug: "test-af-already-taken2" in all site/locales

Create a child page for: "test-af-already-taken2". ( This should work ) Create a child page for: "test-af-already-taken2" with the sites second site/locale. ( This should return a better error )

Logs

No response

Environment

Environment
Application Name: ********
Laravel Version: 9.52.7
PHP Version: 8.1.13
Composer Version: 2.5.8
Environment: local
Debug Mode: ENABLED
URL: ********.ddev.site
Maintenance Mode: OFF

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

Drivers
Broadcasting: log
Cache: redis
Database: mysql
Logs: stack / daily
Mail: smtp
Queue: redis
Session: redis

Statamic
Addons: 4
Antlers: runtime
Stache Watcher: Enabled
Static Caching: Disabled
Version: 3.4.11 PRO

Statamic Addons
doublethreedigital/duplicator: 3.0.0
jacksleight/statamic-bard-mutator: 2.2.0
pecotamic/sitemap: 1.4.1
statamic/eloquent-driver: 1.2.0

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

None

sandersjj commented 1 year ago

I can confirm that I ran into this issue as well.

duncanmcclean commented 8 months ago

Create a top-level page with slug: "test-af-already-taken" in the primary site/locale Create a top-level page with slug: "test-af-already-taken2" in all site/locales

Create a child page for: "test-af-already-taken2". ( This should work ) Create a child page for: "test-af-already-taken2" with the sites second site/locale. ( This should return a better error )

Just to clarify, you're creating the child entry in "Site A" first, then you're going into "Site B" and creating it there too? Is that when you're receiving the error?

I'm only able to replicate the same error if I:

  1. Create child entry in site A
  2. Create child entry in site B
  3. Then, when I try to localize either of the child entries in the other site, that's when I get the validation error (which is what I'd expect)
JesperFiltenborg commented 8 months ago

@duncanmcclean The problem happens when i create a top-level entry in 2 languages. (Primary language) One called: test-af-already-taken (Secondary language) The other called: test-af-already-taken2

Then when i attempt to create a child page for: test-af-already-taken2 When i do this without creating a child page on the primary language i get the error. URL IS ALREADY TAKEN When the actual problem that happens is "page missing in primary language"

jasonvarga commented 8 months ago

Can you provide your config/statamic/sites.php file and the yaml file for the collection?

JesperFiltenborg commented 8 months ago

Hey @jasonvarga here is the sites.php and the yaml for the collection. Be aware that the collection uses some field sets, so you would need to change them in order for the code to run. But i get this issue with all my collection with that uses multiple languages and has a child pages.

Sites.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Sites
    |--------------------------------------------------------------------------
    |
    | Each site should have root URL that is either relative or absolute. Sites
    | are typically used for localization (eg. English/French) but may also
    | be used for related content (eg. different franchise locations).
    |
    */

    'sites' => [

        'da' => [
            'name'       => 'Danish',
            'locale'     => 'da_DK',
            'url'        => env('APP_URL'),
            'attributes' => [
                'text'     => 'Dansk',
                'hreflang' => 'da-dk',
            ],
        ],

        'en' => [
            'name'   => 'English',
            'locale' => 'en_US',
            'url'    => env('APP_URL') . '/en/',
        ],

    ],
];

Collection yaml file

title: Overview
sections:
  main:
    display: Main
    fields:
      -
        handle: title
        field:
          type: text
          required: true
          display: Name
          localizable: true
          width: 50
          validate:
            - required
      -
        handle: headline
        field: common.headline
        config:
          width: 50
          validate:
            - required
      -
        handle: label
        field: common.label
        config:
          width: 50
      -
        handle: description
        field: common.description
        config:
          width: 50
  seo:
    display: SEO
    fields:
      -
        import: seo
        prefix: meta_
  widget:
    display: Widget
    fields:
      -
        import: widget
        prefix: widget_
  sidebar:
    display: Sidebar
    fields:
      -
        handle: slug
        field:
          type: slug
          localizable: true
          validate:
            - required
      -
        handle: theme
        field: common.theme
        config:
          validate:
            - required
      -
        handle: date
        field:
          type: date
          required: true
          display: Visible
          mode: single
          time_enabled: true
          localizable: false
          validate:
            - required
      -
        handle: parent
        field:
          type: entries
          collections:
            - pages
          max_items: 1
          listable: true
          localizable: true
          create: false
      -
        import: last_edited