You are here

public function Template::getTemplates in GatherContent 8

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

Fetch projects from GatherContent.

Return value

array Associative array of projects.

File

src/DAO/Template.php, line 59

Class

Template
Class Template.

Namespace

Drupal\gathercontent\DAO

Code

public function getTemplates($project_id) {
  $templates = array();
  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->name;
      }
    }
  } catch (\Exception $e) {
    drupal_set_message($e
      ->getMessage(), 'error');
    \Drupal::logger('gathercontent')
      ->error($e
      ->getMessage(), array());
  }
  return $templates;
}