Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #95 from salsadigitalauorg/feature/94-package_id_d…
Browse files Browse the repository at this point in the history
…efault

[94] - added a default string for the package_id in case it’s not pre…
  • Loading branch information
SRowlands authored Jun 8, 2017
2 parents 4499775 + 69032ce commit 467ef1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class MediaInternetGovCmsCkanHandler extends MediaInternetBaseHandler {
foreach ($patterns as $pattern) {
preg_match($pattern, $embed_code, $matches);
if (isset($matches[1]) && isset($matches[2])) {
$next_instance = $this->getNextInstanceId($matches[1], $matches[2]);
$uri = $this->baseUri . $matches[1] . '/' . $matches[2] . '/' . $next_instance;
$package_id = empty($matches[1]) ? 'package' : $matches[1];
$next_instance = $this->getNextInstanceId($package_id, $matches[2]);
$uri = $this->baseUri . $package_id . '/' . $matches[2] . '/' . $next_instance;
return file_stream_wrapper_uri_normalize($uri);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ function govcms_ckan_media_field_widget_form(&$form, &$form_state, $field, $inst
// Provide ability to change the dataset url.
if ($result_meta->valid && isset($result_meta->data->id)) {
$handler = new MediaInternetGovCmsCkanHandler('');
$dataset_url = $handler->buildResourceUrl($result_meta->data->package_id, $result_meta->data->id);
$package_id = empty($result_meta->data->package_id) ? 'package' : $result_meta->data->package_id;
$dataset_url = $handler->buildResourceUrl($package_id, $result_meta->data->id);

// Only allow changing dataset if is already saved.
$allow_change_dataset = isset($form_state['file']);
Expand Down Expand Up @@ -257,7 +258,8 @@ function _govcms_ckan_media_field_widget_form_change_dataset_url($form, &$form_s
$handler = new MediaInternetGovCmsCkanHandler('');
$file = $form_state['file'];
$new_dataset_url = $form_state['values']['dataset_url'];
$old_dataset_url = $handler->buildResourceUrl($file->package_id, $file->resource_id);
$package_id = empty($file->package_id) ? 'package' : $file->package_id;
$old_dataset_url = $handler->buildResourceUrl($package_id, $file->resource_id);

// If the dataset url has changed.
if ($old_dataset_url != $new_dataset_url) {
Expand Down

0 comments on commit 467ef1d

Please sign in to comment.