function rac_form_field_storage_config_edit_form_alter in Role Access Control 8.2
Same name and namespace in other branches
- 8 rac.module \rac_form_field_storage_config_edit_form_alter()
Implements hook_form_FORM_ID_alter().
Add a setting to role access fields to enable access controll baded on the fields value. This allows us to add role type fields that are not restricted rac.
File
- ./
rac.module, line 325 - Module providing role access relations.
Code
function rac_form_field_storage_config_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Get form object and field we are editing.
$form_obj = $form_state
->getFormObject();
$field_storage = $form_obj
->getEntity();
if ($field_storage
->getType() !== "entity_reference") {
// We only want to modify entity reference fields. If not, exit.
return $form;
}
$racEntityTypes = _rac_get_supported_entity_types();
$host_type = $field_storage
->getTargetEntityTypeId();
if (!in_array($host_type, $racEntityTypes)) {
// We only want want to controll access on entity types managed by a rac
// consumer. Otherwise, we exit.
return $form;
}
$target_type = $field_storage
->getSetting("target_type");
if (empty($target_type) || $target_type !== "user_role") {
// We can't determine the reference type. Stop trying.
return $form;
}
$form['third_party_settings']['rac'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => t('Role Access Control'),
];
$form['third_party_settings']['rac']['rac_enabled'] = [
'#type' => 'checkbox',
'#title' => t('Enable Role Access Control on this field.'),
'#description' => t('This field will restrict access to content and the field options.'),
'#default_value' => $field_storage
->getThirdPartySetting('rac', 'enabled', FALSE),
];
$form['actions']['submit']['#submit'][] = '_rac_form_field_storage_config_edit_form_submit';
}