You are here

function entity_access_by_field_post_presave in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_post_presave()
  2. 8 modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_post_presave()
  3. 8.2 modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_post_presave()
  4. 8.3 modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_post_presave()
  5. 8.4 modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_post_presave()
  6. 8.5 modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_post_presave()
  7. 8.6 modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_post_presave()
  8. 8.7 modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_post_presave()
  9. 10.3.x modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_post_presave()
  10. 10.0.x modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_post_presave()
  11. 10.1.x modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_post_presave()
  12. 10.2.x modules/custom/entity_access_by_field/entity_access_by_field.module \entity_access_by_field_post_presave()

Implements hook_ENTITY_TYPE_presave().

File

modules/custom/entity_access_by_field/entity_access_by_field.module, line 166
Entity Access By Field module file.

Code

function entity_access_by_field_post_presave(PostInterface $post) {
  $field_definitions = $post
    ->getFieldDefinitions();
  foreach ($field_definitions as $field_name => $field_definition) {
    if ($field_definition
      ->getType() == 'entity_access_field' && $post
      ->get($field_name)
      ->isEmpty()) {
      $default_visibility = _entity_access_by_field_get_default_visibility($post);
      $post
        ->get($field_name)
        ->setValue($default_visibility);
    }
  }
}