Browse Source

Issue #941: Only add <br/> tags to plain text extracted text fields. (#942)

* Issue #941: Only add <br/> tags to plain text extracted text fields.

* Fix PHPCS errors.

* Don't add <br /> tags to edited OCR text field if it looks like hOCR.

* Respond to PHPCS errors.
MNPALS-2.x
Alexander O'Neill 2 years ago committed by Rosie Le Faive
parent
commit
138eab2016
  1. 4
      modules/islandora_text_extraction/islandora_text_extraction.module
  2. 6
      modules/islandora_text_extraction/src/Controller/MediaSourceController.php

4
modules/islandora_text_extraction/islandora_text_extraction.module

@ -40,6 +40,10 @@ function islandora_text_extraction_media_presave(MediaInterface $media) {
$file = File::load($file_id);
if ($file) {
$data = file_get_contents($file->getFileUri());
// Check if it's already markup like hOCR.
if (substr($data, 0, 5) == '<?xml') {
return;
}
$data = nl2br($data);
$media->set('field_edited_text', $data);
$media->field_edited_text->format = 'basic_html';

6
modules/islandora_text_extraction/src/Controller/MediaSourceController.php

@ -108,7 +108,11 @@ class MediaSourceController extends ControllerBase {
$this->getLogger('islandora')->warning("Field $destination_field is not defined in Media Type {$media->bundle()}");
}
if ($media->hasField($destination_text_field)) {
$media->{$destination_text_field}->setValue(nl2br($contents));
// @todo The request actually has a malformed parameter string, ?text_format=plain_text?connection_close=true.
if (substr($request->query->get('text_format'), 0, 10) == 'plain_text') {
$contents = nl2br($contents);
}
$media->{$destination_text_field}->setValue($contents);
}
else {
$this->getLogger('islandora')->warning("Field $destination_text_field is not defined in Media Type {$media->bundle()}");

Loading…
Cancel
Save