CloudBlock.php in Gutenberg 8.2
File
modules/gutenberg_cloud/src/CloudBlock.php
View source
<?php
namespace Drupal\gutenberg_cloud;
class CloudBlock extends CloudBlockBase {
protected $raw = NULL;
public function __construct($block) {
if (is_object($block)) {
$this
->mapFromBlock($block);
}
else {
parent::__construct($block);
}
}
public function getRaw() {
return $this->raw;
}
public function getPrefix() {
return $this->name . '@' . $this->version . '/';
}
public function getAssetUrl($name = '', $base_url = '') {
$allowed = [
'screenshot',
'js',
'edit_css',
'view_css',
];
if (empty($name) || !in_array($name, $allowed)) {
return NULL;
}
return $base_url . $this
->getPrefix() . $this
->get($name);
}
protected function mapFromBlock(\stdClass $block) {
$structure = [
'name' => $block->name,
'version' => $block->version,
'label' => $block->config->name,
'description' => $block->package->description,
'js' => $block->config->js ?? NULL,
'screenshot' => $block->config->screenshot ?? NULL,
'edit_css' => $block->config->editor ?? NULL,
'view_css' => $block->config->css ?? NULL,
'raw' => $block,
];
$this
->setConfig($structure);
}
}