I'm trying to add 2 options to the field settings of all fields of a particular field type, in this case file field. To add the fields to the form I'm using MYMODULE_form_field_config_edit_form_alter()
instead of extending the base class so it will work with other modules and I won't need to use a custom field type.
Using ThirdPartySettings to store the data doesn't add it to the base config for the field therefore the settings won't be automatically available to other modules.
e.g.
function MYMODULE_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$field = $form_state->getFormObject()->getEntity();
if ($field->getType() == 'file') {
$settings = $field->getSettings();
$form['my_checkbox'] = [
'#type' => 'checkbox',
'#title' => t('My Checkbox'),
'#default_value' => isset($settings['my_checkbox']) ? $settings['my_checkbox'] : '',
'#description' => t('Check to check my checkbox.'),
];
$form['#entity_builders'][] = 'MYMODULE_form_builder';
}
}
function MYMODULE_form_builder($entity_type, FieldConfig $field, &$form, FormStateInterface $form_state) {
// What goes here? I can't do $field->set() on properties which don't exists.
}
I've tried setting up a schema file as src/config/scheme/mymodule.schema.yml
but I'm not sure how to extend the relevant settings in core/modules/file/config/schema/file/schema.yml
.
base_file_field_field_settings
seems to have the relevant entries I'm wanting to add to. Do I need to add a class or an install yml file?