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

Blueprint::ensureFieldHasConfig doesn't work as expected when modifying imported fields #10965

Open
conallcoda opened this issue Oct 16, 2024 · 0 comments

Comments

@conallcoda
Copy link

conallcoda commented Oct 16, 2024

Bug description

I am trying to modify the visibility of a field on the fly using a UserBlueprintFound event listener. Unfortunately it does not work as internally the field cannot be found.

How to reproduce

  1. Create new fresh installation via CLI "statamic new example"
  2. Enable pro mode
  3. Create the following fieldset:

resources/fieldsets/custom_fieldset.yaml

title: custom_fieldset
fields:
  - handle: a_custom_field
    field:
      type: text
      display: "A Custom Field"
      visibility: hidden
  1. Import the fieldset to your user blueprint:

resources/blueprints/user.yaml

title: User
tabs:
  main:
    display: Main
    sections:
      -
        fields:
          -
            handle: name
            field:
              type: text
              display: Name
          -
            handle: email
            field:
              type: text
              input_type: email
              display: 'Email Address'
              listable: true
              input: email
          -
            handle: roles
            field:
              type: user_roles
              mode: select
              width: 50
              listable: true
              filterable: false
          -
            handle: groups
            field:
              type: user_groups
              mode: select
              width: 50
              listable: true
              filterable: false
          -
            handle: avatar
            field:
              type: assets
              max_files: 1
              container: assets
          -
            import: custom_fieldset

  1. Add event listener that adapts field config:

/app/Listeners/ModifyUserBlueprint.php

<?php

namespace App\Listeners;


use Statamic\Events\UserBlueprintFound;

class ModifyUserBlueprint
{
    public function handle(UserBlueprintFound $event)
    {
        $blueprint = $event->blueprint;
        if ($blueprint->hasField('a_custom_field')) {
            $blueprint->ensureFieldHasConfig('a_custom_field', ['visiblity' => 'visible']);
        }
    }
}

  1. Try and create a user in the control panel and get the following error message:

image

Logs

No response

Environment

Environment
Application Name: Statamic
Laravel Version: 11.28.0
PHP Version: 8.3.1
Composer Version: 2.7.7
Environment: local
Debug Mode: ENABLED
URL: example.test
Maintenance Mode: OFF
Timezone: UTC
Locale: en

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

Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: log
Queue: sync
Session: file

Statamic
Addons: 0
Sites: 1
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 5.31.0 PRO

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

@duncanmcclean duncanmcclean changed the title User Blueprint::ensureFieldHasConfig not working as expected when modifying imported fields Blueprint::ensureFieldHasConfig doesn't work as expected when modifying imported fields Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants