function image_entity_presave

Implements hook_entity_presave().

Transforms default image of image field from array into single value at save.

File

drupal/core/modules/image/image.module, line 1067
Exposes global functionality for creating image styles.

Code

function image_entity_presave(EntityInterface $entity, $type) {
  $field = FALSE;
  if ($entity instanceof FieldInstance) {
    $field = $entity
      ->getField();
  }
  elseif ($entity instanceof Field) {
    $field = $entity;
  }
  if ($field && $field->type == 'image' && is_array($entity->settings['default_image'])) {
    if (!empty($entity->settings['default_image'][0])) {
      $entity->settings['default_image'] = $entity->settings['default_image'][0];
    }
    else {
      $entity->settings['default_image'] = 0;
    }
  }
}