Skip to content
Permalink
Browse files

MDL-55417 forms: Clean up form element template patch

Use a trait and a base mustache template for all form elements to reduce code
duplication and increase standardisation.

Part of MDL-55071
  • Loading branch information...
damyon authored and danpoltawski committed Aug 11, 2016
1 parent 91bda4c commit 344321e1ef968aa1f41a78d6e04eb5b84f04e407
Showing with 483 additions and 748 deletions.
  1. +4 −10 lib/form/advcheckbox.php
  2. +2 −9 lib/form/button.php
  3. +3 −10 lib/form/checkbox.php
  4. +6 −6 lib/form/editor.php
  5. +6 −6 lib/form/filemanager.php
  6. +5 −6 lib/form/filepicker.php
  7. +8 −2 lib/form/grading.php
  8. +8 −6 lib/form/group.php
  9. +3 −10 lib/form/password.php
  10. +4 −2 lib/form/radio.php
  11. +5 −6 lib/form/recaptcha.php
  12. +7 −11 lib/form/select.php
  13. +6 −11 lib/form/selectgroups.php
  14. +6 −6 lib/form/static.php
  15. +6 −6 lib/form/submit.php
  16. +80 −0 lib/form/templatable_form_element.php
  17. +2 −10 lib/form/text.php
  18. +3 −11 lib/form/textarea.php
  19. +7 −7 lib/form/url.php
  20. +12 −1 lib/form/warning.php
  21. +0 −18 theme/noname/scss/moodle/buttons.scss
  22. +5 −36 theme/noname/templates/core_form/element-autocomplete.mustache
  23. +10 −6 theme/noname/templates/core_form/element-button-inline.mustache
  24. +6 −8 theme/noname/templates/core_form/element-button.mustache
  25. +2 −1 theme/noname/templates/core_form/element-checkbox-inline.mustache
  26. +1 −1 theme/noname/templates/core_form/element-checkbox.mustache
  27. +6 −7 theme/noname/templates/core_form/element-date_selector.mustache
  28. +9 −0 theme/noname/templates/core_form/element-date_time_selector-inline.mustache
  29. +6 −10 theme/noname/templates/core_form/element-date_time_selector.mustache
  30. +1 −0 theme/noname/templates/core_form/element-duration-inline.mustache
  31. +4 −32 theme/noname/templates/core_form/element-editor.mustache
  32. +4 −32 theme/noname/templates/core_form/element-filemanager.mustache
  33. +4 −32 theme/noname/templates/core_form/element-filepicker.mustache
  34. +5 −33 theme/noname/templates/core_form/element-grading.mustache
  35. +7 −0 theme/noname/templates/core_form/element-group-inline.mustache
  36. +4 −7 theme/noname/templates/core_form/element-group.mustache
  37. +5 −31 theme/noname/templates/core_form/element-password.mustache
  38. +33 −0 theme/noname/templates/core_form/element-radio-inline.mustache
  39. +36 −0 theme/noname/templates/core_form/element-radio.mustache
  40. +4 −32 theme/noname/templates/core_form/element-recaptcha.mustache
  41. +5 −33 theme/noname/templates/core_form/element-select-inline.mustache
  42. +5 −36 theme/noname/templates/core_form/element-select.mustache
  43. +5 −33 theme/noname/templates/core_form/element-selectgroups-inline.mustache
  44. +5 −36 theme/noname/templates/core_form/element-selectgroups.mustache
  45. +4 −32 theme/noname/templates/core_form/element-static.mustache
  46. +10 −7 theme/noname/templates/core_form/element-submit-inline.mustache
  47. +10 −9 theme/noname/templates/core_form/element-submit.mustache
  48. +33 −0 theme/noname/templates/core_form/element-template-inline.mustache
  49. +35 −0 theme/noname/templates/core_form/element-template.mustache
  50. +6 −31 theme/noname/templates/core_form/element-text-inline.mustache
  51. +6 −33 theme/noname/templates/core_form/element-text.mustache
  52. +13 −33 theme/noname/templates/core_form/element-textarea.mustache
  53. +6 −33 theme/noname/templates/core_form/element-url.mustache
  54. +5 −10 theme/noname/templates/core_form/element-warning.mustache
@@ -26,7 +26,7 @@
*/
require_once('HTML/QuickForm/advcheckbox.php');
require_once(__DIR__ . '/../outputcomponents.php');
require_once('templatable_form_element.php');
/**
* HTML class for an advcheckbox type element
@@ -40,6 +40,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_advcheckbox extends HTML_QuickForm_advcheckbox implements templatable {
use templatable_form_element;
/** @var string html for help button, if empty then no help will icon will be dispalyed. */
var $_helpbutton='';
@@ -131,13 +134,4 @@ function getFrozenHtml()
}
return $output;
}
public function export_for_template(renderer_base $output) {
$context = [];
$context['frozen'] = $this->_flagFrozen;
foreach ($this->getAttributes() as $name => $value) {
$context[$name] = $value;
}
return $context;
}
}
@@ -40,6 +40,8 @@
*/
class MoodleQuickForm_button extends HTML_QuickForm_button implements templatable
{
use templatable_form_element;
/** @var string html for help button, if empty then no help */
var $_helpbutton='';
@@ -86,13 +88,4 @@ function getElementTemplateType(){
return 'default';
}
}
public function export_for_template(renderer_base $output) {
$context = [];
$context['frozen'] = $this->_flagFrozen;
foreach ($this->getAttributes() as $name => $value) {
$context[$name] = $value;
}
return $context;
}
}
@@ -26,7 +26,7 @@
*/
require_once('HTML/QuickForm/checkbox.php');
require_once(__DIR__ . '/../outputcomponents.php');
require_once('templatable_form_element.php');
/**
* HTML class for a checkbox type element
@@ -41,6 +41,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_checkbox extends HTML_QuickForm_checkbox implements templatable {
use templatable_form_element;
/** @var string html for help button, if empty then no help */
var $_helpbutton='';
@@ -139,13 +141,4 @@ function getFrozenHtml()
}
return $output;
}
public function export_for_template(renderer_base $output) {
$context = [];
$context['frozen'] = $this->_flagFrozen;
foreach ($this->getAttributes() as $name => $value) {
$context[$name] = $value;
}
return $context;
}
}
@@ -30,7 +30,7 @@
require_once('HTML/QuickForm/element.php');
require_once($CFG->dirroot.'/lib/filelib.php');
require_once($CFG->dirroot.'/repository/lib.php');
require_once($CFG->libdir.'/outputcomponents.php');
require_once('templatable_form_element.php');
/**
* Editor element
@@ -45,6 +45,10 @@
* @todo MDL-29426 ajax format conversion
*/
class MoodleQuickForm_editor extends HTML_QuickForm_element implements templatable {
use templatable_form_element {
export_for_template as export_for_template_base;
}
/** @var string html for help button, if empty then no help will icon will be dispalyed. */
public $_helpbutton = '';
@@ -451,11 +455,7 @@ function toHtml() {
}
public function export_for_template(renderer_base $output) {
$context = [];
$context['frozen'] = $this->_flagFrozen;
foreach ($this->getAttributes() as $name => $value) {
$context[$name] = $value;
}
$context = $this->export_for_template_base($output);
$context['html'] = $this->toHtml();
return $context;
}
@@ -30,7 +30,7 @@
require_once('HTML/QuickForm/element.php');
require_once($CFG->dirroot.'/lib/filelib.php');
require_once($CFG->dirroot.'/repository/lib.php');
require_once($CFG->libdir.'/outputcomponents.php');
require_once('templatable_form_element.php');
/**
* Filemanager form element
@@ -42,6 +42,10 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_filemanager extends HTML_QuickForm_element implements templatable {
use templatable_form_element {
export_for_template as export_for_template_base;
}
/** @var string html for help button, if empty then no help will icon will be dispalyed. */
public $_helpbutton = '';
@@ -300,11 +304,7 @@ function toHtml() {
}
public function export_for_template(renderer_base $output) {
$context = [];
$context['frozen'] = $this->_flagFrozen;
foreach ($this->getAttributes() as $name => $value) {
$context[$name] = $value;
}
$context = $this->export_for_template_base($output);
$context['html'] = $this->toHtml();
return $context;
}
@@ -29,7 +29,7 @@
require_once("HTML/QuickForm/button.php");
require_once($CFG->dirroot.'/repository/lib.php');
require_once($CFG->libdir.'/outputcomponents.php');
require_once('templatable_form_element.php');
/**
* Filepicker form element
@@ -42,6 +42,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_filepicker extends HTML_QuickForm_input implements templatable {
use templatable_form_element {
export_for_template as export_for_template_base;
}
/** @var string html for help button, if empty then no help will icon will be dispalyed. */
public $_helpbutton = '';
@@ -223,11 +226,7 @@ function exportValue(&$submitValues, $assoc = false) {
}
public function export_for_template(renderer_base $output) {
$context = [];
$context['frozen'] = $this->_flagFrozen;
foreach ($this->getAttributes() as $name => $value) {
$context[$name] = $value;
}
$context = $this->export_for_template_base($output);
$context['html'] = $this->toHtml();
return $context;
}
@@ -28,7 +28,7 @@
global $CFG;
require_once("HTML/QuickForm/element.php");
require_once($CFG->dirroot.'/grade/grading/form/lib.php');
require_once($CFG->libdir.'/outputcomponents.php');
require_once('templatable_form_element.php');
if (class_exists('HTML_QuickForm')) {
HTML_QuickForm::registerRule('gradingvalidated', 'callback', '_validate', 'MoodleQuickForm_grading');
@@ -49,6 +49,10 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_grading extends HTML_QuickForm_input implements templatable {
use templatable_form_element {
export_for_template as export_for_template_base;
}
/** @var string html for help button, if empty then no help */
var $_helpbutton='';
@@ -162,6 +166,8 @@ public static function _validate($elementvalue, $attributes = null) {
}
public function export_for_template(renderer_base $output) {
return $this->toHtml();
$context = $this->export_for_template_base($output);
$context['html'] = $this->toHtml();
return $context;
}
}
@@ -26,7 +26,7 @@
*/
require_once("HTML/QuickForm/group.php");
require_once(__DIR__ . '/../outputcomponents.php');
require_once('templatable_form_element.php');
/**
* HTML class for a form element group
@@ -39,6 +39,10 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_group extends HTML_QuickForm_group implements templatable {
use templatable_form_element {
export_for_template as export_for_template_base;
}
/** @var string html for help button, if empty then no help */
var $_helpbutton='';
@@ -153,15 +157,13 @@ public function createFormElement() {
public function export_for_template(renderer_base $output) {
global $OUTPUT;
$context = $this->export_for_template_base($output);
$this->_renderedfromtemplate = true;
include_once('HTML/QuickForm/Renderer/Default.php');
$context = [];
$context['frozen'] = $this->_flagFrozen;
foreach ($this->getAttributes() as $name => $value) {
$context[$name] = $value;
}
$elements = [];
foreach ($this->_elements as $key => $element) {
$element->_generateId();
@@ -26,7 +26,7 @@
*/
require_once('HTML/QuickForm/password.php');
require_once(__DIR__ . '/../outputcomponents.php');
require_once('templatable_form_element.php');
/**
* Password type form element
@@ -39,6 +39,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_password extends HTML_QuickForm_password implements templatable {
use templatable_form_element;
/** @var string, html for help button, if empty then no help */
var $_helpbutton='';
@@ -84,13 +86,4 @@ public function MoodleQuickForm_password($elementName=null, $elementLabel=null,
function getHelpButton(){
return $this->_helpbutton;
}
public function export_for_template(renderer_base $output) {
$context = [];
$context['frozen'] = $this->_flagFrozen;
foreach ($this->getAttributes() as $name => $value) {
$context[$name] = $value;
}
return $context;
}
}
@@ -26,7 +26,7 @@
*/
require_once('HTML/QuickForm/radio.php');
require_once('templatable_form_element.php');
/**
* radio type form element
*
@@ -37,7 +37,9 @@
* @copyright 2006 Jamie Pratt <me@jamiep.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_radio extends HTML_QuickForm_radio{
class MoodleQuickForm_radio extends HTML_QuickForm_radio implements templatable {
use templatable_form_element;
/** @var string html for help button, if empty then no help */
var $_helpbutton='';
@@ -26,7 +26,7 @@
*/
require_once('HTML/QuickForm/input.php');
require_once(__DIR__ . '/../outputcomponents.php');
require_once('templatable_form_element.php');
/**
* recaptcha type form element
@@ -39,6 +39,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_recaptcha extends HTML_QuickForm_input implements templatable {
use templatable_form_element {
export_for_template as export_for_template_base;
}
/** @var string html for help button, if empty then no help */
var $_helpbutton='';
@@ -155,11 +158,7 @@ function verify($challenge_field, $response_field) {
}
public function export_for_template(renderer_base $output) {
$context = [];
$context['frozen'] = $this->_flagFrozen;
foreach ($this->getAttributes() as $name => $value) {
$context[$name] = $value;
}
$context = $this->export_for_template_base($output);
$context['html'] = $this->toHtml();
return $context;
}
@@ -26,7 +26,7 @@
*/
require_once('HTML/QuickForm/select.php');
require_once(__DIR__ . '/../outputcomponents.php');
require_once('templatable_form_element.php');
/**
* select type form element
@@ -39,6 +39,11 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_select extends HTML_QuickForm_select implements templatable {
use templatable_form_element {
export_for_template as export_for_template_base;
}
/** @var string html for help button, if empty then no help */
var $_helpbutton='';
@@ -192,15 +197,7 @@ function exportValue(&$submitValues, $assoc = false)
}
public function export_for_template(renderer_base $output) {
$context = [];
$context['frozen'] = $this->_flagFrozen;
$context['attributes'] = [];
foreach ($this->getAttributes() as $name => $value) {
$context[$name] = $value;
if (!in_array($name, ['id', 'name', 'multiple'])) {
$context['attributes'][] = ['name' => $name, 'value' => $value];
}
}
$context = $this->export_for_template_base($output);
$options = [];
foreach ($this->_options as $option) {
@@ -215,7 +212,6 @@ public function export_for_template(renderer_base $output) {
$options[] = $o;
}
$context['options'] = $options;
$context['hideLabel'] = $this->_hiddenLabel;
return $context;
}

0 comments on commit 344321e

Please sign in to comment.
You can’t perform that action at this time.