Skip to content

Commit

Permalink
Add shortcut button serlo empty content
Browse files Browse the repository at this point in the history
  • Loading branch information
thang-new committed Oct 14, 2024
1 parent 505203d commit 2827b26
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
67 changes: 67 additions & 0 deletions classes/output/format_topics_renderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Settings code for the serlo theme
*
* @package theme_serlo
* @author Faisal Kaleem <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright 2024 Serlo (https://adornis.de)
*/

namespace theme_serlo\output;

defined('MOODLE_INTERNAL') || die();

use \format_topics\output\renderer;
use \moodle_url;
use context_course;

/**
* Renderers format topics
*/
class format_topics_renderer extends renderer
{
function course_section_add_cm_control($course, $section, $sectionreturn = null, $displayoptions = array())
{
// Check to see if user can add menus.
if (
!has_capability('moodle/course:manageactivities', context_course::instance($course->id))
|| !$this->page->user_is_editing()
) {
return '';
}

$data = [
'sectionid' => $section,
'sectionreturn' => $sectionreturn,
'serlo_empty_editor_url' => new moodle_url('/course/modedit.php', [
"course" => $course->id,
"add" => "serlo",
"return" => 0,
"type" => "empty",
"section" => $section,
])
];
$ajaxcontrol = $this->render_from_template('core_course/activitychooserbutton', $data);

// Load the JS for the modal.
$this->course_activitychooser($course->id);

return $ajaxcontrol;
}
}
1 change: 1 addition & 0 deletions lang/de/theme_serlo.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@
$string['secondbutton'] = 'Second Button';
$string['secondbutton_desc'] = 'This is a description for the second button.';
$string['serlo'] = 'Serlo';
$string['serlo_empty_editor'] = 'Serlo Editor';
1 change: 1 addition & 0 deletions lang/en/theme_serlo.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@
$string['secondbutton'] = 'Second Button';
$string['secondbutton_desc'] = 'This is a description for the second button.';
$string['serlo'] = 'Serlo';
$string['serlo_empty_editor'] = 'Serlo Editor';
6 changes: 6 additions & 0 deletions pix/serlo-logo-feather.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions templates/core_course/activitychooserbutton.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template core_course/activitychooserbutton
Displays a add activity or resource button.
Context variables required for this template:
* sectionid - Relative section number (field course_sections.section).
* sectionreturn - The section to link back to.
Example context (json):
{
"sectionid": 1,
"sectionreturn": 0
}
}}
{{< core_courseformat/local/content/divider}}
{{$extraclasses}}always-visible my-3{{/extraclasses}}
{{$content}}
<button class="btn add-content section-modchooser section-modchooser-link justify-content-center align-items-center py-1 px-2"
data-action="open-chooser"
data-sectionid="{{sectionid}}"
{{#sectionreturn}}data-sectionreturnid="{{.}}"{{/sectionreturn}}
>
{{#pix}} t/add, core {{/pix}}
<span class="activity-add-text pr-1">{{#str}}addresourceoractivity, core{{/str}}</span>
</button>
<a href="{{{serlo_empty_editor_url}}}" class="btn add-content justify-content-center align-items-center py-1 px-2"
>
{{#pix}} serlo-logo-feather, theme_serlo {{/pix}}
<span class="activity-add-text pr-1">{{#str}}serlo_empty_editor, theme_serlo{{/str}}</span>
</a>
{{/content}}
{{/ core_courseformat/local/content/divider}}

0 comments on commit 2827b26

Please sign in to comment.