You are here

public function Template::getTemplatesObject in GatherContent 8.3

Same name and namespace in other branches
  1. 8 src/DAO/Template.php \Drupal\gathercontent\DAO\Template::getTemplatesObject()

Fetch projects from GatherContent.

Return value

array Associative array of projects.

File

src/DAO/Template.php, line 85

Class

Template
Class Template.

Namespace

Drupal\gathercontent\DAO

Code

public function getTemplatesObject($project_id) {
  $templates = [];
  try {
    $response = $this->client
      ->get('/templates?project_id=' . $project_id);
    if ($response
      ->getStatusCode() === 200) {
      $data = json_decode($response
        ->getBody());
      foreach ($data->data as $template) {
        $templates[$template->id] = $template;
      }
    }
  } catch (\Exception $e) {
    drupal_set_message($e
      ->getMessage(), 'error');
    \Drupal::logger('gathercontent')
      ->error($e
      ->getMessage(), []);
  }
  return $templates;
}