Skip to content

Commit

Permalink
MDL-52081 forms: Use __construct() for constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Dec 10, 2015
1 parent 0dfcc25 commit 1a0df55
Show file tree
Hide file tree
Showing 83 changed files with 1,014 additions and 208 deletions.
2 changes: 1 addition & 1 deletion blocks/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function __construct($actionurl, $block, $page) {
global $CFG;
$this->block = $block;
$this->page = $page;
parent::moodleform($actionurl);
parent::__construct($actionurl);
}

function definition() {
Expand Down
2 changes: 1 addition & 1 deletion blocks/rss_client/editfeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class feed_edit_form extends moodleform {
function __construct($actionurl, $isadding, $caneditshared) {
$this->isadding = $isadding;
$this->caneditshared = $caneditshared;
parent::moodleform($actionurl);
parent::__construct($actionurl);
}

function definition() {
Expand Down
14 changes: 12 additions & 2 deletions course/moodleform_mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ abstract class moodleform_mod extends moodleform {
/** @var object The course format of the current course. */
protected $courseformat;

function moodleform_mod($current, $section, $cm, $course) {
public function __construct($current, $section, $cm, $course) {
global $CFG;

$this->current = $current;
Expand All @@ -83,7 +83,17 @@ function moodleform_mod($current, $section, $cm, $course) {
}
$this->_modname = $matches[1];
$this->init_features();
parent::moodleform('modedit.php');
parent::__construct('modedit.php');
}

/**
* Old syntax of class constructor. Deprecated in PHP7.
*
* @deprecated since Moodle 3.1
*/
public function moodleform_mod($current, $section, $cm, $course) {
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
self::__construct($current, $section, $cm, $course);
}

protected function init_features() {
Expand Down
2 changes: 1 addition & 1 deletion filter/local_settings_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class filter_local_settings_form extends moodleform {
public function __construct($submiturl, $filter, $context) {
$this->filter = $filter;
$this->context = $context;
parent::moodleform($submiturl);
parent::__construct($submiturl);
}

/**
Expand Down
12 changes: 11 additions & 1 deletion grade/grading/form/guide/guideeditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,18 @@ class moodlequickform_guideeditor extends HTML_QuickForm_input {
* @param string $elementlabel
* @param array $attributes
*/
public function __construct($elementname=null, $elementlabel=null, $attributes=null) {
parent::__construct($elementname, $elementlabel, $attributes);
}

/**
* Old syntax of class constructor. Deprecated in PHP7.
*
* @deprecated since Moodle 3.1
*/
public function moodlequickform_guideeditor($elementname=null, $elementlabel=null, $attributes=null) {
parent::HTML_QuickForm_input($elementname, $elementlabel, $attributes);
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
self::__construct($elementname, $elementlabel, $attributes);
}

/**
Expand Down
14 changes: 12 additions & 2 deletions grade/grading/form/rubric/rubriceditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,18 @@ class MoodleQuickForm_rubriceditor extends HTML_QuickForm_input {
* @param string $elementLabel
* @param array $attributes
*/
function MoodleQuickForm_rubriceditor($elementName=null, $elementLabel=null, $attributes=null) {
parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
public function __construct($elementName=null, $elementLabel=null, $attributes=null) {
parent::__construct($elementName, $elementLabel, $attributes);
}

/**
* Old syntax of class constructor. Deprecated in PHP7.
*
* @deprecated since Moodle 3.1
*/
public function MoodleQuickForm_rubriceditor($elementName=null, $elementLabel=null, $attributes=null) {
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
self::__construct($elementName, $elementLabel, $attributes);
}

/**
Expand Down
14 changes: 12 additions & 2 deletions lib/form/advcheckbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class MoodleQuickForm_advcheckbox extends HTML_QuickForm_advcheckbox{
* or an associative array
* @param mixed $values (optional) Values to pass if checked or not checked
*/
function MoodleQuickForm_advcheckbox($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null)
public function __construct($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null)
{
if ($values === null){
$values = array(0, 1);
Expand All @@ -81,7 +81,17 @@ function MoodleQuickForm_advcheckbox($elementName=null, $elementLabel=null, $tex
}
}

parent::HTML_QuickForm_advcheckbox($elementName, $elementLabel, $text, $attributes, $values);
parent::__construct($elementName, $elementLabel, $text, $attributes, $values);
}

/**
* Old syntax of class constructor. Deprecated in PHP7.
*
* @deprecated since Moodle 3.1
*/
public function MoodleQuickForm_advcheckbox($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null) {
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
self::__construct($elementName, $elementLabel, $text, $attributes, $values);
}

/**
Expand Down
14 changes: 12 additions & 2 deletions lib/form/autocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class MoodleQuickForm_autocomplete extends MoodleQuickForm_select {
* @param mixed $attributes Either a typical HTML attribute string or an associative array. Special options
* "tags", "placeholder", "ajax", "multiple", "casesensitive" are supported.
*/
function MoodleQuickForm_autocomplete($elementName=null, $elementLabel=null, $options=null, $attributes=null) {
public function __construct($elementName=null, $elementLabel=null, $options=null, $attributes=null) {
// Even if the constructor gets called twice we do not really want 2x options (crazy forms!).
$this->_options = array();
if ($attributes === null) {
Expand All @@ -87,11 +87,21 @@ function MoodleQuickForm_autocomplete($elementName=null, $elementLabel=null, $op
$this->casesensitive = $attributes['casesensitive'] ? true : false;
unset($attributes['casesensitive']);
}
parent::HTML_QuickForm_select($elementName, $elementLabel, $options, $attributes);
parent::__construct($elementName, $elementLabel, $options, $attributes);

$this->_type = 'autocomplete';
}

/**
* Old syntax of class constructor. Deprecated in PHP7.
*
* @deprecated since Moodle 3.1
*/
public function MoodleQuickForm_autocomplete($elementName=null, $elementLabel=null, $options=null, $attributes=null) {
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
self::__construct($elementName, $elementLabel, $options, $attributes);
}

/**
* Returns HTML for select form element.
*
Expand Down
14 changes: 12 additions & 2 deletions lib/form/button.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,18 @@ class MoodleQuickForm_button extends HTML_QuickForm_button
* @param mixed $attributes (optional) Either a typical HTML attribute string
* or an associative array
*/
function MoodleQuickForm_button($elementName=null, $value=null, $attributes=null) {
parent::HTML_QuickForm_button($elementName, $value, $attributes);
public function __construct($elementName=null, $value=null, $attributes=null) {
parent::__construct($elementName, $value, $attributes);
}

/**
* Old syntax of class constructor. Deprecated in PHP7.
*
* @deprecated since Moodle 3.1
*/
public function MoodleQuickForm_button($elementName=null, $value=null, $attributes=null) {
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
self::__construct($elementName, $value, $attributes);
}

/**
Expand Down
17 changes: 13 additions & 4 deletions lib/form/cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ class MoodleQuickForm_cancel extends MoodleQuickForm_submit
* @param mixed $attributes (optional) Either a typical HTML attribute string
* or an associative array
*/
function MoodleQuickForm_cancel($elementName=null, $value=null, $attributes=null)
public function __construct($elementName=null, $value=null, $attributes=null)
{
if ($elementName==null){
$elementName='cancel';
}
if ($value==null){
$value=get_string('cancel');
}
MoodleQuickForm_submit::MoodleQuickForm_submit($elementName, $value, $attributes);
parent::__construct($elementName, $value, $attributes);
$this->updateAttributes(array('onclick'=>'skipClientValidation = true; return true;'));

// Add the class btn-cancel.
Expand All @@ -71,6 +71,16 @@ function MoodleQuickForm_cancel($elementName=null, $value=null, $attributes=null
$this->updateAttributes(array('class' => $class . ' btn-cancel'));
}

/**
* Old syntax of class constructor. Deprecated in PHP7.
*
* @deprecated since Moodle 3.1
*/
public function MoodleQuickForm_cancel($elementName=null, $value=null, $attributes=null) {
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
self::__construct($elementName, $value, $attributes);
}

/**
* Called by HTML_QuickForm whenever form event is made on this element
*
Expand All @@ -83,8 +93,7 @@ function onQuickFormEvent($event, $arg, &$caller)
{
switch ($event) {
case 'createElement':
$className = get_class($this);
$this->$className($arg[0], $arg[1], $arg[2]);
static::__construct($arg[0], $arg[1], $arg[2]);
$caller->_registerCancelButton($this->getName());
return true;
break;
Expand Down
14 changes: 12 additions & 2 deletions lib/form/checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,18 @@ class MoodleQuickForm_checkbox extends HTML_QuickForm_checkbox{
* @param mixed $attributes (optional) Either a typical HTML attribute string
* or an associative array
*/
function MoodleQuickForm_checkbox($elementName=null, $elementLabel=null, $text='', $attributes=null) {
parent::HTML_QuickForm_checkbox($elementName, $elementLabel, $text, $attributes);
public function __construct($elementName=null, $elementLabel=null, $text='', $attributes=null) {
parent::__construct($elementName, $elementLabel, $text, $attributes);
}

/**
* Old syntax of class constructor. Deprecated in PHP7.
*
* @deprecated since Moodle 3.1
*/
public function MoodleQuickForm_checkbox($elementName=null, $elementLabel=null, $text='', $attributes=null) {
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
self::__construct($elementName, $elementLabel, $text, $attributes);
}

/**
Expand Down
14 changes: 12 additions & 2 deletions lib/form/dateselector.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ class MoodleQuickForm_date_selector extends MoodleQuickForm_group {
* @param array $options Options to control the element's display
* @param mixed $attributes Either a typical HTML attribute string or an associative array
*/
function MoodleQuickForm_date_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) {
public function __construct($elementName = null, $elementLabel = null, $options = array(), $attributes = null) {
// Get the calendar type used - see MDL-18375.
$calendartype = \core_calendar\type_factory::get_calendar_instance();
$this->_options = array('startyear' => $calendartype->get_min_year(), 'stopyear' => $calendartype->get_max_year(),
'defaulttime' => 0, 'timezone' => 99, 'step' => 5, 'optional' => false);
$this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
HTML_QuickForm_element::__construct($elementName, $elementLabel, $attributes);
$this->_persistantFreeze = true;
$this->_appendName = true;
$this->_type = 'date_selector';
Expand All @@ -103,6 +103,16 @@ function MoodleQuickForm_date_selector($elementName = null, $elementLabel = null
}
}

/**
* Old syntax of class constructor. Deprecated in PHP7.
*
* @deprecated since Moodle 3.1
*/
public function MoodleQuickForm_date_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) {
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
self::__construct($elementName, $elementLabel, $options, $attributes);
}

/**
* This will create date group element constisting of day, month and year.
*
Expand Down
14 changes: 12 additions & 2 deletions lib/form/datetimeselector.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group {
* @param array $options Options to control the element's display
* @param mixed $attributes Either a typical HTML attribute string or an associative array
*/
function MoodleQuickForm_date_time_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) {
public function __construct($elementName = null, $elementLabel = null, $options = array(), $attributes = null) {
// Get the calendar type used - see MDL-18375.
$calendartype = \core_calendar\type_factory::get_calendar_instance();
$this->_options = array('startyear' => $calendartype->get_min_year(), 'stopyear' => $calendartype->get_max_year(),
'defaulttime' => 0, 'timezone' => 99, 'step' => 5, 'optional' => false);

$this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
HTML_QuickForm_element::__construct($elementName, $elementLabel, $attributes);
$this->_persistantFreeze = true;
$this->_appendName = true;
$this->_type = 'date_time_selector';
Expand All @@ -106,6 +106,16 @@ function MoodleQuickForm_date_time_selector($elementName = null, $elementLabel =
}
}

/**
* Old syntax of class constructor. Deprecated in PHP7.
*
* @deprecated since Moodle 3.1
*/
public function MoodleQuickForm_date_time_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) {
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
self::__construct($elementName, $elementLabel, $options, $attributes);
}

/**
* This will create date group element constisting of day, month and year.
*
Expand Down
14 changes: 12 additions & 2 deletions lib/form/duration.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class MoodleQuickForm_duration extends MoodleQuickForm_group {
* If not specified, minutes is used.
* @param mixed $attributes Either a typical HTML attribute string or an associative array
*/
function MoodleQuickForm_duration($elementName = null, $elementLabel = null, $options = array(), $attributes = null) {
$this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
public function __construct($elementName = null, $elementLabel = null, $options = array(), $attributes = null) {
HTML_QuickForm_element::__construct($elementName, $elementLabel, $attributes);
$this->_persistantFreeze = true;
$this->_appendName = true;
$this->_type = 'duration';
Expand All @@ -83,6 +83,16 @@ function MoodleQuickForm_duration($elementName = null, $elementLabel = null, $op
}
}

/**
* Old syntax of class constructor. Deprecated in PHP7.
*
* @deprecated since Moodle 3.1
*/
public function MoodleQuickForm_duration($elementName = null, $elementLabel = null, $options = array(), $attributes = null) {
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
self::__construct($elementName, $elementLabel, $options, $attributes);
}

/**
* Returns time associative array of unit length.
*
Expand Down
14 changes: 12 additions & 2 deletions lib/form/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
* or an associative array
* @param array $options set of options to initalize filepicker
*/
function MoodleQuickForm_editor($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
public function __construct($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
global $CFG, $PAGE;

$options = (array)$options;
Expand All @@ -89,14 +89,24 @@ function MoodleQuickForm_editor($elementName=null, $elementLabel=null, $attribut
}
}
$this->_options['trusted'] = trusttext_trusted($this->_options['context']);
parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
parent::__construct($elementName, $elementLabel, $attributes);

// Note: for some reason the code using this setting does not like bools.
$this->_options['subdirs'] = (int)($this->_options['subdirs'] == 1);

editors_head_setup();
}

/**
* Old syntax of class constructor. Deprecated in PHP7.
*
* @deprecated since Moodle 3.1
*/
public function MoodleQuickForm_editor($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
self::__construct($elementName, $elementLabel, $attributes, $options);
}

/**
* Called by HTML_QuickForm whenever form event is made on this element
*
Expand Down
14 changes: 12 additions & 2 deletions lib/form/filemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
* or an associative array
* @param array $options set of options to initalize filemanager
*/
function MoodleQuickForm_filemanager($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
public function __construct($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
global $CFG, $PAGE;

$options = (array)$options;
Expand All @@ -76,7 +76,17 @@ function MoodleQuickForm_filemanager($elementName=null, $elementLabel=null, $att
$this->_options['return_types'] = (FILE_INTERNAL | FILE_REFERENCE);
}
$this->_type = 'filemanager';
parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
parent::__construct($elementName, $elementLabel, $attributes);
}

/**
* Old syntax of class constructor. Deprecated in PHP7.
*
* @deprecated since Moodle 3.1
*/
public function MoodleQuickForm_filemanager($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
self::__construct($elementName, $elementLabel, $attributes, $options);
}

/**
Expand Down
Loading

0 comments on commit 1a0df55

Please sign in to comment.