From 8118abbcf8e0fe2e128cc3dd201ce482b16b27ce Mon Sep 17 00:00:00 2001 From: Marc Berger Date: Wed, 4 Dec 2024 17:01:01 -0800 Subject: [PATCH] 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 %}