Skip to content

Instantly share code, notes, and snippets.

@RikdeBoer
Last active August 5, 2019 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RikdeBoer/fed04afdc2d6eb3acc140ee7623f37a8 to your computer and use it in GitHub Desktop.
Save RikdeBoer/fed04afdc2d6eb3acc140ee7623f37a8 to your computer and use it in GitHub Desktop.
Embedding a Vanilla Forum as a Drupal block
<?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