You are here

function media_directories_media_presave in Media Directories 8

Same name and namespace in other branches
  1. 2.x media_directories.module \media_directories_media_presave()

Implements hook_ENTITY_TYPE_presave().

File

./media_directories.module, line 84
Main module file.

Code

function media_directories_media_presave(FieldableEntityInterface $entity) {
  if ($entity
    ->hasField('directory') && !$entity
    ->get('directory')
    ->isEmpty()) {
    if ($entity
      ->get('directory')->target_id <= 0) {

      // Make sure we store an allowed value.
      $entity
        ->set('directory', NULL);
    }
  }
}