class CloudBlock in Gutenberg 8
Same name and namespace in other branches
- 8.2 modules/gutenberg_cloud/src/CloudBlock.php \Drupal\gutenberg_cloud\CloudBlock
Class CloudBlock.
Hierarchy
- class \Drupal\gutenberg_cloud\CloudBlockBase implements CloudBlockInterface
- class \Drupal\gutenberg_cloud\CloudBlock
Expanded class hierarchy of CloudBlock
File
- modules/
gutenberg_cloud/ src/ CloudBlock.php, line 8
Namespace
Drupal\gutenberg_cloudView source
class CloudBlock extends CloudBlockBase {
/**
* Raw block retrieved from API.
*
* @var null
*/
protected $raw = NULL;
/**
* CloudBlock constructor.
*
* @param mixed $block
* Cloud block structure.
*/
public function __construct($block) {
if (is_object($block)) {
$this
->mapFromBlock($block);
}
else {
parent::__construct($block);
}
}
/**
* Getter for raw block.
*
* @return object|null
* Block object, defaults to null.
*/
public function getRaw() {
return $this->raw;
}
/**
* Defines prefix for accessing the assets.
*/
public function getPrefix() {
return $this->name . '@' . $this->version . '/';
}
/**
* Get asset URL.
*
* @param string $name
* Name of the asset.
* @param string $base_url
* Base Url.
*
* @return string|null
* Url of the asset or NULL if the asset name
* was not allowed or the name value was empty.
*/
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);
}
/**
* Map the API block to CloudBlock properties.
*
* @param object $block
* Cloud Block from API.
*/
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CloudBlock:: |
protected | property | Raw block retrieved from API. | |
CloudBlock:: |
public | function | Get asset URL. | |
CloudBlock:: |
public | function | Defines prefix for accessing the assets. | |
CloudBlock:: |
public | function | Getter for raw block. | |
CloudBlock:: |
protected | function | Map the API block to CloudBlock properties. | |
CloudBlock:: |
public | function |
CloudBlock constructor. Overrides CloudBlockBase:: |
|
CloudBlockBase:: |
protected | property | Block description. | |
CloudBlockBase:: |
protected | property | Block edit css. | |
CloudBlockBase:: |
protected | property | Block js. | |
CloudBlockBase:: |
protected | property | Block label (human readable name). | |
CloudBlockBase:: |
protected | property | Block machine name. | |
CloudBlockBase:: |
protected | property | Block screenshot. | |
CloudBlockBase:: |
protected | property | Block version. | |
CloudBlockBase:: |
protected | property | Block view css. | |
CloudBlockBase:: |
public | function |
Getter for object properties. Overrides CloudBlockInterface:: |
|
CloudBlockBase:: |
public | function |
Getter for properties related to Cloud Block config. Overrides CloudBlockInterface:: |
|
CloudBlockBase:: |
public | function |
Getter for description. Overrides CloudBlockInterface:: |
|
CloudBlockBase:: |
public | function |
Getter for edit css. Overrides CloudBlockInterface:: |
|
CloudBlockBase:: |
public | function |
Getter for js. Overrides CloudBlockInterface:: |
|
CloudBlockBase:: |
public | function |
Getter for label. Overrides CloudBlockInterface:: |
|
CloudBlockBase:: |
public | function |
Getter for name. Overrides CloudBlockInterface:: |
|
CloudBlockBase:: |
public | function |
Getter for screenshot. Overrides CloudBlockInterface:: |
|
CloudBlockBase:: |
public | function |
Getter for version. Overrides CloudBlockInterface:: |
|
CloudBlockBase:: |
public | function |
Getter for view css. Overrides CloudBlockInterface:: |
|
CloudBlockBase:: |
protected | function | Sets object properties based on a given array. |