public static function EventLogStorage::formGetOperations in Events Log Track 8
Same name and namespace in other branches
- 8.2 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 = array(
'#type' => 'select',
'#name' => 'operation',
'#title' => t('Operation'),
'#description' => t('The entity operation.'),
'#options' => array(
'' => 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 = array();
foreach ($results as $name => $count) {
$operations[$name] = $name . ' (' . $count . ')';
}
$element['#options'] += $operations;
}
return $element;
}