diff -u b/dbtng_example/dbtng_example.module b/dbtng_example/dbtng_example.module --- b/dbtng_example/dbtng_example.module +++ b/dbtng_example/dbtng_example.module @@ -589,14 +589,7 @@ */ function dbtng_example_ordered_list() { $result = dbtng_example_execute_ordered_select_query(); - $output = ''; - if ($result) { - $output .= dbtng_example_render_resultset_as_table($result); - } - else { - drupal_set_message(t('No records found.')); - } - return $output; + return dbtng_example_render_resultset_as_table($result); } /** @@ -617,7 +610,6 @@ $dbtng_example_execute_ordered_select_query->orderBy('ex.name', 'ASC'); // generate the result in object format. $dbtng_example_result = $dbtng_example_execute_ordered_select_query->execute()->fetchAll(); - // return the result return $dbtng_example_result; } @@ -626,14 +618,26 @@ */ function dbtng_example_render_resultset_as_table($result) { $rows = array(); - foreach ($result as $row) { - // Sanitize the data before handing it off to the theme layer. - $rows[] = array_map('check_plain', (array) $row); + if($result) { + foreach ($result as $row) { + // Sanitize the data before handing it off to the theme layer. + $rows[] = array_map('check_plain', (array) $row); + } } - // Make a table for them. + return dbtng_example_convert_resultset_to_table_render_array($rows); +} + +/** + * This function renders array for table 'dbtng_example' + */ +function dbtng_example_convert_resultset_to_table_render_array($rows = array()) { $header = array(t('Id'), t('uid'), t('Name'), t('Surname'), t('Age')); - $output = theme('table', array('header' => $header, 'rows' => $rows)); - return $output; + return [ + '#theme' => 'table', + '#header' => $header, + '#rows' => $rows, + '#empty' => t('No records found'), + ]; } /** * @} End of "defgroup dbtng_example".