Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert HTML paragraphs to new lines in transcripts [MA-167] #269

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/Helpers/StringHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,12 @@ public static function summation(array $array = [])
return implode(', ', $array) . ', and ' . $last;
}
}

public static function convertHtmlParagraphsToNewlines($text)
{
$return = preg_replace('/<p[^>]*>/', '', $text);
$return = str_replace('</p>', "\r\n", $return);
$return = preg_replace('/<br[^>]*>/', "\r\n", $return);
return $return;
}
}
3 changes: 2 additions & 1 deletion app/Models/Transformers/AudioTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use A17\Twill\Models\Contracts\TwillModelContract;
use App\Repositories\Serializers\OptionalKeyArraySerializer;
use App\Helpers\StringHelpers;
use League\Fractal\TransformerAbstract;

class AudioTransformer extends TransformerAbstract
Expand All @@ -21,7 +22,7 @@ public function transform(TwillModelContract $audio)
'title' => $audio->title,
'nid' => (string) $audio->id, // Legacy from Drupal
'audio_file_url' => $audio->content,
'audio_transcript' => $audio->transcript,
'audio_transcript' => StringHelpers::convertHtmlParagraphsToNewlines($audio->transcript),
'track_title' => null, // Legacy from Drupal
])
];
Expand Down
3 changes: 2 additions & 1 deletion app/Models/Transformers/AudioTranslationTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use A17\Twill\Models\Contracts\TwillModelContract;
use League\Fractal\TransformerAbstract;
use App\Helpers\StringHelpers;

class AudioTranslationTransformer extends TransformerAbstract
{
Expand All @@ -17,7 +18,7 @@ public function transform(TwillModelContract $translation)
'audio_file_url' => $translation->content,
'audio_filemime' => null, // Legacy from Drupal
'audio_filesize' => null, // Legacy from Drupal
'audio_transcript' => $translation->transcript,
'audio_transcript' => StringHelpers::convertHtmlParagraphsToNewlines($translation->transcript),
'credits' => null, // Legacy from Drupal
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use Illuminate\Database\Migrations\Migration;
use App\Models\LoanObject;

return new class extends Migration
{
return new class () extends Migration {
public function up(): void
{
LoanObject::query()->update(['is_on_view' => 1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class () extends Migration {
public function up(): void
{
Schema::table('loan_objects', function (Blueprint $table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
use Illuminate\Support\Facades\Schema;
use App\Models\Selector;

return new class extends Migration
{
return new class () extends Migration {
public function up(): void
{
Schema::table('selectors', function (Blueprint $table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
use Illuminate\Support\Facades\Schema;
use App\Models\LoanObject;

return new class extends Migration
{
return new class () extends Migration {
public function up(): void
{
Schema::table('loan_objects', function (Blueprint $table) {
Expand Down
Loading