How can I add fields in fields.yaml but prevent them to be added to any form. I want to add these fields only with the method 'formRenderField'
Asked
Active
Viewed 1,263 times
0
-
I don't understand your question. If you don't want a field to be added to any form, simply don't put it in the `fields.yaml` file. Do you want to display the field in the form or not? – B Faley Dec 04 '17 at 13:43
1 Answers
1
I guess if you want to extend them then you can directly write inside "fields.yaml" file and create different version of it and use them to render form based on conditions
<?php namespace Acme\Blog\Controllers;
class Categories extends \Backend\Classes\Controller
{
public $implement = ['Backend.Behaviors.FormController'];
public $formConfig = 'form_config.yaml';
}
this is normal approach
but you can put condition in constructor to change config file
public __construct() {
// if condition is true then use this config otherwise use regular one
if(condition) {
$this->formConfig = 'modified_form_config.yaml';
}
}
another approach is to extend forms based on conditions, like :
UsersController::extendFormFields(function($form, $model, $context){
if (!$model instanceof UserModel)
return;
$form->addFields([
'store' => [
'label'=> 'Store',
'type'=>'relation',
'nameFrom'=> 'name'
],
]);
});
you can write this code in plugin Boot method
here we are adding fields when UserController is called and only when it tries to render UserModel model.
if you need some custom scenarios please describe more so we can help you in better way.

Hardik Satasiya
- 9,547
- 3
- 22
- 40