Skip to content

Commit

Permalink
Merge pull request #50 from wieni/field-not-found
Browse files Browse the repository at this point in the history
Fix field_media_file not found when adding the media link manually
  • Loading branch information
akasake authored May 6, 2024
2 parents f3dbb45 + 2fe3d52 commit 3143ad2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
This changelog is incomplete. Pull requests with entries before 1.7.0
are welcome.

## [2.3.0] - 2024-XX-XX
## [2.3.1] - 2024-05-06
### Fixed
- wmmedia_file_link filter does not break when getting a hardcoded media url

## [2.3.0] - 2024-04-12
### Changed
- wmmedia_file_link filter now requires a `/media` url to find the media entity
- Deprecate MediaFileLink ckeditor plugin, this will not work on ckeditor 5
Expand Down
9 changes: 6 additions & 3 deletions src/Plugin/Filter/MediaFileLinkFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ public function process($text, $langcode): FilterProcessResult
continue;
}

preg_match('/(?<=media\/)\d+/', $href, $matches);
preg_match('/media\/(\d+)(?:\/)?(?:edit)?$/', $href, $matches);

$mid = reset($matches);
$mid = end($matches);

if (!$mid) {
continue;
}

$media = $storage->load($mid);

if (!$media instanceof Media) {
if (
!$media instanceof Media
|| !$media->hasField('field_media_file')
) {
continue;
}

Expand Down

0 comments on commit 3143ad2

Please sign in to comment.