function domain_access_default_form_values in Domain Access 8
Defines default values for domain access field.
This function is a workaround for a core bug. When the domain access field is not accessible to some users, the existing values are not preserved.
See also
domain_access_entity_field_access()
1 call to domain_access_default_form_values()
- domain_access_form_alter in domain_access/
domain_access.module - Implements hook_form_alter().
File
- domain_access/
domain_access.module, line 747 - Domain-based access control for content.
Code
function domain_access_default_form_values(&$form, &$form_state, $entity) {
// Set domain access default value when the user does not have access
// to edit the field. This seems to work fine for all affiliates, which
// suggests a core bug in entity reference handling.
if (!$entity
->isNew() && isset($form['field_domain_access']) && !$form['field_domain_access']['#access'] && empty($form['field_domain_access']['widget']['#default_value'])) {
// Set the default values correctly.
$values = \Drupal::service('domain_access.manager')
->getAccessValues($entity);
$form['field_domain_access']['widget']['#default_value'] = array_keys($values);
}
}