From 1378a356da9340112b787fd07e315e8faab8cd1d Mon Sep 17 00:00:00 2001 From: Marc Berger Date: Thu, 12 Dec 2024 17:03:56 -0800 Subject: [PATCH] fix(IYY-266): Updates existing Power BI embeds to work with new PowerBI embed --- .../src/Plugin/EmbedSource/PowerBI.php | 8 +++---- .../modules/custom/ys_embed/ys_embed.install | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/src/Plugin/EmbedSource/PowerBI.php b/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/src/Plugin/EmbedSource/PowerBI.php index ca91c6399a..1a8fc6a4f3 100644 --- a/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/src/Plugin/EmbedSource/PowerBI.php +++ b/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/src/Plugin/EmbedSource/PowerBI.php @@ -21,12 +21,12 @@ class PowerBI extends EmbedSourceBase implements EmbedSourceInterface { /** * {@inheritdoc} */ - protected static $pattern = '/^https:\/\/app.powerbi.com\/(?view|reportEmbed)(?\?.+)/'; + protected static $pattern = '/^https:\/\/app.powerbi.com\/(?view|reportEmbed)(?\?.+)/'; /** * {@inheritdoc} */ - protected static $template = ''; + protected static $template = ''; /** * {@inheritdoc} @@ -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; } } diff --git a/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/ys_embed.install b/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/ys_embed.install index c80aae3c68..45ebbe1d8d 100644 --- a/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/ys_embed.install +++ b/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/ys_embed.install @@ -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(); + } + } +}