You are here

public function WebformEntityStorage::getCategories in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/WebformEntityStorage.php \Drupal\webform\WebformEntityStorage::getCategories()

Gets the names of all categories.

Parameters

null|bool $template: If TRUE only template categories will be returned. If FALSE only webform categories will be returned. If NULL all categories will be returned.

Return value

string[] An array of translated categories, sorted alphabetically.

Overrides WebformEntityStorageInterface::getCategories

File

src/WebformEntityStorage.php, line 196

Class

WebformEntityStorage
Storage controller class for "webform" configuration entities.

Namespace

Drupal\webform

Code

public function getCategories($template = NULL) {
  $webforms = $this
    ->loadMultiple();
  $categories = [];
  foreach ($webforms as $webform) {
    if ($template !== NULL && $webform
      ->get('template') !== $template) {
      continue;
    }
    if ($category = $webform
      ->get('category')) {
      $categories[$category] = $category;
    }
  }
  ksort($categories);
  return $categories;
}