Skip to content

Commit

Permalink
MDL-72466 core_output: dropdown menu alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Bas Brands committed Jan 27, 2022
1 parent e63604f commit 7c76e1c
Show file tree
Hide file tree
Showing 27 changed files with 25 additions and 47 deletions.
1 change: 0 additions & 1 deletion admin/tool/admin_presets/classes/output/presets_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public function export_for_template(renderer_base $output): stdClass {
$actionsmenu = new \action_menu();
$actionsmenu->set_menu_trigger(get_string('actions'));
$actionsmenu->set_owner_selector('preset-actions-' . $preset->id);
$actionsmenu->set_alignment(\action_menu::TL, \action_menu::BL);

$loadlink = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'load', 'id' => $preset->id]);
$actionsmenu->add(new \action_menu_link_secondary(
Expand Down
3 changes: 1 addition & 2 deletions admin/tool/analytics/classes/output/models_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function export_for_template(\renderer_base $output) {

$newmodelmenu = new \action_menu();
$newmodelmenu->set_menu_trigger(get_string('newmodel', 'tool_analytics'), 'btn btn-secondary');
$newmodelmenu->set_alignment(\action_menu::TL, \action_menu::BL);
$newmodelmenu->set_menu_left();

$newmodelmenu->add(new \action_menu_link(
new \moodle_url('/admin/tool/analytics/createmodel.php'),
Expand Down Expand Up @@ -191,7 +191,6 @@ public function export_for_template(\renderer_base $output) {
$actionsmenu = new \action_menu();
$actionsmenu->set_menu_trigger(get_string('actions'));
$actionsmenu->set_owner_selector('model-actions-' . $model->get_id());
$actionsmenu->set_alignment(\action_menu::TL, \action_menu::BL);

$urlparams = ['id' => $model->get_id(), 'sesskey' => sesskey()];

Expand Down
1 change: 0 additions & 1 deletion admin/tool/componentlibrary/docspage.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
$thememenu = new action_menu($menuthemes);
$thememenu->set_menu_trigger($PAGE->theme->name, 'nav-link');
$thememenu->set_owner_selector('change-moodle-theme');
$thememenu->set_alignment(\action_menu::TL, \action_menu::BL);
$PAGE->set_headingmenu($OUTPUT->render($thememenu));
}

Expand Down
1 change: 0 additions & 1 deletion admin/tool/dataprivacy/classes/output/crud_element.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ protected final function action_menu($elementname, $exported, $persistent) {
$actionmenu = new \action_menu();
$actionmenu->set_menu_trigger(get_string('actions'));
$actionmenu->set_owner_selector($elementname . '-' . $exported->id . '-actions');
$actionmenu->set_alignment(\action_menu::TL, \action_menu::BL);

$url = new \moodle_url('/admin/tool/dataprivacy/edit' . $elementname . '.php',
['id' => $exported->id]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public function export_for_template(renderer_base $output) {
$actionmenu = new \action_menu();
$actionmenu->set_menu_trigger(get_string('edit'), 'btn btn-primary');
$actionmenu->set_owner_selector('dataregistry-actions');
$actionmenu->set_alignment(\action_menu::TL, \action_menu::BL);

$url = new \moodle_url('/admin/tool/dataprivacy/categories.php');
$categories = new \action_menu_link_secondary($url, null, get_string('categories', 'tool_dataprivacy'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ public function col_actions($data) {
$actionsmenu = new action_menu($actions);
$actionsmenu->set_menu_trigger(get_string('actions'));
$actionsmenu->set_owner_selector('request-actions-' . $requestid);
$actionsmenu->set_alignment(\action_menu::TL, \action_menu::BL);
$actionsmenu->set_constraint('[data-region=data-requests-table] > .no-overflow');

return $OUTPUT->render($actionsmenu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ public function export_for_template(renderer_base $output) {
$actionsmenu = new action_menu($actions);
$actionsmenu->set_menu_trigger(get_string('actions'));
$actionsmenu->set_owner_selector('request-actions-' . $requestid);
$actionsmenu->set_alignment(\action_menu::TL, \action_menu::BL);
$item->actions = $actionsmenu->export_for_template($output);
}

Expand Down
1 change: 0 additions & 1 deletion admin/tool/policy/classes/output/page_managedocs_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ protected function export_version_for_template($output, $policy, $version, $isin

$actionmenu = new action_menu();
$actionmenu->set_menu_trigger(get_string('actions', 'tool_policy'));
$actionmenu->set_alignment(action_menu::TL, action_menu::BL);
$actionmenu->prioritise = true;
if ($moveup) {
$actionmenu->add(new action_menu_link(
Expand Down
1 change: 0 additions & 1 deletion contentbank/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@

// Create the cog menu with all the secondary actions, such as delete, rename...
$actionmenu = new action_menu();
$actionmenu->set_alignment(action_menu::TR, action_menu::BR);
if ($contenttype->can_manage($content)) {
// Add the visibility item to the menu.
switch($content->get_visibility()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ public function get_action_menu(\renderer_base $output): ?action_menu {

// Convert control array into an action_menu.
$menu = new action_menu();
$menu->set_alignment(action_menu::TR, action_menu::BR);
$icon = $output->pix_icon('i/menu', get_string('edit'));
$menu->set_menu_trigger($icon, 'btn btn-icon d-flex align-items-center justify-content-center');

Expand Down
1 change: 0 additions & 1 deletion course/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ public function course_section_cm_edit_actions($actions, cm_info $mod = null, $d
$menu = new action_menu();
$menu->set_owner_selector($ownerselector);
$menu->set_constraint($constraint);
$menu->set_alignment(action_menu::TR, action_menu::BR);
$menu->set_menu_trigger(get_string('edit'));

foreach ($actions as $action) {
Expand Down
1 change: 0 additions & 1 deletion customfield/classes/output/management.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public function export_for_template(\renderer_base $output) {
}

$menu = new \action_menu();
$menu->set_alignment(\action_menu::BL, \action_menu::BL);
$menu->set_menu_trigger(get_string('createnewcustomfield', 'core_customfield'));

foreach ($fieldtypes as $type => $fieldname) {
Expand Down
3 changes: 1 addition & 2 deletions grade/edit/tree/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ public function build_html_tree($element, $totals, $parents, $level, &$row_count
$actionsmenu = new action_menu();
$actionsmenu->set_menu_trigger(get_string('edit'));
$actionsmenu->set_owner_selector('grade-item-' . $eid);
$actionsmenu->set_alignment(action_menu::TL, action_menu::BL);

if (!$is_category_item && ($icon = $this->gtree->get_edit_icon($element, $this->gpr, true))) {
$actionsmenu->add($icon);
Expand Down Expand Up @@ -1090,4 +1089,4 @@ protected function get_checkbox_togglegroup(grade_category $category): string {

return $togglegroup;
}
}
}
1 change: 0 additions & 1 deletion h5p/classes/output/libraries.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public function export_for_template(renderer_base $output) {
// Get the action menu options.
$actionmenu = new action_menu();
$actionmenu->set_menu_trigger(get_string('actions', 'core_h5p'));
$actionmenu->set_alignment(action_menu::TL, action_menu::BL);
$actionmenu->prioritise = true;
$actionmenu->add_primary_action(new action_menu_link(
new moodle_url('/h5p/libraries.php', ['deletelibrary' => $version->id]),
Expand Down
20 changes: 19 additions & 1 deletion lib/outputcomponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -4232,6 +4232,12 @@ class action_menu implements renderable, templatable {
*/
public $prioritise = false;

/**
* Dropdown menu alignment class.
* @var string
*/
public $dropdownalignment = '';

/**
* Constructs the action menu with the given items.
*
Expand All @@ -4258,7 +4264,7 @@ public function __construct(array $actions = array()) {
'aria-labelledby' => 'action-menu-toggle-'.$this->instance,
'role' => 'menu'
);
$this->set_alignment(self::TR, self::BR);
$this->dropdownalignment = 'dropdown-menu-right';
foreach ($actions as $action) {
$this->add($action);
}
Expand Down Expand Up @@ -4436,10 +4442,13 @@ public function set_owner_selector($selector) {
/**
* Sets the alignment of the dialogue in relation to button used to toggle it.
*
* @deprecated since Moodle 4.0
*
* @param int $dialogue One of action_menu::TL, action_menu::TR, action_menu::BL, action_menu::BR.
* @param int $button One of action_menu::TL, action_menu::TR, action_menu::BL, action_menu::BR.
*/
public function set_alignment($dialogue, $button) {
debugging('The method action_menu::set_alignment() is deprecated, use action_menu::set_menu_left()', DEBUG_DEVELOPER);
if (isset($this->attributessecondary['data-align'])) {
// We've already got one set, lets remove the old class so as to avoid troubles.
$class = $this->attributessecondary['class'];
Expand Down Expand Up @@ -4472,6 +4481,14 @@ protected function get_align_string($align) {
}
}

/**
* Aligns the left corner of the dropdown.
*
*/
public function set_menu_left() {
$this->dropdownalignment = 'dropdown-menu-left';
}

/**
* Sets a constraint for the dialogue.
*
Expand Down Expand Up @@ -4633,6 +4650,7 @@ public function export_for_template(renderer_base $output) {

$data->primary = $primary;
$data->secondary = $secondary;
$data->dropdownalignment = $this->dropdownalignment;

return $data;
}
Expand Down
1 change: 0 additions & 1 deletion lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3469,7 +3469,6 @@ public function user_menu($user = null, $withlinks = null) {
'nav-link'
);
$am->set_action_label(get_string('usermenu'));
$am->set_alignment(action_menu::TR, action_menu::BR);
$am->set_nowrap_on_items();
if ($withlinks) {
$navitemcount = count($opts->navitems);
Expand Down
3 changes: 2 additions & 1 deletion lib/templates/action_menu_trigger.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
],
"secondary": {
"classes": "menu align-tr-br",
"dropdownalignment": "dropdown-menu-right",
"attributes": [
{"name": "id", "value": "action-menu-0-menu"},
{"name": "data-rel", "value": "menu-content"},
Expand Down Expand Up @@ -92,7 +93,7 @@
{{/menutrigger}}
</a>
{{#secondary}}
<div class="dropdown-menu dropdown-menu-right {{classes}}"{{#attributes}} {{name}}="{{value}}"{{/attributes}}>
<div class="dropdown-menu {{classes}} {{dropdownalignment}}"{{#attributes}} {{name}}="{{value}}"{{/attributes}}>
{{#items}}
{{#actionmenulink}}
{{< core/action_menu_link}}
Expand Down
2 changes: 2 additions & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ This files describes API changes in core libraries and APIs,
information provided here is intended especially for developers.

=== 4.0 ===
* The method action_menu->set_alignment() has been deprecated, please use action_menu->set_menu_left if you need a dropdown
to align to the left of the dropdown button.
* The $OUTPUT->should_display_main_logo() function has been deprecated and should no longer be used.
* New method flexible_table::set_columnsattributes() has been introduced to add column attributes applied in every cell.
* New method flexible_table::get_row_cells_html() has been introduced, extracted from flexible_table::get_row_html
Expand Down
1 change: 0 additions & 1 deletion mod/assign/gradingtable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,6 @@ public function col_userid(stdClass $row) {

$menu = new action_menu();
$menu->set_owner_selector('.gradingtable-actionmenu');
$menu->set_alignment(action_menu::TL, action_menu::BL);
$menu->set_constraint('.gradingtable > .no-overflow');
$menu->set_menu_trigger(get_string('edit'));
foreach ($actions as $action) {
Expand Down
1 change: 0 additions & 1 deletion mod/feedback/classes/complete_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ protected function enhance_name_for_edit($item, $element) {
$menu = new action_menu();
$menu->set_owner_selector('#' . $this->guess_element_id($item, $element));
$menu->set_constraint('.feedback_form');
$menu->set_alignment(action_menu::TR, action_menu::BR);
$menu->set_menu_trigger(get_string('edit'));
$menu->prioritise = true;

Expand Down
1 change: 0 additions & 1 deletion mod/quiz/classes/output/edit_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,6 @@ public function add_menu_actions(structure $structure, $page, \moodle_url $pageu
return '';
}
$menu = new \action_menu();
$menu->set_alignment(\action_menu::TR, \action_menu::TR);
$menu->set_constraint('.mod-quiz-edit-content');
$trigger = html_writer::tag('span', get_string('add', 'quiz'), array('class' => 'add-menu'));
$menu->set_menu_trigger($trigger);
Expand Down
1 change: 0 additions & 1 deletion payment/accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
}

$menu = new action_menu();
$menu->set_alignment(action_menu::TL, action_menu::BL);
$menu->set_menu_trigger(get_string('edit'));
if ($canmanage) {
$menu->add(new action_menu_link_secondary($account->get_edit_url(), null, get_string('edit')));
Expand Down
1 change: 0 additions & 1 deletion question/classes/local/bank/edit_menu_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ protected function display_content($question, $rowclasses): void {

$menu = new \action_menu();
$menu->set_menu_trigger(get_string('edit'));
$menu->set_alignment(\action_menu::TL, \action_menu::BL);
foreach ($this->actions as $actioncolumn) {
$action = $actioncolumn->get_action_menu_link($question);
if ($action) {
Expand Down
8 changes: 0 additions & 8 deletions theme/boost/scss/moodle/bootstrap-rtl.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@
background-position: 0.75rem center;
}

/*rtl:raw:
.dropdown-menu {
right: auto;
left: 0;
text-align: right;
}
*/

.dir-rtl .custom-switch .custom-control-input:checked ~ .custom-control-label::after {
transform: translateX(-($custom-switch-width - $custom-control-indicator-size));
}
7 changes: 0 additions & 7 deletions theme/boost/style/moodle.css
Original file line number Diff line number Diff line change
Expand Up @@ -9847,13 +9847,6 @@ a.text-dark:hover, a.text-dark:focus {
.dir-rtl .custom-select {
background-position: 0.75rem center; }

/*rtl:raw:
.dropdown-menu {
right: auto;
left: 0;
text-align: right;
}
*/
.dir-rtl .custom-switch .custom-control-input:checked ~ .custom-control-label::after {
transform: translateX(-0.9375rem); }

Expand Down
7 changes: 0 additions & 7 deletions theme/classic/style/moodle.css
Original file line number Diff line number Diff line change
Expand Up @@ -9847,13 +9847,6 @@ a.text-dark:hover, a.text-dark:focus {
.dir-rtl .custom-select {
background-position: 0.75rem center; }

/*rtl:raw:
.dropdown-menu {
right: auto;
left: 0;
text-align: right;
}
*/
.dir-rtl .custom-switch .custom-control-input:checked ~ .custom-control-label::after {
transform: translateX(-0.75rem); }

Expand Down
1 change: 0 additions & 1 deletion user/profile/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@

// Add new field menu.
$menu = new \action_menu();
$menu->set_alignment(\action_menu::BL, \action_menu::BL);
$menu->set_menu_trigger($strcreatefield);
foreach ($options as $type => $fieldname) {
$action = new \action_menu_link_secondary(new \moodle_url('#'), null, $fieldname,
Expand Down

0 comments on commit 7c76e1c

Please sign in to comment.