bolt/docs

RFC fields inside a set inside a collection can't be named "name"

eduardomart opened this issue · 3 comments

I believe this is related to: #1025

sidebar:
    ...
    fields:
        socialnetworks:
            label: "Social Networks"
            type: collection
            fields:
                socialnetwork:   # <----------------- this is always the output of 'name'
                    type: set
                    label: Social Network
                    fields:
                        name:        # <------------------ this can't be accessed, unless it's renamed to something else
                            label: Name
                            type: text
                        icon:
                            label: Icon
                            type: text
                        link:
                            label: Link
                            type: text
            group: content
   ...
  singleton: true

And you try to iterate the 'socialnetworks':

{% set content sn = 'contenttype' %}

{% for item in sn.socialnetworks %}
   {{ item.name }}
{% endfo%}

you will always get "socialnetwork" output in each iteration, however if you rename the text field "name" to something different like "title" then you get the actual value of the text field.

I think this needs to be clarified still in the docs, or maybe make a note that "name" shouldn't be used inside collection fields...

Yesss! Essentially all the getter methods in the Field entity cannot be used as names for fields. Let's update the docs on that.

@I-Valchev but this would only be the case for fields within collections, correct? because it seems regular fields can use the name name so I don't know if this might lead to confusion for users.

Yes, you are right!

Essentially:
If there's a getX method in Content.php -> x cannot be the name of a field.
If there's a getY method in Field.php (and all methods from field classes) -> y cannot be the name of a field inside a collection/set.