From e37936bc946103b88208af2a77c0338b4e3330e5 Mon Sep 17 00:00:00 2001 From: wilso929 Date: Thu, 19 Oct 2023 10:39:35 -0400 Subject: [PATCH 1/2] d10 update --- src/Plugin/Field/FieldFormatter/ReplayWebPageFormatter.php | 6 ++++-- tests/src/Functional/DisplayTest.php | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Plugin/Field/FieldFormatter/ReplayWebPageFormatter.php b/src/Plugin/Field/FieldFormatter/ReplayWebPageFormatter.php index fe13b3d..5e7f670 100644 --- a/src/Plugin/Field/FieldFormatter/ReplayWebPageFormatter.php +++ b/src/Plugin/Field/FieldFormatter/ReplayWebPageFormatter.php @@ -83,10 +83,12 @@ public function settingsSummary() { */ public function viewElements(FieldItemListInterface $items, $langcode) { $element = []; - $media = $items->getEntity(); + $ent = $items->getEntity(); - if ($media->hasField('field_base_url') && $media->hasField('field_media_file')) { + if ($ent->hasField('field_base_url') && $ent->hasField('field_media_file')) { // get direct path to file + /** @var \Drupal\media\Entity\Media $media */ + $media = $ent; $fid = $media->getSource()->getSourceFieldValue($media); $file = File::load($fid); $uri = $file->getFileUri(); diff --git a/tests/src/Functional/DisplayTest.php b/tests/src/Functional/DisplayTest.php index c900573..1b7a113 100644 --- a/tests/src/Functional/DisplayTest.php +++ b/tests/src/Functional/DisplayTest.php @@ -63,7 +63,7 @@ protected function setUp(): void { $data = []; $data['fields[field_media_file][type]'] = 'replaywebpage_formatter'; $this->submitForm($data, 'Save'); - $this->assertSession()->pageTextContains('Your settings have been saved.'); + $this->assertSession()->pageTextContainsOnce('Your settings have been saved.'); // upload file $this->drupalGet('media/add/web_archive'); @@ -73,7 +73,7 @@ protected function setUp(): void { $path = \Drupal::service('extension.list.module')->getPath('replaywebpage') . '/tests/files/wikipedia.wacz'; $data['files[field_media_file_0]'] = $path; $this->submitForm($data, 'Save'); - $this->assertSession()->pageTextContains('Web Archive Test has been created.'); + $this->assertSession()->pageTextContainsOnce('Web Archive Test has been created.'); // create content type $this->drupalGet('admin/structure/types/add'); @@ -114,7 +114,7 @@ protected function setUp(): void { */ public function testPlayerWarcDisplay() { $this->drupalGet('node/1'); - $this->assertSession()->responseMatches('~https://cdn.jsdelivr.net/npm/replaywebpage@[\d\.]+/ui.js~'); + $this->assertSession()->responseContains('~https://cdn.jsdelivr.net/npm/replaywebpage@[\d\.]+/ui.js~'); $this->assertSession()->responseContains('wikipedia.wacz'); $this->assertSession()->responseContains('https://en.wikipedia.org/wiki/Pok%C3%A9mon'); } From 695bcd077f184ad3b07fadefccfa9125c3d0aa99 Mon Sep 17 00:00:00 2001 From: wilso929 Date: Mon, 30 Oct 2023 12:24:20 -0400 Subject: [PATCH 2/2] fixed error with entity --- src/Plugin/Field/FieldFormatter/ReplayWebPageFormatter.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Plugin/Field/FieldFormatter/ReplayWebPageFormatter.php b/src/Plugin/Field/FieldFormatter/ReplayWebPageFormatter.php index 5e7f670..06c9d8e 100644 --- a/src/Plugin/Field/FieldFormatter/ReplayWebPageFormatter.php +++ b/src/Plugin/Field/FieldFormatter/ReplayWebPageFormatter.php @@ -83,12 +83,11 @@ public function settingsSummary() { */ public function viewElements(FieldItemListInterface $items, $langcode) { $element = []; - $ent = $items->getEntity(); + /** @var \Drupal\media\Entity\Media $media */ + $media = $items->getEntity(); - if ($ent->hasField('field_base_url') && $ent->hasField('field_media_file')) { + if ($media->hasField('field_base_url') && $media->hasField('field_media_file')) { // get direct path to file - /** @var \Drupal\media\Entity\Media $media */ - $media = $ent; $fid = $media->getSource()->getSourceFieldValue($media); $file = File::load($fid); $uri = $file->getFileUri();