mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 18:06:51 +02:00
MDL-67810 core_contentbank: added dropdown menu to create content
This commit is contained in:
parent
68fd8d8bdf
commit
75f58cbfa2
16 changed files with 437 additions and 14 deletions
|
@ -98,7 +98,56 @@ class bankcontent implements renderable, templatable {
|
|||
);
|
||||
}
|
||||
$data->contents = $contentdata;
|
||||
$data->tools = $this->toolbar;
|
||||
// The tools are displayed in the action bar on the index page.
|
||||
foreach ($this->toolbar as $tool) {
|
||||
// Customize the output of a tool, like dropdowns.
|
||||
$method = 'export_tool_'.$tool['name'];
|
||||
if (method_exists($this, $method)) {
|
||||
$this->$method($tool);
|
||||
}
|
||||
$data->tools[] = $tool;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the content type items to display to the Add dropdown.
|
||||
*
|
||||
* Each content type is represented as an object with the properties:
|
||||
* - name: the name of the content type.
|
||||
* - baseurl: the base content type editor URL.
|
||||
* - types: different types of the content type to display as dropdown items.
|
||||
*
|
||||
* @param array $tool Data for rendering the Add dropdown, including the editable content types.
|
||||
*/
|
||||
private function export_tool_add(array &$tool) {
|
||||
$editabletypes = $tool['contenttypes'];
|
||||
|
||||
$addoptions = [];
|
||||
foreach ($editabletypes as $class => $type) {
|
||||
$contentype = new $class($this->context);
|
||||
// Get the creation options of each content type.
|
||||
$types = $contentype->get_contenttype_types();
|
||||
if ($types) {
|
||||
// Add a text describing the content type as first option. This will be displayed in the drop down to
|
||||
// separate the options for the different content types.
|
||||
$contentdesc = new stdClass();
|
||||
$contentdesc->typename = get_string('description', $contentype->get_contenttype_name());
|
||||
array_unshift($types, $contentdesc);
|
||||
// Context data for the template.
|
||||
$addcontenttype = new stdClass();
|
||||
// Content type name.
|
||||
$addcontenttype->name = $type;
|
||||
// Content type editor base URL.
|
||||
$tool['link']->param('plugin', $type);
|
||||
$addcontenttype->baseurl = $tool['link']->out();
|
||||
// Different types of the content type.
|
||||
$addcontenttype->types = $types;
|
||||
$addoptions[] = $addcontenttype;
|
||||
}
|
||||
}
|
||||
|
||||
$tool['contenttypes'] = $addoptions;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue