You are here

public function HubspotFormsCore::getFormIds in Hubspot forms 8

Get form ids.

File

src/HubspotFormsCore.php, line 20

Class

HubspotFormsCore
Class HubspotFormsCore.

Namespace

Drupal\hubspot_forms

Code

public function getFormIds() {
  $cid = 'hubspot_forms';
  $forms = NULL;
  if ($cache = \Drupal::cache()
    ->get($cid)) {
    $forms = $cache->data;
  }
  else {
    $forms = $this
      ->fetchHubspotForms();
    usort($forms, function ($a, $b) {
      return $b->createdAt - $a->createdAt;
    });
    \Drupal::cache()
      ->set($cid, $forms);
  }
  $form_ids = [
    '' => $this
      ->t('Choose a Hubspot form'),
  ];
  if (!empty($forms)) {
    foreach ($forms as $item) {
      $form_ids[$item->portalId . '::' . $item->guid] = $item->name;
    }
  }
  return $form_ids;
}