From 09a95634ea12d67de0e3606bd17a0fe59154f408 Mon Sep 17 00:00:00 2001 From: Marc Berger Date: Tue, 26 Nov 2024 11:28:57 -0800 Subject: [PATCH 1/4] feat(IYY-266): Relax Power BI embed to allow for both /view and /reportEmbed URLs --- .../custom/ys_embed/src/Plugin/EmbedSource/PowerBI.php | 6 +++--- 1 file changed, 3 insertions(+), 3 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 140fad3041..108b25404f 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(?.+)/'; + protected static $pattern = '/^https:\/\/app.powerbi.com\/(?.+)/'; /** * {@inheritdoc} */ - protected static $template = ''; + protected static $template = ''; /** * {@inheritdoc} @@ -55,7 +55,7 @@ class PowerBI extends EmbedSourceBase implements EmbedSourceInterface { */ public function getUrl(array $params): string { $form_params = $params['form_params']; - return 'https://app.powerbi.com/view' . $form_params; + return 'https://app.powerbi.com/' . $form_params; } } From 6b83814de7e94de84bf9ee34321da6e7accd60c8 Mon Sep 17 00:00:00 2001 From: Marc Berger Date: Tue, 26 Nov 2024 12:39:04 -0800 Subject: [PATCH 2/4] feat(IYY-266): Change Power BI embed to allow two kinds of URLs - view and reportEmbed --- .../ys_embed/src/Plugin/EmbedSource/PowerBI.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 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 108b25404f..9b7b01260c 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\/(?.+)/'; + protected static $pattern = '/^https:\/\/app.powerbi.com\/(?view|reportEmbed)(?\?.+)/'; /** * {@inheritdoc} */ - protected static $template = ''; + protected static $template = ''; /** * {@inheritdoc} @@ -36,7 +36,7 @@ class PowerBI extends EmbedSourceBase implements EmbedSourceInterface { /** * {@inheritdoc} */ - protected static $example = 'https://app.powerbi.com/view?r=eyJrIjoiYzQ1ODA0ZjEtZjc5YS00OTgyLWIzOTItNmJmNDY2YmRiODQ2IiwidCI6ImRkOGNiZWJiLTIxMzktNGRmOC1iNDExLTRlM2U4N2FiZWI1YyIsImMiOjF9&pageName=ReportSection2ac2649f17189885d376'; + protected static $example = 'https://app.powerbi.com/reportEmbed?reportId=66e25bd6-5e0a-4db8-ad0c-28bb31b0fd5e&autoAuth=true&ctid=dd8cbebb-2139-4df8-b411-4e3e87abeb5c'; /** * {@inheritdoc} @@ -54,8 +54,9 @@ class PowerBI extends EmbedSourceBase implements EmbedSourceInterface { * {@inheritdoc} */ public function getUrl(array $params): string { - $form_params = $params['form_params']; - return 'https://app.powerbi.com/' . $form_params; + $type = $params['type']; + $query_params = $params['query_params']; + return 'https://app.powerbi.com/' . $type . $query_params; } } From 8118abbcf8e0fe2e128cc3dd201ce482b16b27ce Mon Sep 17 00:00:00 2001 From: Marc Berger Date: Wed, 4 Dec 2024 17:01:01 -0800 Subject: [PATCH 3/4] feat(IYY-266): Update instructions and examples for Power BI to get both public and private embeds --- .../EmbedInstructionsController.php | 5 ++-- .../src/Plugin/EmbedSource/PowerBI.php | 23 +++++++++++++++++-- .../ys_embed/src/Plugin/EmbedSourceBase.php | 14 +++++++++++ .../src/Plugin/EmbedSourceInterface.php | 8 +++++++ .../templates/embed-instructions.html.twig | 2 +- 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/src/Controller/EmbedInstructionsController.php b/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/src/Controller/EmbedInstructionsController.php index 8bd478e6c8..6fccd88c3b 100644 --- a/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/src/Controller/EmbedInstructionsController.php +++ b/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/src/Controller/EmbedInstructionsController.php @@ -6,6 +6,7 @@ use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\OpenDialogCommand; use Drupal\Core\Controller\ControllerBase; +use Drupal\Core\Render\Markup; use Drupal\Core\Render\RendererInterface; use Drupal\ys_embed\Plugin\EmbedSourceManager; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -81,14 +82,14 @@ public function content() { $sources = []; foreach ($this->embedManager->getSources() as $id => $source) { $sources[$id]['name'] = $source['label']; - $sources[$id]['instructions'] = $source['class']::getInstructions(); + $sources[$id]['instructions'] = Markup::create($source['class']::getInstructions()); $sources[$id]['example'] = [ '#open' => FALSE, '#type' => 'details', '#title' => 'Example', ]; $sources[$id]['example']['code'] = [ - '#markup' => Html::escape($source['class']::getExample()), + '#markup' => $source['class']::exampleContainsMarkup() ? Markup::create($source['class']::getExample()) : Html::escape($source['class']::getExample()), ]; } $content = [ 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 9b7b01260c..349e26a1d0 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 @@ -31,12 +31,31 @@ class PowerBI extends EmbedSourceBase implements EmbedSourceInterface { /** * {@inheritdoc} */ - protected static $instructions = 'Open a report in the Power BI service. On the File menu, select Embed report > Website or portal. In the Secure embed code dialog, select the value under "Here\'s a link you can use to embed this content."'; + protected static $instructions = ' +

+ For a Public Report: Open a report in the Power BI service. On the File menu, select Embed report > Publish to web (public). In the Embed Code dialog, select the value under "Link you can send in email". +

+

+ For a Private (login required) Report: Open a report in the Power BI service. On the File menu, select Embed report > Website or portal. In the Secure embed code dialog, select the value under "Here\'s a link you can use to embed this content." +

+ '; /** * {@inheritdoc} */ - protected static $example = 'https://app.powerbi.com/reportEmbed?reportId=66e25bd6-5e0a-4db8-ad0c-28bb31b0fd5e&autoAuth=true&ctid=dd8cbebb-2139-4df8-b411-4e3e87abeb5c'; + protected static $example = ' +

+ Public: https://app.powerbi.com/view?r=eyJrIjoiYzhkODFiMDUtZGU3Zi00ZDAzLWJlYTEtZmM1Mjg3MzMzZGE3IiwidCI6ImRkOGNiZWJiLTIxMzktNGRmOC1iNDExLTRlM2U4N2FiZWI1YyIsImMiOjF9 +

+

+ Private: https://app.powerbi.com/reportEmbed?reportId=66e25bd6-5e0a-4db8-ad0c-28bb31b0fd5e&autoAuth=true&ctid=dd8cbebb-2139-4df8-b411-4e3e87abeb5c +

+ '; + + /** + * {@inheritdoc} + */ + protected static $exampleContainsMarkup = TRUE; /** * {@inheritdoc} diff --git a/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/src/Plugin/EmbedSourceBase.php b/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/src/Plugin/EmbedSourceBase.php index 722b237894..8f5160437b 100644 --- a/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/src/Plugin/EmbedSourceBase.php +++ b/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/src/Plugin/EmbedSourceBase.php @@ -58,6 +58,13 @@ abstract class EmbedSourceBase extends PluginBase implements EmbedSourceInterfac */ protected static $example; + /** + * Does the example contain markup. Defaults to false. + * + * @var bool + */ + protected static $exampleContainsMarkup = FALSE; + /** * An array of attributes to add to the template. * @@ -145,6 +152,13 @@ public static function getExample(): string { return static::$example; } + /** + * {@inheritdoc} + */ + public static function exampleContainsMarkup(): bool { + return static::$exampleContainsMarkup; + } + /** * {@inheritdoc} */ diff --git a/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/src/Plugin/EmbedSourceInterface.php b/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/src/Plugin/EmbedSourceInterface.php index fb879cf431..760861d68a 100644 --- a/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/src/Plugin/EmbedSourceInterface.php +++ b/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/src/Plugin/EmbedSourceInterface.php @@ -55,6 +55,14 @@ public static function getInstructions(): string; */ public static function getExample(): string; + /** + * Does the example contain markup that should not be escaped. + * + * @return bool + * If the example contains markup. + */ + public static function exampleContainsMarkup(): bool; + /** * Get a render array for an embed code. * diff --git a/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/templates/embed-instructions.html.twig b/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/templates/embed-instructions.html.twig index ccd65134c5..9d4c4cda4f 100644 --- a/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/templates/embed-instructions.html.twig +++ b/web/profiles/custom/yalesites_profile/modules/custom/ys_embed/templates/embed-instructions.html.twig @@ -8,6 +8,6 @@ {% for source in sources %}

{{ source.name }}

-

{{ source.instructions }}

+ {{ source.instructions }} {{ source.example }} {% endfor %} From 7113ee3548fc003f1111aaf88f06f6a321b9df0a Mon Sep 17 00:00:00 2001 From: Marc Berger Date: Wed, 4 Dec 2024 17:25:47 -0800 Subject: [PATCH 4/4] fix(IYY-266): Change public example back to original example --- .../modules/custom/ys_embed/src/Plugin/EmbedSource/PowerBI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 349e26a1d0..ca91c6399a 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 @@ -45,7 +45,7 @@ class PowerBI extends EmbedSourceBase implements EmbedSourceInterface { */ protected static $example = '

- Public: https://app.powerbi.com/view?r=eyJrIjoiYzhkODFiMDUtZGU3Zi00ZDAzLWJlYTEtZmM1Mjg3MzMzZGE3IiwidCI6ImRkOGNiZWJiLTIxMzktNGRmOC1iNDExLTRlM2U4N2FiZWI1YyIsImMiOjF9 + Public: https://app.powerbi.com/view?r=eyJrIjoiYzQ1ODA0ZjEtZjc5YS00OTgyLWIzOTItNmJmNDY2YmRiODQ2IiwidCI6ImRkOGNiZWJiLTIxMzktNGRmOC1iNDExLTRlM2U4N2FiZWI1YyIsImMiOjF9&pageName=ReportSection2ac2649f17189885d376

Private: https://app.powerbi.com/reportEmbed?reportId=66e25bd6-5e0a-4db8-ad0c-28bb31b0fd5e&autoAuth=true&ctid=dd8cbebb-2139-4df8-b411-4e3e87abeb5c