Ng2Block.php in Decoupled Blocks 8
File
modules/pdb_ng2/src/Plugin/Block/Ng2Block.php
View source
<?php
namespace Drupal\pdb_ng2\Plugin\Block;
use Drupal\pdb\Plugin\Block\PdbBlock;
class Ng2Block 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="instance-id-' . $this->configuration['uuid'] . '"></' . $machine_name . '>';
return $build;
}
public function attachFramework(array $component) {
$attached = [];
$attached['drupalSettings']['pdb']['ng2']['global_injectables'] = [];
return $attached;
}
public function attachSettings(array $component) {
$attached = parent::attachSettings($component);
$machine_name = $component['machine_name'];
$uuid = $this->configuration['uuid'];
$attached['drupalSettings']['pdb']['ng2']['components']['instance-id-' . $uuid] = [
'uri' => $component['path'],
'element' => $machine_name,
];
if (!empty($component['ng_class_name'])) {
$attached['drupalSettings']['pdb']['ng2']['components']['instance-id-' . $uuid] += [
'ngClassName' => $component['ng_class_name'],
];
}
$attached['drupalSettings']['pdb']['ng2']['module_path'] = drupal_get_path('module', 'pdb_ng2');
$config_settings = \Drupal::config('pdb_ng2.settings');
if (isset($config_settings)) {
$attached['drupalSettings']['pdb']['ng2']['development_mode'] = $config_settings
->get('development_mode');
}
else {
$attached['drupalSettings']['pdb']['ng2']['development_mode'] = TRUE;
}
return $attached;
}
public function attachLibraries(array $component) {
$parent_libraries = parent::attachLibraries($component);
$framework_libraries = [
'pdb_ng2/pdb.ng2.config',
];
$libraries = [
'library' => array_merge($parent_libraries, $framework_libraries),
];
return $libraries;
}
}
Classes
Name |
Description |
Ng2Block |
Exposes an Angular 2 component as a block. |