Skip to content

Commit

Permalink
Add behat generators, named selectors and page URLs for smart menus. (m…
Browse files Browse the repository at this point in the history
…oodle-an-hochschulen#765)

This creates generators and named selectors for smart menus and smart
menu items, plus some navigation URLs for the smart menu settings forms.
  • Loading branch information
marxjohnson committed Nov 22, 2024
1 parent 57c6304 commit 62b8670
Show file tree
Hide file tree
Showing 7 changed files with 1,435 additions and 117 deletions.
53 changes: 8 additions & 45 deletions classes/form/smartmenu_edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ public function definition() {
$mform->addRule('location', get_string('required'), 'required');

// Add mode as select element.
$modeoptions = [
smartmenu::MODE_SUBMENU => get_string('smartmenusmodesubmenu', 'theme_boost_union'),
smartmenu::MODE_INLINE => get_string('smartmenusmodeinline', 'theme_boost_union'),
];
$modeoptions = smartmenu::get_mode_options();
$mform->addElement('select', 'mode', get_string('smartmenusmenumode', 'theme_boost_union'), $modeoptions);
$mform->setDefault('mode', smartmenu::MODE_SUBMENU);
$mform->setType('mode', PARAM_INT);
Expand All @@ -102,24 +99,15 @@ public function definition() {
$mform->addHelpButton('type', 'smartmenusmenutype', 'theme_boost_union');

// Add show description as select element.
$showdescriptionoptions = [
smartmenu::DESC_NEVER => get_string('smartmenusmenushowdescriptionnever', 'theme_boost_union'),
smartmenu::DESC_ABOVE => get_string('smartmenusmenushowdescriptionabove', 'theme_boost_union'),
smartmenu::DESC_BELOW => get_string('smartmenusmenushowdescriptionbelow', 'theme_boost_union'),
smartmenu::DESC_HELP => get_string('smartmenusmenushowdescriptionhelp', 'theme_boost_union'),
];
$showdescriptionoptions = smartmenu::get_showdescription_options();
$mform->addElement('select', 'showdesc', get_string('smartmenusmenushowdescription', 'theme_boost_union'),
$showdescriptionoptions);
$mform->setDefault('showdesc', smartmenu::DESC_NEVER);
$mform->setType('showdesc', PARAM_INT);
$mform->addHelpButton('showdesc', 'smartmenusmenushowdescription', 'theme_boost_union');

// Add more menu behavior as select element.
$moremenuoptions = [
smartmenu::MOREMENU_DONOTCHANGE => get_string('dontchange', 'theme_boost_union'),
smartmenu::MOREMENU_INTO => get_string('smartmenusmenumoremenubehaviorforceinto', 'theme_boost_union'),
smartmenu::MOREMENU_OUTSIDE => get_string('smartmenusmenumoremenubehaviorkeepoutside', 'theme_boost_union'),
];
$moremenuoptions = smartmenu::get_moremenu_options();
$mform->addElement('select', 'moremenubehavior', get_string('smartmenusmenumoremenubehavior', 'theme_boost_union'),
$moremenuoptions);
$mform->setDefault('moremenubehavior', smartmenu::MOREMENU_DONOTCHANGE);
Expand All @@ -132,29 +120,15 @@ public function definition() {
$mform->setType('cssclass', PARAM_TEXT);

// Add card size as select element.
$cardsizeoptions = [
smartmenu::CARDSIZE_TINY => get_string('smartmenusmenucardsizetiny', 'theme_boost_union').' (50px)',
smartmenu::CARDSIZE_SMALL => get_string('smartmenusmenucardsizesmall', 'theme_boost_union').' (100px)',
smartmenu::CARDSIZE_MEDIUM => get_string('smartmenusmenucardsizemedium', 'theme_boost_union').' (150px)',
smartmenu::CARDSIZE_LARGE => get_string('smartmenusmenucardsizelarge', 'theme_boost_union').' (200px)',
];
$cardsizeoptions = smartmenu::get_cardsize_options();
$mform->addElement('select', 'cardsize', get_string('smartmenusmenucardsize', 'theme_boost_union'), $cardsizeoptions);
$mform->setDefault('cardsize', smartmenu::CARDSIZE_TINY);
$mform->setType('cardsize', PARAM_INT);
$mform->hideIf('cardsize', 'type', 'neq', smartmenu::TYPE_CARD);
$mform->addHelpButton('cardsize', 'smartmenusmenucardsize', 'theme_boost_union');

// Add card form as select element.
$cardformoptions = [
smartmenu::CARDFORM_SQUARE =>
get_string('smartmenusmenucardformsquare', 'theme_boost_union').' (1/1)',
smartmenu::CARDFORM_PORTRAIT =>
get_string('smartmenusmenucardformportrait', 'theme_boost_union').' (2/3)',
smartmenu::CARDFORM_LANDSCAPE =>
get_string('smartmenusmenucardformlandscape', 'theme_boost_union').' (3/2)',
smartmenu::CARDFORM_FULLWIDTH =>
get_string('smartmenusmenucardformfullwidth', 'theme_boost_union'),
];
$cardformoptions = smartmenu::get_cardform_options();
$mform->addElement('select', 'cardform',
get_string('smartmenusmenucardform', 'theme_boost_union'), $cardformoptions);
$mform->setDefault('cardform', smartmenu::CARDFORM_SQUARE);
Expand All @@ -163,12 +137,7 @@ public function definition() {
$mform->addHelpButton('cardform', 'smartmenusmenucardform', 'theme_boost_union');

// Add card overflow behaviour as select element.
$cardoverflowoptions = [
smartmenu::CARDOVERFLOWBEHAVIOUR_NOWRAP =>
get_string('smartmenusmenucardoverflowbehaviornowrap', 'theme_boost_union'),
smartmenu::CARDOVERFLOWBEHAVIOUR_WRAP =>
get_string('smartmenusmenucardoverflowbehaviorwrap', 'theme_boost_union'),
];
$cardoverflowoptions = smartmenu::get_cardoverflowbehaviour_options();
$mform->addElement('select', 'cardoverflowbehavior',
get_string('smartmenusmenucardoverflowbehavior', 'theme_boost_union'), $cardoverflowoptions);
$mform->setDefault('cardoverflowbehaviour', smartmenu::CARDOVERFLOWBEHAVIOUR_NOWRAP);
Expand Down Expand Up @@ -199,10 +168,7 @@ public function definition() {
$mform->addHelpButton('roles', 'smartmenusbyrole', 'theme_boost_union');

// Add context as select element.
$rolecontext = [
smartmenu::ANYCONTEXT => get_string('any'),
smartmenu::SYSTEMCONTEXT => get_string('coresystem'),
];
$rolecontext = smartmenu::get_rolecontext_options();
$mform->addElement('select', 'rolecontext', get_string('smartmenusrolecontext', 'theme_boost_union'), $rolecontext);
$mform->setDefault('rolecontext', smartmenu::ANYCONTEXT);
$mform->setType('rolecontext', PARAM_INT);
Expand Down Expand Up @@ -249,10 +215,7 @@ public function definition() {
$mform->addHelpButton('cohorts', 'smartmenusbycohort', 'theme_boost_union');

// Add operator as select element.
$operatoroptions = [
smartmenu::ANY => get_string('any'),
smartmenu::ALL => get_string('all'),
];
$operatoroptions = smartmenu::get_operator_options();
$mform->addElement('select', 'operator', get_string('smartmenusoperator', 'theme_boost_union'), $operatoroptions);
$mform->setDefault('operator', smartmenu::ANY);
$mform->setType('operator', PARAM_INT);
Expand Down
79 changes: 10 additions & 69 deletions classes/form/smartmenu_item_edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ public function definition() {
$mform->addHelpButton('url', 'smartmenusmenuitemurl', 'theme_boost_union');

// Add mode as select element.
$modeoptions = [
smartmenu_item::MODE_INLINE => get_string('smartmenusmodeinline', 'theme_boost_union'),
smartmenu_item::MODE_SUBMENU => get_string('smartmenusmodesubmenu', 'theme_boost_union'),
];
$modeoptions = smartmenu_item::get_mode_options();
$mform->addElement('select', 'mode', get_string('smartmenusmenuitemmode', 'theme_boost_union'), $modeoptions);
$mform->setDefault('mode', smartmenu_item::MODE_INLINE);
$mform->setType('mode', PARAM_INT);
Expand Down Expand Up @@ -138,14 +135,7 @@ public function definition() {
$mform->addHelpButton('enrolmentrole', 'smartmenusdynamiccoursesenrolmentrole', 'theme_boost_union');

// Add completion status (for the dynamic courses menu item type) as autocomplete element.
$completionstatusoptions = [
smartmenu_item::COMPLETION_ENROLLED =>
get_string('smartmenusdynamiccoursescompletionstatusenrolled', 'theme_boost_union'),
smartmenu_item::COMPLETION_INPROGRESS =>
get_string('smartmenusdynamiccoursescompletionstatusinprogress', 'theme_boost_union'),
smartmenu_item::COMPLETION_COMPLETED =>
get_string('smartmenusdynamiccoursescompletionstatuscompleted', 'theme_boost_union'),
];
$completionstatusoptions = smartmenu_item::get_completionstatus_options();
$completionstatuswidget = $mform->addElement('autocomplete', 'completionstatus',
get_string('smartmenusmenuitemtypedynamiccourses', 'theme_boost_union').': '.
get_string('smartmenusdynamiccoursescompletionstatus', 'theme_boost_union'), $completionstatusoptions);
Expand All @@ -155,14 +145,7 @@ public function definition() {
$mform->addHelpButton('completionstatus', 'smartmenusdynamiccoursescompletionstatus', 'theme_boost_union');

// Add date range (for the dynamic courses menu item type) as autocomplete element.
$daterangeoptions = [
smartmenu_item::RANGE_PAST =>
get_string('smartmenusdynamiccoursesdaterangepast', 'theme_boost_union'),
smartmenu_item::RANGE_PRESENT =>
get_string('smartmenusdynamiccoursesdaterangepresent', 'theme_boost_union'),
smartmenu_item::RANGE_FUTURE =>
get_string('smartmenusdynamiccoursesdaterangefuture', 'theme_boost_union'),
];
$daterangeoptions = smartmenu_item::get_daterange_options();
$daterangewidget = $mform->addElement('autocomplete', 'daterange',
get_string('smartmenusmenuitemtypedynamiccourses', 'theme_boost_union').': '.
get_string('smartmenusdynamiccoursesdaterange', 'theme_boost_union'), $daterangeoptions);
Expand Down Expand Up @@ -196,13 +179,7 @@ public function definition() {
$PAGE->requires->js_call_amd('theme_boost_union/fontawesome-popover', 'init', ['#id_menuicon', $systemcontextid]);

// Add title presentation and select element.
$displayoptions = [
smartmenu_item::DISPLAY_SHOWTITLEICON =>
get_string('smartmenusmenuitemdisplayoptionsshowtitleicon', 'theme_boost_union'),
smartmenu_item::DISPLAY_HIDETITLE => get_string('smartmenusmenuitemdisplayoptionshidetitle', 'theme_boost_union'),
smartmenu_item::DISPLAY_HIDETITLEMOBILE =>
get_string('smartmenusmenuitemdisplayoptionshidetitlemobile', 'theme_boost_union'),
];
$displayoptions = smartmenu_item::get_display_options();
$mform->addElement('select', 'display', get_string('smartmenusmenuitemdisplayoptions', 'theme_boost_union'),
$displayoptions);
$mform->setDefault('display', smartmenu_item::DISPLAY_SHOWTITLEICON);
Expand All @@ -215,10 +192,7 @@ public function definition() {
$mform->addHelpButton('tooltip', 'smartmenusmenuitemtooltip', 'theme_boost_union');

// Add link target as select element.
$targetoptions = [
smartmenu_item::TARGET_SAME => get_string('smartmenusmenuitemlinktargetsamewindow', 'theme_boost_union'),
smartmenu_item::TARGET_NEW => get_string('smartmenusmenuitemlinktargetnewtab', 'theme_boost_union'),
];
$targetoptions = smartmenu_item::get_target_options();
$mform->addElement('select', 'target', get_string('smartmenusmenuitemlinktarget', 'theme_boost_union'),
$targetoptions);
$mform->setDefault('target', smartmenu_item::TARGET_SAME);
Expand Down Expand Up @@ -256,24 +230,7 @@ public function definition() {
$mform->addHelpButton('cssclass', 'smartmenusmenuitemcssclass', 'theme_boost_union');

// Add course list ordering (for the dynamic courses menu item type) as select element.
$listsortoptions = [
smartmenu_item::LISTSORT_FULLNAME_ASC =>
get_string('smartmenusmenuitemlistsortfullnameasc', 'theme_boost_union'),
smartmenu_item::LISTSORT_FULLNAME_DESC =>
get_string('smartmenusmenuitemlistsortfullnamedesc', 'theme_boost_union'),
smartmenu_item::LISTSORT_SHORTNAME_ASC =>
get_string('smartmenusmenuitemlistsortshortnameasc', 'theme_boost_union'),
smartmenu_item::LISTSORT_SHORTNAME_DESC =>
get_string('smartmenusmenuitemlistsortshortnamedesc', 'theme_boost_union'),
smartmenu_item::LISTSORT_COURSEID_ASC =>
get_string('smartmenusmenuitemlistsortcourseidasc', 'theme_boost_union'),
smartmenu_item::LISTSORT_COURSEID_DESC =>
get_string('smartmenusmenuitemlistsortcourseiddesc', 'theme_boost_union'),
smartmenu_item::LISTSORT_COURSEIDNUMBER_ASC =>
get_string('smartmenusmenuitemlistsortcourseidnumberasc', 'theme_boost_union'),
smartmenu_item::LISTSORT_COURSEIDNUMBER_DESC =>
get_string('smartmenusmenuitemlistsortcourseidnumberdesc', 'theme_boost_union'),
];
$listsortoptions = smartmenu_item::get_listsort_options();
$mform->addElement('select', 'listsort',
get_string('smartmenusmenuitemtypedynamiccourses', 'theme_boost_union').': '.
get_string('smartmenusmenuitemlistsort', 'theme_boost_union'), $listsortoptions);
Expand All @@ -283,10 +240,7 @@ public function definition() {
$mform->addHelpButton('listsort', 'smartmenusmenuitemlistsort', 'theme_boost_union');

// Add course name presentation (for the dynamic courses menu item type) as select element.
$displayfieldoptions = [
smartmenu_item::FIELD_FULLNAME => get_string('smartmenusmenuitemdisplayfieldcoursefullname', 'theme_boost_union'),
smartmenu_item::FIELD_SHORTNAME => get_string('smartmenusmenuitemdisplayfieldcourseshortname', 'theme_boost_union'),
];
$displayfieldoptions = smartmenu_item::get_displayfield_options();
$mform->addElement('select', 'displayfield',
get_string('smartmenusmenuitemtypedynamiccourses', 'theme_boost_union').': '.
get_string('smartmenusmenuitemdisplayfield', 'theme_boost_union'), $displayfieldoptions);
Expand Down Expand Up @@ -318,14 +272,7 @@ public function definition() {
$mform->addHelpButton('image', 'smartmenusmenuitemcardimage', 'theme_boost_union');

// Add card text position as select element.
$textpositionoptions = [
smartmenu_item::POSITION_BELOW =>
get_string('smartmenusmenuitemtextpositionbelowimage', 'theme_boost_union'),
smartmenu_item::POSITION_OVERLAYTOP =>
get_string('smartmenusmenuitemtextpositionoverlaytop', 'theme_boost_union'),
smartmenu_item::POSITION_OVERLAYBOTTOM =>
get_string('smartmenusmenuitemtextpositionoverlaybottom', 'theme_boost_union'),
];
$textpositionoptions = smartmenu_item::get_textposition_options();
$mform->addElement('select', 'textposition',
get_string('smartmenusmenuitemtextposition', 'theme_boost_union'), $textpositionoptions);
$mform->setDefault('textposition', smartmenu_item::POSITION_BELOW);
Expand Down Expand Up @@ -368,10 +315,7 @@ public function definition() {
$mform->addHelpButton('roles', 'smartmenusbyrole', 'theme_boost_union');

// Add context as select element.
$rolecontext = [
smartmenu::ANYCONTEXT => get_string('any'),
smartmenu::SYSTEMCONTEXT => get_string('coresystem'),
];
$rolecontext = smartmenu::get_rolecontext_options();
$mform->addElement('select', 'rolecontext', get_string('smartmenusrolecontext', 'theme_boost_union'), $rolecontext);
$mform->setDefault('rolecontext', smartmenu::ANYCONTEXT);
$mform->setType('rolecontext', PARAM_INT);
Expand Down Expand Up @@ -418,10 +362,7 @@ public function definition() {
$mform->addHelpButton('cohorts', 'smartmenusbycohort', 'theme_boost_union');

// Add operator as select element.
$operatoroptions = [
smartmenu::ANY => get_string('any'),
smartmenu::ALL => get_string('all'),
];
$operatoroptions = smartmenu::get_operator_options();
$mform->addElement('select', 'operator', get_string('smartmenusoperator', 'theme_boost_union'), $operatoroptions);
$mform->setDefault('operator', smartmenu::ANY);
$mform->setType('operator', PARAM_INT);
Expand Down
Loading

0 comments on commit 62b8670

Please sign in to comment.