public static function EventLogStorage::formGetOperations in Events Log Track 8.2
Same name and namespace in other branches
- 8 src/EventLogStorage.php \Drupal\event_log_track\EventLogStorage::formGetOperations()
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 EventLogStorage::formGetOperations()
- OverviewForm::buildForm in src/
OverviewForm.php - Form constructor.
- OverviewForm::formGetAjaxOperation in src/
OverviewForm.php - Ajax callback for the operations options.
File
- src/
EventLogStorage.php, line 74
Class
- EventLogStorage
- Controller class for event log track required special handling for events.
Namespace
Drupal\event_log_trackCode
public static function formGetOperations($type) {
$element = [
'#type' => 'select',
'#name' => 'operation',
'#title' => t('CUD Operation'),
'#options' => [
'' => t('Choose an operation'),
],
'#prefix' => '<div id="operation-dropdown-replace">',
'#suffix' => '</div>',
];
if ($type) {
$db = \Drupal::database();
$query = $db
->select('event_log_track', '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;
}