public function ConfigFormBuilder::assignDisableFieldThirdPartySettingsToEntity in Disable Field 8.2
Assign the disable field settings to the given entity.
Parameters
string $entity_type: The entity type.
\Drupal\Core\Field\FieldConfigInterface $field_config: The field config entity.
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
File
- src/
ConfigFormBuilder.php, line 196
Class
- ConfigFormBuilder
- Class ConfigFormAlter.
Namespace
Drupal\disable_fieldCode
public function assignDisableFieldThirdPartySettingsToEntity(string $entity_type, FieldConfigInterface $field_config, array &$form, FormStateInterface $form_state) {
$add_option = $form_state
->getValue([
'disable_field',
'add',
'disable',
]);
$add_roles = $form_state
->getValue([
'disable_field',
'add',
'roles',
]);
$field_config
->setThirdPartySetting('disable_field', 'add_disable', $add_option);
$field_config
->unsetThirdPartySetting('disable_field', 'add_roles');
if (in_array($add_option, [
'roles',
'roles_enable',
])) {
$field_config
->setThirdPartySetting('disable_field', 'add_roles', array_keys($add_roles));
}
$edit_option = $form_state
->getValue([
'disable_field',
'edit',
'disable',
]);
$edit_roles = $form_state
->getValue([
'disable_field',
'edit',
'roles',
]);
$field_config
->setThirdPartySetting('disable_field', 'edit_disable', $edit_option);
$field_config
->unsetThirdPartySetting('disable_field', 'edit_roles');
if (in_array($edit_option, [
'roles',
'roles_enable',
])) {
$field_config
->setThirdPartySetting('disable_field', 'edit_roles', array_keys($edit_roles));
}
}