Skip to content

Commit

Permalink
Merge pull request #115 from laceysanderson/hook_into_dashboards
Browse files Browse the repository at this point in the history
Hook into dashboards
  • Loading branch information
almasaeed2010 authored Oct 15, 2019
2 parents 2b38a25 + daaf4c0 commit 45589eb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
36 changes: 19 additions & 17 deletions includes/tripal_hq_admin_dashboard.form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function tripal_hq_admin_dashboard_form(array $form, array &$form_state, $status
global $user;
$uid = $user->uid;

$items_per_page = 10;

$form['instructions'] = ['#markup' => $message];

$header = [
Expand Down Expand Up @@ -80,7 +82,7 @@ function tripal_hq_admin_dashboard_form(array $form, array &$form_state, $status

$requests = $query->fields('t')
->orderBy('id', 'desc')
->limit(10)
->limit($items_per_page)
->execute()
->fetchAll();
}
Expand All @@ -95,20 +97,11 @@ function tripal_hq_admin_dashboard_form(array $form, array &$form_state, $status
}
$requests = $query->fields('t')
->orderBy('id', 'desc')
->limit(10)
->limit($items_per_page)
->execute()
->fetchAll();
}

if (!$requests) {
$message = '<h4>no ' . $status . ' requests</h4>';

$form['message'] = [
'#markup' => $message,
];
return $form;
}

$rows = [];
$date_format = 'M d Y H:i:s';

Expand Down Expand Up @@ -144,14 +137,23 @@ function tripal_hq_admin_dashboard_form(array $form, array &$form_state, $status
$rows[] = $row;
}

$output = theme('table', [
'header' => $header,
'rows' => $rows,
]);
$form['table'] = [
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('There are no !status content submissions.', ['!status' => $status]),
];

$form['pager'] = [
'#theme' => 'pager',
];

$output .= theme('pager', ['quantity', 5]);
// Now we add in an alter hook to allow submodules to add to this dashboard.
// To use this after hook in your own module create a function named
// [yourmodule]_tripal_hq_admin_dashboard_alter($form, $form_state, $status)
// and change or add to the form as needed.
drupal_alter('tripal_hq_admin_dashboard', $form, $form_state, $status);

$form['table'] = ['#markup' => $output];
return $form;
}

Expand Down
27 changes: 19 additions & 8 deletions includes/tripal_hq_user_dashboard.form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function tripal_hq_user_dashboard_form($form, &$form_state) {
global $user;
$uid = $user->uid;

$items_per_page = 5;

$header = [
'Title' => [
'data' => t('Title'),
Expand Down Expand Up @@ -45,7 +47,7 @@ function tripal_hq_user_dashboard_form($form, &$form_state) {
->extend('TableSort')
->orderByHeader($header)
->extend('PagerDefault')
->limit(20)
->limit($items_per_page)
->execute()
->fetchAll();

Expand Down Expand Up @@ -101,13 +103,22 @@ function tripal_hq_user_dashboard_form($form, &$form_state) {
];
}

$output = theme(
'table', [
'header' => $header,
'rows' => $rows,
]
);
$form['my_submissions'] = [
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t("You have no pending content submissions."),
];

$form['pager'] = [
'#theme' => 'pager',
];

// Now we add in an alter hook to allow submodules to add to this dashboard.
// To use this after hook in your own module create a function named
// [yourmodule]_tripal_hq_user_dashboard_alter($form, $form_state) {}
// and change or add to the form as needed.
drupal_alter('tripal_hq_user_dashboard', $form, $form_state);

$form['my_submissions'] = ['#markup' => $output];
return $form;
}

0 comments on commit 45589eb

Please sign in to comment.