Skip to content

Commit

Permalink
Add null check prior to using object. (#791)
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelgbanks authored Feb 4, 2021
1 parent 986a3d4 commit cfa48a9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions modules/islandora_text_extraction/islandora_text_extraction.module
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,18 @@ function islandora_text_extraction_media_presave(MediaInterface $media) {
$text = $media->get('field_edited_text')->getValue();
if (!$text) {
$file_id = $media->get('field_media_file')->getValue()[0]['target_id'];
$file = File::load($file_id);
$data = file_get_contents($file->getFileUri());
$data = nl2br($data);
$media->set('field_edited_text', $data);
$media->field_edited_text->format = 'basic_html';
if ($file_id) {
$file = File::load($file_id);
if ($file) {
$data = file_get_contents($file->getFileUri());
$data = nl2br($data);
$media->set('field_edited_text', $data);
$media->field_edited_text->format = 'basic_html';
}
}
else {
\Drupal::logger('islandora_text_extraction')->warning("No file associated with media entity.");
}
}
}

Expand Down

0 comments on commit cfa48a9

Please sign in to comment.