ReactBlock.php in Decoupled Blocks 8
File
modules/pdb_react/src/Plugin/Block/ReactBlock.php
View source
<?php
namespace Drupal\pdb_react\Plugin\Block;
use Drupal\pdb\Plugin\Block\PdbBlock;
class ReactBlock extends PdbBlock {
public function build() {
$info = $this
->getComponentInfo();
$machine_name = $info['machine_name'];
$build = parent::build();
$build['#allowed_tags'] = [
$machine_name,
];
$build['#markup'] = '<' . $machine_name . ' id="' . $machine_name . '"></' . $machine_name . '>';
return $build;
}
public function attachSettings(array $component) {
$machine_name = $component['machine_name'];
$attached = [];
$attached['drupalSettings']['react-apps'][$machine_name]['uri'] = '/' . $component['path'];
return $attached;
}
public function attachLibraries(array $component) {
$parent_libraries = parent::attachLibraries($component);
$framework_libraries = [
'pdb_react/react',
'pdb_react/components',
];
$libraries = [
'library' => array_merge($parent_libraries, $framework_libraries),
];
return $libraries;
}
}