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

IYY-266: Updates existing Power BI embeds to work with new Power BI embedder #830

Merged
merged 1 commit into from
Dec 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class PowerBI extends EmbedSourceBase implements EmbedSourceInterface {
/**
* {@inheritdoc}
*/
protected static $pattern = '/^https:\/\/app.powerbi.com\/(?<type>view|reportEmbed)(?<query_params>\?.+)/';
protected static $pattern = '/^https:\/\/app.powerbi.com\/(?<type>view|reportEmbed)(?<form_params>\?.+)/';

/**
* {@inheritdoc}
*/
protected static $template = '<iframe class="iframe" title="{{ title }}" src="https://app.powerbi.com/{{ type }}{{ query_params }}" height="100%" width="100%" loading="lazy"></iframe>';
protected static $template = '<iframe class="iframe" title="{{ title }}" src="https://app.powerbi.com/{{ type }}{{ form_params }}" height="100%" width="100%" loading="lazy"></iframe>';

/**
* {@inheritdoc}
Expand Down Expand Up @@ -74,8 +74,8 @@ class PowerBI extends EmbedSourceBase implements EmbedSourceInterface {
*/
public function getUrl(array $params): string {
$type = $params['type'];
$query_params = $params['query_params'];
return 'https://app.powerbi.com/' . $type . $query_params;
$form_params = $params['form_params'];
return 'https://app.powerbi.com/' . $type . $form_params;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,25 @@ function _copy_embed_file($filename) {

return TRUE;
}

/**
* Updates existing Power BI embeds to add new type parameter.
*/
function ys_embed_update_9006() {
$media_storage = \Drupal::entityTypeManager()->getStorage('media');

$power_bi_embeds = $media_storage->loadByProperties([
'bundle' => 'embed',
'field_media_embed.embed_source' => 'powerbi',
]);

foreach ($power_bi_embeds as $embed) {
/** @var \Drupal\media\Entity\Media $embed */
$field_value = $embed->get('field_media_embed')->getValue();
if (!isset($field_value[0]['params']['type'])) {
$field_value[0]['params']['type'] = 'view';
$embed->set('field_media_embed', $field_value);
$embed->save();
}
}
}
Loading