Merge branch 'MDL-73495-master' of https://github.com/dravek/moodle
This commit is contained in:
@@ -31,19 +31,15 @@ use templatable;
|
||||
*/
|
||||
class dynamic_tabs implements templatable {
|
||||
|
||||
/** @var array */
|
||||
protected $attributes;
|
||||
/** @var base[] */
|
||||
protected $tabs = [];
|
||||
|
||||
/**
|
||||
* tabs constructor.
|
||||
*
|
||||
* @param array $attributes additional attributes that will be passed to the webservice
|
||||
* @param base[] $tabs array of tab
|
||||
*/
|
||||
public function __construct(array $attributes = [], array $tabs = []) {
|
||||
$this->attributes = $attributes;
|
||||
public function __construct(array $tabs = []) {
|
||||
foreach ($tabs as $tab) {
|
||||
$this->add_tab($tab);
|
||||
}
|
||||
@@ -66,20 +62,21 @@ class dynamic_tabs implements templatable {
|
||||
*/
|
||||
public function export_for_template(renderer_base $output): array {
|
||||
$data = [
|
||||
'dataattributes' => [],
|
||||
'tabs' => []
|
||||
];
|
||||
|
||||
foreach ($this->attributes as $name => $value) {
|
||||
$data['dataattributes'][] = ['name' => $name, 'value' => $value];
|
||||
}
|
||||
|
||||
foreach ($this->tabs as $tab) {
|
||||
$dataattributes = [];
|
||||
foreach ($tab->get_data() as $name => $value) {
|
||||
$dataattributes[] = ['name' => $name, 'value' => $value];
|
||||
}
|
||||
|
||||
$data['tabs'][] = [
|
||||
'shortname' => $tab->get_tab_id(),
|
||||
'displayname' => $tab->get_tab_label(),
|
||||
'enabled' => $tab->is_available(),
|
||||
'tabclass' => get_class($tab)
|
||||
'tabclass' => get_class($tab),
|
||||
'dataattributes' => $dataattributes,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -83,4 +83,22 @@ abstract class base implements templatable {
|
||||
* @return string
|
||||
*/
|
||||
abstract public function get_template(): string;
|
||||
|
||||
/**
|
||||
* Return tab data attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_data(): array {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom data to the tab data attributes
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function add_data(array $data): void {
|
||||
$this->data = array_merge($this->data, $data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user