From db49be139d337f1e4fdd5d6d394b1c35881c7310 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Mon, 17 Aug 2009 07:00:16 +0000 Subject: [PATCH] MDL-19756 Added the component::has_action() method for quickly detecting if a component has an action of a given type, and unmuted debugging messages for old output functions that have been upgraded in HEAD --- lib/deprecatedlib.php | 41 +++++++++++++++++++++++----------------- lib/outputcomponents.php | 14 ++++++++++++++ lib/outputrenderers.php | 5 +++++ 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 4b08d911ff..4d5e3a1e87 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -1865,6 +1865,7 @@ function skip_main_destination() { */ function print_headline($text, $size=2, $return=false) { global $OUTPUT; + debugging('print_headline() has been deprecated. Please change your code to use $OUTPUT->heading().'); $output = $OUTPUT->heading($text, $size); if ($return) { return $output; @@ -1887,6 +1888,7 @@ function print_headline($text, $size=2, $return=false) { */ function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') { global $OUTPUT; + debugging('print_heading() has been deprecated. Please change your code to use $OUTPUT->heading().'); if (!empty($deprecated)) { debugging('Use of deprecated align attribute of print_heading. ' . 'Please do not specify styling in PHP code like that.', DEBUG_DEVELOPER); @@ -1910,6 +1912,7 @@ function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $ret */ function print_heading_block($heading, $class='', $return=false) { global $OUTPUT; + debugging('print_heading_with_block() has been deprecated. Please change your code to use $OUTPUT->heading().'); $output = $OUTPUT->heading($heading, 2, 'headingblock header ' . moodle_renderer_base::prepare_classes($class)); if ($return) { return $output; @@ -1931,6 +1934,7 @@ function print_heading_block($heading, $class='', $return=false) { */ function print_box($message, $classes='generalbox', $ids='', $return=false) { global $OUTPUT; + debugging('print_box() has been deprecated. Please change your code to use $OUTPUT->box().'); $output = $OUTPUT->box($message, $classes, $ids); if ($return) { return $output; @@ -1951,6 +1955,7 @@ function print_box($message, $classes='generalbox', $ids='', $return=false) { */ function print_box_start($classes='generalbox', $ids='', $return=false) { global $OUTPUT; + debugging('print_box_start() has been deprecated. Please change your code to use $OUTPUT->box_start().'); $output = $OUTPUT->box_start($classes, $ids); if ($return) { return $output; @@ -1969,6 +1974,7 @@ function print_box_start($classes='generalbox', $ids='', $return=false) { */ function print_box_end($return=false) { global $OUTPUT; + debugging('print_box_end() has been deprecated. Please change your code to use $OUTPUT->box_end().'); $output = $OUTPUT->box_end(); if ($return) { return $output; @@ -2159,6 +2165,7 @@ function print_header($title='', $heading='', $navigation='', $focus='', function print_footer($course = NULL, $usercourse = NULL, $return = false) { global $PAGE, $OUTPUT; + debugging('print_footer() has been deprecated. Please change your code to use $OUTPUT->footer().'); // TODO check arguments. if (is_string($course)) { debugging("Magic values like 'home', 'empty' passed to print_footer no longer have any effect. " . @@ -2440,7 +2447,7 @@ function link_to_popup_window ($url, $name=null, $linkname=null, $options=null, $return=false) { global $OUTPUT; - // debugging('link_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->link_to_popup().'); + // debugging('link_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->link().'); if ($options == 'none') { $options = null; @@ -2476,7 +2483,7 @@ function link_to_popup_window ($url, $name=null, $linkname=null, $link->add_action($popupaction); // Call the output method - $output = $OUTPUT->link_to_popup($link); + $output = $OUTPUT->link($link); if ($return) { return $output; @@ -2508,7 +2515,7 @@ function button_to_popup_window ($url, $name=null, $linkname=null, $id=null, $class=null) { global $OUTPUT; - // debugging('link_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->link_to_popup().'); + debugging('link_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->link_to_popup().'); if ($options == 'none') { $options = null; @@ -2620,7 +2627,7 @@ function print_single_button($link, $options, $label='OK', $method='get', $notus function print_spacer($height=1, $width=1, $br=true, $return=false) { global $CFG, $OUTPUT; - // debugging('print_spacer() has been deprecated. Please change your code to use $OUTPUT->spacer().'); + debugging('print_spacer() has been deprecated. Please change your code to use $OUTPUT->spacer().'); $spacer = new html_image(); $spacer->height = $height; @@ -2733,7 +2740,7 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v /// $width and height are legacy fields and no longer used as pixels like they used to be. /// However, you can set them to zero to override the mincols and minrows values below. - // debugging('print_textarea() has been deprecated. Please change your code to use $OUTPUT->textarea().'); + debugging('print_textarea() has been deprecated. Please change your code to use $OUTPUT->textarea().'); global $CFG; @@ -2901,7 +2908,7 @@ function print_arrow($direction='up', $strsort=null, $return=false) { function doc_link($path='', $text='', $iconpath='') { global $CFG, $OUTPUT; - // debugging('doc_link() has been deprecated. Please change your code to use $OUTPUT->doc_link().'); + debugging('doc_link() has been deprecated. Please change your code to use $OUTPUT->doc_link().'); if (empty($CFG->docroot)) { return ''; @@ -2928,7 +2935,7 @@ function doc_link($path='', $text='', $iconpath='') { function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) { global $OUTPUT; - // debugging('print_paging_bar() has been deprecated. Please change your code to use $OUTPUT->paging_bar($pagingbar).'); + debugging('print_paging_bar() has been deprecated. Please change your code to use $OUTPUT->paging_bar($pagingbar).'); $pagingbar = moodle_paging_bar::make($totalcount, $page, $perpage, $baseurl); $pagingbar->pagevar = $pagevar; @@ -3066,7 +3073,7 @@ function choose_from_menu ($options, $name, $selected='', $nothing='choose', $sc * @return string|void If $return=true returns string, else echo's and returns void */ function choose_from_menu_yesno($name, $selected, $script = '', $return = false, $disabled = false, $tabindex = 0) { - // debugging('choose_from_menu_yesno() has been deprecated. Please change your code to use $OUTPUT->select($select).'); + debugging('choose_from_menu_yesno() has been deprecated. Please change your code to use $OUTPUT->select($select).'); global $OUTPUT; if ($script) { @@ -3113,7 +3120,7 @@ function choose_from_menu_yesno($name, $selected, $script = '', $return = false, function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '', $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) { - // debugging('choose_from_menu_nested() has been deprecated. Please change your code to use $OUTPUT->select($select).'); + debugging('choose_from_menu_nested() has been deprecated. Please change your code to use $OUTPUT->select($select).'); global $OUTPUT; if ($script) { @@ -3195,7 +3202,7 @@ function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $ * @return string|bool Depending on value of $return */ function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) { - // debugging('print_time_selector() has been deprecated. Please change your code to use $OUTPUT->select($timeselector).'); + debugging('print_time_selector() has been deprecated. Please change your code to use $OUTPUT->select($timeselector).'); global $OUTPUT; $hourselector = html_select::make_time_selector('hours', $hour, $currenttime); $minuteselector = html_select::make_time_selector('minutes', $minute, $currenttime, $step); @@ -3223,7 +3230,7 @@ function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=fa */ function print_date_selector($day, $month, $year, $currenttime=0, $return=false) { - // debugging('print_date_selector() has been deprecated. Please change your code to use $OUTPUT->select($dateselector).'); + debugging('print_date_selector() has been deprecated. Please change your code to use $OUTPUT->select($dateselector).'); global $OUTPUT; $dayselector = html_select::make_time_selector('days', $day, $currenttime); @@ -3271,7 +3278,7 @@ function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose' $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) { global $OUTPUT; - // debugging('popup_form() has been deprecated. Please change your code to use $OUTPUT->select($select).'); + debugging('popup_form() has been deprecated. Please change your code to use $OUTPUT->select($select).'); if (empty($options)) { return ''; @@ -3328,7 +3335,7 @@ function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose' function close_window_button($name='closewindow', $return=false, $reloadopener = false) { global $OUTPUT; - // debugging('close_window_button() has been deprecated. Please change your code to use $OUTPUT->close_window_button().'); + debugging('close_window_button() has been deprecated. Please change your code to use $OUTPUT->close_window_button().'); $output = $OUTPUT->close_window_button(get_string($name)); if ($return) { @@ -3353,7 +3360,7 @@ function close_window_button($name='closewindow', $return=false, $reloadopener = */ function choose_from_radio ($options, $name, $checked='', $return=false) { - // debugging('choose_from_radio() has been deprecated. Please change your code to use $OUTPUT->select($select).'); + debugging('choose_from_radio() has been deprecated. Please change your code to use $OUTPUT->select($select).'); global $OUTPUT; $select = html_select::make($options, $name, $checked); @@ -3454,7 +3461,7 @@ function print_textfield ($name, $value, $alt = '',$size=50,$maxlength=0, $retur */ function print_heading_with_help($text, $helppage, $module='moodle', $icon=false, $return=false) { - // debugging('print_heading_with_help() has been deprecated. Please change your code to use $OUTPUT->textfield($field).'); + debugging('print_heading_with_help() has been deprecated. Please change your code to use $OUTPUT->textfield($field).'); global $OUTPUT; @@ -3493,7 +3500,7 @@ function update_mymoodle_icon() { * @return string */ function update_tag_button($tagid) { - // debugging('update_tag_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).'); + debugging('update_tag_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).'); return $OUTPUT->edit_button(new moodle_url($CFG->wwwroot.'/tag/index.php', array('id' => $tagid))); } @@ -3558,7 +3565,7 @@ function print_user($user, $course, $messageselect=false, $return=false) { function update_course_icon($courseid) { global $CFG, $OUTPUT; - // debugging('update_course_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).'); + debugging('update_course_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).'); return $OUTPUT->edit_button(new moodle_url($CFG->wwwroot.'/course/view.php', array('id' => $courseid))); } diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index e2178809aa..95f64dba03 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -196,6 +196,20 @@ class moodle_html_component { public function add_confirm_action($message) { $this->add_action(new component_action('click', 'confirm_dialog', array('message' => $message))); } + + /** + * Returns true if this component has an action of the requested type (component_action by default). + * @param string $class The class of the action we are looking for + * @return boolean True if action is found + */ + public function has_action($class='component_action') { + foreach ($this->actions as $action) { + if (get_class($action) == $class) { + return true; + } + } + return false; + } } class labelled_html_component extends moodle_html_component { diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 8b38648a46..322f0ef966 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -1061,6 +1061,11 @@ class moodle_core_renderer extends moodle_renderer_base { if (is_a($link, 'html_link')) { $link = clone($link); + + if ($link->has_action('popup_action')) { + return $this->link_to_popup($link); + } + $link->prepare(); $this->prepare_event_handlers($link); $attributes['href'] = prepare_url($link->url); -- 2.39.5