statamic / cms

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

Navigations can't access group data when it has a condition #10055

Closed JonKaric closed 3 months ago

JonKaric commented 3 months ago

Bug description

When you create a group and give it a condition of show when, you can no longer access the data if a child precedes it.

Copy the data below and try re-ordering them inside your navigation to see what I mean.

How to reproduce

inside antlers:

<div class="p-10 bg-blue-100">
    {{ nav:test }}
        {{ title }}
        <div class="p-10 m-10 bg-red-200">
            {{ children }}
            {{ title }}
                <span class="block text-xs rounded-full bg-slate-200">
                    Type: {{ type }}
                </span>
                <span class="block text-xs rounded-full bg-slate-200">
                    Columns: {{ test_group.columns }}
                </span>
                <span class="block text-xs rounded-full bg-slate-200">
                    Rows: {{ test_group.rows }}
                </span>
                <span class="block text-xs rounded-full bg-slate-200">
                    Text: {{ test_text }}
                </span>
            {{ /children }}
        </div>
    {{ /nav:test }}
</div>

content/navigation/test.yaml

title: test

content/trees/navigation/default/test.yaml

tree:
  -
    id: 2a92b97a-81c7-45c3-8ac5-51abcfbe2c62
    title: Home
    children:
      -
        id: 93d23cc8-7634-43bc-95b9-b3b934e64468
        title: 'Group 1'
        data:
          type: row
          test_text: null
      -
        id: 9b22f158-4c69-4e03-9be1-181e3fa2fe7d
        title: 'Group 2'
        data:
          type: column
          test_group:
            columns: '2'
            rows: Two
          test_text: 'Group 2'

resources/blueprints/navigation/test.yaml

tabs:
  main:
    display: Main
    sections:
      -
        fields:
          -
            handle: type
            field:
              options:
                column: Column
                row: Row
              type: select
              display: Type
          -
            handle: test_group
            field:
              type: group
              display: 'Test Group'
              if:
                type: 'equals column'
              fields:
                -
                  handle: columns
                  field:
                    options:
                      1: '1'
                      2: '2'
                    type: select
                    display: Columns
                -
                  handle: rows
                  field:
                    type: text
                    display: Rows
          -
            handle: test_text
            field:
              type: text
              display: 'Test Text'
              if:
                type: 'equals column'

Logs

No response

Environment

Environment
Application Name: Statamic
Laravel Version: 10.48.10
PHP Version: 8.2.11
Composer Version: 2.5.5
Environment: local
Debug Mode: ENABLED
Maintenance Mode: OFF

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

Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Livewire
Livewire: v3.4.12

Statamic
Addons: 3
Sites: 2 (en, fr)
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.1.0 PRO

Statamic Addons
jonassiewertsen/statamic-livewire: 3.3.1
statamic-rad-pack/shopify: 3.3.0

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

robdekort commented 3 months ago

Not sure if I understand your issue and if it's similar. But I don't seem to get any navigation blueprint data returned in Antlers for root items. It does seem to work for children (in my case).

tree:
  -
    id: c818add2-f657-474b-ae28-fa4cec914bc2
    title: Follow
    data:
      contents: social_media
{{ nav:footer max_depth="2" select="contents|title|url|collection_source|buttons" }}
   {{ contents | dump }}

This dumps nothing. Only the Title and URL are available. When I dump the whole nav I don't see the data:

Screenshot 2024-05-14 at 08 55 58
JonKaric commented 3 months ago

@robdekort Do you have any conditions anywhere? That is what seems to be messing mine up, but only for groups.

robdekort commented 3 months ago

What do you mean with groups? Even without conditions the data doesn't seem available on root items. Only on children (in my case).

JonKaric commented 3 months ago

Group fieldtypes (and possibly other fields that produce the same data structure, but I didn't test them)

robdekort commented 3 months ago

Gotcha!

robdekort commented 3 months ago

Mine might be a separate issue. We'll see :-)

duncanmcclean commented 3 months ago

Mine might be a separate issue. We'll see :-)

It seems like both issues are related 😄

Reverting the changes made in https://github.com/statamic/cms/pull/9636 seem to fix both issues.

robdekort commented 3 months ago

Ah good. Jason suggested I create a separate one so it doesn’t get lost. I’ll do that tomorrow.