Same name and namespace in other branches
  1. 8.x-2.x exif.module \exif_entity_presave() 1 comment

Implements hook_entity_presave().

Calculate the value for each metadata field so they can be stored correctly.

File

./exif.module, line 58

Code

function exif_entity_presave(EntityInterface $entity) {
    $entityType = '';
    if ($entity instanceof NodeInterface) {
        $entityType = 'node';
    }
    else {
        if (Drupal::moduleHandler()->moduleExists("media_entity") && $entity instanceof MediaInterface) {
            $entityType = 'media';
        }
    }
    if ($entityType != '') {
        $config = Drupal::configFactory()->get('exif.settings');
        $shouldUpdateMetadata = $config->get('update_metadata');
        if (!isset($shouldUpdateMetadata)) {
            $shouldUpdateMetadata = TRUE;
        }
        $inserting = !isset($entity->original);
        if ($inserting || $shouldUpdateMetadata) {
            $exifContentHandler = new ExifContent();
            $exifContentHandler->entity_insert_update($entityType, $entity);
        }
    }
}