You are here

public function CloudBlockManager::loadAllFromRemote in Gutenberg 8.2

Same name and namespace in other branches
  1. 8 modules/gutenberg_cloud/src/CloudBlockManager.php \Drupal\gutenberg_cloud\CloudBlockManager::loadAllFromRemote()

Load available blocks from Gutenberg API.

The blocks are stored in variable, to avoid http calls on each method request.

Return value

array Array of CloudBlock instances or empty array if no results.

1 call to CloudBlockManager::loadAllFromRemote()
CloudBlockManager::loadRemote in modules/gutenberg_cloud/src/CloudBlockManager.php
Load single block from cloud.

File

modules/gutenberg_cloud/src/CloudBlockManager.php, line 96

Class

CloudBlockManager
Class CloudBlockManager.

Namespace

Drupal\gutenberg_cloud

Code

public function loadAllFromRemote() {
  $blocks = $this->blocks;
  if (!empty($this->blocks)) {
    return $blocks;
  }
  try {
    $request = $this->httpClient
      ->get($this
      ->getApiUrl());
    $blocksToLoad = json_decode($request
      ->getBody())->rows;
    foreach ($blocksToLoad as $block) {
      $cloudBlock = new CloudBlock($block);
      $blocks[$cloudBlock
        ->getName()] = $cloudBlock;
    }
  } catch (\Exception $e) {
    $blocks = [];
  }
  return $blocks;
}