Showing a field based on the type of authenticated user
Created 7 years ago by pnicolau

Hi everyone, i am just started testing pyrocms, so far i am enjoying it alot.

Is it possible to show or hide a field based of the type of user that is authenticated, for example show the field "internal_comments" only to admin and salesmen in the admin form or in public form.

I was wondering if there is any option that enable this functionality in the form builder or in a stream migration or other way of doing this.

Best regards Pedro Nicolau

ryanthompson  —  7 years ago

Hey there! Glad you're enjoying yourself 😊

You can limit / define fields dynamically using a "field handler". If you have FooFormBuilder the handler would be FooFormFields and sit right next to it. The handler accepts the $builder in it's handle method.. From there you can do $builder->setFields($fields) dynamically.

Check out this example: https://github.com/anomalylabs/pages-module/blob/master/src/Page/Form/PageFormFields.php

ryanthompson  —  7 years ago

PS: You can do this for any UI components.