Skip to content

Commit

Permalink
Merge pull request #810 from yalesites-org/IYY-266--fix-ms-bi-embed
Browse files Browse the repository at this point in the history
IYY-266: Ensure Microsoft BI embeds work
  • Loading branch information
codechefmarc authored Dec 11, 2024
2 parents 3d0069b + 7113ee3 commit 06d7349
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,41 @@ class PowerBI extends EmbedSourceBase implements EmbedSourceInterface {
/**
* {@inheritdoc}
*/
protected static $pattern = '/^https:\/\/app.powerbi.com\/view(?<form_params>.+)/';
protected static $pattern = '/^https:\/\/app.powerbi.com\/(?<type>view|reportEmbed)(?<query_params>\?.+)/';

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

/**
* {@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 = '
<p>
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".
</p>
<p>
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."
</p>
';

/**
* {@inheritdoc}
*/
protected static $example = 'https://app.powerbi.com/view?r=eyJrIjoiYzQ1ODA0ZjEtZjc5YS00OTgyLWIzOTItNmJmNDY2YmRiODQ2IiwidCI6ImRkOGNiZWJiLTIxMzktNGRmOC1iNDExLTRlM2U4N2FiZWI1YyIsImMiOjF9&pageName=ReportSection2ac2649f17189885d376';
protected static $example = '
<p>
<strong>Public:</strong> https://app.powerbi.com/view?r=eyJrIjoiYzQ1ODA0ZjEtZjc5YS00OTgyLWIzOTItNmJmNDY2YmRiODQ2IiwidCI6ImRkOGNiZWJiLTIxMzktNGRmOC1iNDExLTRlM2U4N2FiZWI1YyIsImMiOjF9&pageName=ReportSection2ac2649f17189885d376
</p>
<p>
<strong>Private:</strong> https://app.powerbi.com/reportEmbed?reportId=66e25bd6-5e0a-4db8-ad0c-28bb31b0fd5e&autoAuth=true&ctid=dd8cbebb-2139-4df8-b411-4e3e87abeb5c
</p>
';

/**
* {@inheritdoc}
*/
protected static $exampleContainsMarkup = TRUE;

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -145,6 +152,13 @@ public static function getExample(): string {
return static::$example;
}

/**
* {@inheritdoc}
*/
public static function exampleContainsMarkup(): bool {
return static::$exampleContainsMarkup;
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

{% for source in sources %}
<h2>{{ source.name }}</h2>
<p>{{ source.instructions }}</p>
{{ source.instructions }}
{{ source.example }}
{% endfor %}

0 comments on commit 06d7349

Please sign in to comment.