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

UHF-10406: Catch exceptions from UrlResolverInterface::getProviderByUrl #884

Merged
merged 2 commits into from
Jan 13, 2025
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
2 changes: 1 addition & 1 deletion helfi_platform_config.module
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ function helfi_platform_config_form_alter(&$form, FormStateInterface $form_state
'#title' => new TranslatableMarkup('Published'),
'#default_value' => $redirect->isPublished(),
];
};
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\helfi_media_remote_video\Entity\RemoteVideo;
use Drupal\media\OEmbed\Resource;
use Drupal\media\OEmbed\ResourceException;
use Drupal\media\OEmbed\UrlResolverInterface;

/**
* Implements hook_media_source_info_alter().
Expand Down Expand Up @@ -186,7 +187,8 @@ function _helfi_media_remote_video_remote_video_validate(array $form, FormStateI
*/
function _helfi_media_remote_video_remote_video_url_handler(string $video_url): false|string {
$converted_url = FALSE;
$url_resolver = \Drupal::service('media.oembed.url_resolver');
/** @var \Drupal\media\OEmbed\UrlResolverInterface $url_resolver */
$url_resolver = \Drupal::service(UrlResolverInterface::class);
$provider = $url_resolver->getProviderByUrl($video_url);
$helsinki_kanava_url_pattern = 'https://www.helsinkikanava.fi/*/web/helsinkikanava/player/vod?assetId=*';

Expand Down
17 changes: 13 additions & 4 deletions modules/helfi_media_remote_video/src/Entity/RemoteVideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Drupal\helfi_media\Entity\MediaEntityBundle;
use Drupal\media\MediaInterface;
use Drupal\media\OEmbed\UrlResolverInterface;

/**
* Bundle class for remote_video media.
Expand All @@ -22,10 +23,18 @@ public function getServiceUrl(): ?string {
if (!$this->hasProvider()) {
return NULL;
}
$url_resolver = \Drupal::service('media.oembed.url_resolver');
/** @var \Drupal\media\OEmbed\UrlResolverInterface $url_resolver */
$url_resolver = \Drupal::service(UrlResolverInterface::class);
$video_url = $this->get('field_media_oembed_video')->value;
$provider = $url_resolver->getProviderByUrl($video_url);
return rtrim($provider->getUrl(), '/');
try {
$provider = $url_resolver->getProviderByUrl($video_url);
return rtrim($provider->getUrl(), '/');
}
// UrlResolverInterface::getProviderByUrl makes
// network requests that can fail.
catch (\Exception) {
return NULL;
}
}

/**
Expand All @@ -34,7 +43,7 @@ public function getServiceUrl(): ?string {
* @return mixed
* The video title.
*/
public function getMediaTitle() {
public function getMediaTitle(): mixed {
return $this->get('field_media_oembed_video')
->iframe_title;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/helfi_react_search/src/LinkedEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public function parseParams(string $url) : array {
$params['end'] = 'today';
break;

case 'tomorrow';
case 'tomorrow':
$params['start'] = date('Y-m-d', strtotime('tomorrow'));
$params['end'] = date('Y-m-d', strtotime('tomorrow'));
break;
Expand Down Expand Up @@ -440,7 +440,7 @@ protected function categoriesToKeywords(string $categories) : string {
};

$keywords = array_merge($map, $keywords);
};
}

return implode(',', $keywords);
}
Expand Down
Loading