MDL-78556 tablelib: flexible_table should support caption tag

This commit is contained in:
danghieu1407
2023-07-11 14:15:22 +07:00
parent 2ef6a3b9b9
commit 38d1c5f174
3 changed files with 104 additions and 18 deletions
+38 -1
View File
@@ -171,6 +171,16 @@ class flexible_table {
/** @var bool $resetting Whether the table preferences is resetting. */
protected $resetting;
/**
* @var string $caption The caption of table
*/
public $caption;
/**
* @var array $captionattributes The caption attributes of table
*/
public $captionattributes;
/**
* @var filterset The currently applied filerset
* This is required for dynamic tables, but can be used by other tables too if desired.
@@ -1839,8 +1849,35 @@ class flexible_table {
// Start of main data table
echo html_writer::start_tag('div', array('class' => 'no-overflow'));
echo html_writer::start_tag('table', $this->attributes);
echo html_writer::start_tag('table', $this->attributes) . $this->render_caption();
}
/**
* This function set caption for table.
*
* @param string $caption Caption of table.
* @param array|null $captionattributes Caption attributes of table.
*/
public function set_caption(string $caption, ?array $captionattributes): void {
$this->caption = $caption;
$this->captionattributes = $captionattributes;
}
/**
* This function renders a table caption.
*
* @return string $output Caption of table.
*/
public function render_caption(): string {
if ($this->caption === null) {
return '';
}
return html_writer::tag(
'caption',
$this->caption,
$this->captionattributes,
);
}
/**