You are here

public static function AdminAuditTrailStorage::formGetOperations in Admin Audit Trail 1.0.x

Returns the form element for the operations based on the event log type.

Parameters

string $type: Event type.

Return value

array A form element.

2 calls to AdminAuditTrailStorage::formGetOperations()
OverviewForm::buildForm in src/OverviewForm.php
Form constructor.
OverviewForm::formGetAjaxOperation in src/OverviewForm.php
Ajax callback for the operations options.

File

src/AdminAuditTrailStorage.php, line 73

Class

AdminAuditTrailStorage
Controller class for admin audit trail required special handling for events.

Namespace

Drupal\admin_audit_trail

Code

public static function formGetOperations($type) {
  $element = [
    '#type' => 'select',
    '#name' => 'operation',
    '#title' => t('Operation'),
    '#description' => t('The entity operation.'),
    '#options' => [
      '' => t('Choose an operation'),
    ],
    '#prefix' => '<div id="operation-dropdown-replace">',
    '#suffix' => '</div>',
  ];
  if ($type) {
    $db = \Drupal::database();
    $query = $db
      ->select('admin_audit_trail', 'e')
      ->fields('e', [
      'operation',
    ])
      ->condition('type', $type)
      ->groupBy('operation');
    $query
      ->addExpression('COUNT(e.lid)', 'c');
    $query
      ->distinct(TRUE);
    $results = $query
      ->execute()
      ->fetchAllKeyed(0);
    $operations = [];
    foreach ($results as $name => $count) {
      $operations[$name] = $name . ' (' . $count . ')';
    }
    $element['#options'] += $operations;
  }
  return $element;
}