You are here

public function LogTemplateManager::getLabelsByCategory in Commerce Core 8.2

Gets the log template labels grouped by category.

Parameters

string $entity_type_id: (optional) The entity type ID to filter by. If provided, only log templates that belong to categories with the specified entity type will be returned.

Return value

array Keys are category labels, and values are arrays of which the keys are log template IDs and the values are log template labels.

Overrides LogTemplateManagerInterface::getLabelsByCategory

File

modules/log/src/LogTemplateManager.php, line 91

Class

LogTemplateManager
Manages discovery and instantiation of commerce_log_template plugins.

Namespace

Drupal\commerce_log

Code

public function getLabelsByCategory($entity_type_id = NULL) {
  $definitions = $this
    ->getSortedDefinitions();
  $category_labels = $this
    ->getCategoryLabels($entity_type_id);
  $grouped_definitions = [];
  foreach ($definitions as $id => $definition) {
    $category_id = $definition['category'];
    if (!isset($category_labels[$category_id])) {

      // Don't return log templates for categories ignored due to their entity type.
      continue;
    }
    $category_label = $category_labels[$category_id];
    $grouped_definitions[$category_label][$id] = $definition['label'];
  }
  return $grouped_definitions;
}