Skip to content

Commit 10d451e

Browse files
authored
Merge pull request #830 from yalesites-org/IYY-266--power-bi-hotfix
IYY-266: Updates existing Power BI embeds to work with new Power BI embedder
2 parents 08d9938 + 1378a35 commit 10d451e

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

web/profiles/custom/yalesites_profile/modules/custom/ys_embed/src/Plugin/EmbedSource/PowerBI.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ class PowerBI extends EmbedSourceBase implements EmbedSourceInterface {
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
protected static $pattern = '/^https:\/\/app.powerbi.com\/(?<type>view|reportEmbed)(?<query_params>\?.+)/';
24+
protected static $pattern = '/^https:\/\/app.powerbi.com\/(?<type>view|reportEmbed)(?<form_params>\?.+)/';
2525

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

3131
/**
3232
* {@inheritdoc}
@@ -74,8 +74,8 @@ class PowerBI extends EmbedSourceBase implements EmbedSourceInterface {
7474
*/
7575
public function getUrl(array $params): string {
7676
$type = $params['type'];
77-
$query_params = $params['query_params'];
78-
return 'https://app.powerbi.com/' . $type . $query_params;
77+
$form_params = $params['form_params'];
78+
return 'https://app.powerbi.com/' . $type . $form_params;
7979
}
8080

8181
}

web/profiles/custom/yalesites_profile/modules/custom/ys_embed/ys_embed.install

+22
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,25 @@ function _copy_embed_file($filename) {
179179

180180
return TRUE;
181181
}
182+
183+
/**
184+
* Updates existing Power BI embeds to add new type parameter.
185+
*/
186+
function ys_embed_update_9006() {
187+
$media_storage = \Drupal::entityTypeManager()->getStorage('media');
188+
189+
$power_bi_embeds = $media_storage->loadByProperties([
190+
'bundle' => 'embed',
191+
'field_media_embed.embed_source' => 'powerbi',
192+
]);
193+
194+
foreach ($power_bi_embeds as $embed) {
195+
/** @var \Drupal\media\Entity\Media $embed */
196+
$field_value = $embed->get('field_media_embed')->getValue();
197+
if (!isset($field_value[0]['params']['type'])) {
198+
$field_value[0]['params']['type'] = 'view';
199+
$embed->set('field_media_embed', $field_value);
200+
$embed->save();
201+
}
202+
}
203+
}

0 commit comments

Comments
 (0)