public function NodeTypeCountController::userRoleCount in Node Type count 8
This code (noted in the callback above) creates the.
Contents of the page for User count.
1 string reference to 'NodeTypeCountController::userRoleCount'
File
- src/
Controller/ NodeTypeCountController.php, line 71 - Contains \Drupal\node_type_count\Controller\NodeTypeCountController.
Class
- NodeTypeCountController
- Controller routines for page example routes.
Namespace
Drupal\node_type_count\ControllerCode
public function userRoleCount() {
// We are going to output the results in a table with a nice header.
$header = array(
t('Role Name'),
t('Role Machine Name'),
t('Number of Users'),
);
$results = user_role_names();
if (is_array($results)) {
foreach ($results as $user_role_machine_name => $content_type_title) {
// Get the value as key and value pair.
$result_arr['title'] = check_plain($content_type_title);
$result_arr['machine_name'] = $user_role_machine_name;
$result_arr['count'] = NodeTypeCountController::userCountByRole($user_role_machine_name);
$result_final[$user_role_machine_name] = $result_arr;
}
}
$rows = array();
foreach ($result_final as $row) {
// Normally we would add some nice formatting to our rows
// but for our purpose we are simply going to add our row
// to the array.
$rows[] = array(
'data' => (array) $row,
);
}
// Build the table for the nice output.
$build = array(
'#markup' => '<p>' . t('The layout here is a themed as a table
that is sortable by clicking the header name.') . '</p>',
);
$build['tablesort_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
);
return $build;
}