Browse Source

Add null check prior to using object. (#791)

pull/828/head
Nigel Banks 4 years ago committed by GitHub
parent
commit
cfa48a9db7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      modules/islandora_text_extraction/islandora_text_extraction.module

7
modules/islandora_text_extraction/islandora_text_extraction.module

@ -36,13 +36,20 @@ function islandora_text_extraction_media_presave(MediaInterface $media) {
$text = $media->get('field_edited_text')->getValue(); $text = $media->get('field_edited_text')->getValue();
if (!$text) { if (!$text) {
$file_id = $media->get('field_media_file')->getValue()[0]['target_id']; $file_id = $media->get('field_media_file')->getValue()[0]['target_id'];
if ($file_id) {
$file = File::load($file_id); $file = File::load($file_id);
if ($file) {
$data = file_get_contents($file->getFileUri()); $data = file_get_contents($file->getFileUri());
$data = nl2br($data); $data = nl2br($data);
$media->set('field_edited_text', $data); $media->set('field_edited_text', $data);
$media->field_edited_text->format = 'basic_html'; $media->field_edited_text->format = 'basic_html';
} }
} }
else {
\Drupal::logger('islandora_text_extraction')->warning("No file associated with media entity.");
}
}
}
/** /**
* Implements hook_media_insert(). * Implements hook_media_insert().

Loading…
Cancel
Save