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

Using the same names for fields causes the fields not to appear in the editor. #273

Closed
pkosciak opened this issue Aug 3, 2024 · 1 comment · Fixed by #276
Closed

Using the same names for fields causes the fields not to appear in the editor. #273

pkosciak opened this issue Aug 3, 2024 · 1 comment · Fixed by #276

Comments

@pkosciak
Copy link

pkosciak commented Aug 3, 2024

Hey, this is something I came across while creating blocks based on the description in the README file. If you create Blocks/Example.php and Fields/Example.php and both files contain a field with the same name, then one of them overrides the other (I suppose?). And consequently, one of the fields doesn't appear in the editor.

public function fields(): array
{
    $example = Builder::make('example'); // <-- this part, if you name it 'example' in both files

    $example
        ->addRepeater('items')
            ->addText('item')
        ->endRepeater();

    return $example->build();
}

Additionally, if you also create an option page with such a field (Options/Example.php), it will appear on the option page but will completely disappear from both the block and field.

I didn't see any mention that you cannot name fields with the same name, and if this is the case, then I think there should be some kind of warning that something is not right. It took me a while to figure out what was going on; I thought my other code had broken something.

@pkosciak pkosciak changed the title Same names for fields cause fields not appearing in the editor Using the same names for fields causes the fields not to appear in the editor. Aug 3, 2024
@Log1x
Copy link
Owner

Log1x commented Aug 3, 2024

i think this is an ACF limitation. i will fix the docs to append the type at the end of the names like ExampleOptions and look into maybe throwing an exception in this situation 👍

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