Last active
August 5, 2019 00:18
-
-
Save RikdeBoer/fed04afdc2d6eb3acc140ee7623f37a8 to your computer and use it in GitHub Desktop.
Embedding a Vanilla Forum as a Drupal block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Put this file in YOUR_MODULE/src/Plugin/Block. | |
namespace Drupal\YOUR_MODULE\Plugin\Block; | |
use Drupal\Core\Block\BlockBase; | |
/** | |
* Provides the Vanilla Forum Block. | |
* | |
* @Block( | |
* id = "vanilla_forum", | |
* admin_label = @Translation("Vanilla Forum"), | |
* category = @Translation("Forum"), | |
* ) | |
*/ | |
class VanillaForumBlock extends BlockBase { | |
/** | |
* {@inheritdoc} | |
*/ | |
public function build() { | |
// The site hosting the forum may be specified as a configuration setting. | |
$vanilla_root = \Drupal::config('vanilla.settings')->get('vanilla_url')) { | |
$ext_js = '<script type="text/javascript" src="' . $vanilla_root . '/js/embed.js"></script>'; | |
return [ | |
'#markup' => $ext_js, | |
// Without #allowed_tags the <script> tag will be filtered out during rendering. | |
'#allowed_tags' => ['script'], | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment