-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvement: Add field controllers for text and textarea and return t…
…ext controller as fallback. #774
- Loading branch information
1 parent
7f44e71
commit 60ff811
Showing
3 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
classes/local/customfield/field/text/wbt_field_controller.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Extension of the customfield field controller for Wunderbyte table. | ||
* | ||
* @package local_wunderbyte_table | ||
* @copyright 2024 Wunderbyte GmbH <[email protected]> | ||
* @author Bernhard Fischer-Sengseis | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace local_wunderbyte_table\local\customfield\field\text; | ||
|
||
// Important: Use the field controller for the right customfield. | ||
use customfield_text\field_controller; | ||
use local_wunderbyte_table\local\customfield\wbt_field_controller_base; | ||
|
||
/** | ||
* Extension of the customfield field controller for Wunderbyte table. | ||
* | ||
* @package local_wunderbyte_table | ||
* @copyright 2024 Wunderbyte GmbH <[email protected]> | ||
* @author Bernhard Fischer-Sengseis | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class wbt_field_controller extends field_controller implements wbt_field_controller_base { | ||
|
||
/** | ||
* Get the actual string value of the customfield. | ||
* | ||
* @param string $key | ||
* @return string the string value | ||
*/ | ||
public function get_option_value_by_key(string $key): string { | ||
global $DB; | ||
|
||
if (!empty($key)) { | ||
// For normal text fields we need format_string. | ||
return format_string($key); | ||
} | ||
return ''; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
classes/local/customfield/field/textarea/wbt_field_controller.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Extension of the customfield field controller for Wunderbyte table. | ||
* | ||
* @package local_wunderbyte_table | ||
* @copyright 2024 Wunderbyte GmbH <[email protected]> | ||
* @author Bernhard Fischer-Sengseis | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace local_wunderbyte_table\local\customfield\field\textarea; | ||
|
||
// Important: Use the field controller for the right customfield. | ||
use customfield_textarea\field_controller; | ||
use local_wunderbyte_table\local\customfield\wbt_field_controller_base; | ||
|
||
/** | ||
* Extension of the customfield field controller for Wunderbyte table. | ||
* | ||
* @package local_wunderbyte_table | ||
* @copyright 2024 Wunderbyte GmbH <[email protected]> | ||
* @author Bernhard Fischer-Sengseis | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class wbt_field_controller extends field_controller implements wbt_field_controller_base { | ||
|
||
/** | ||
* Get the actual string value of the customfield. | ||
* | ||
* @param string $key | ||
* @return string the string value | ||
*/ | ||
public function get_option_value_by_key(string $key): string { | ||
global $DB; | ||
|
||
if (!empty($key)) { | ||
// For textarea we need format_text. | ||
return format_text($key); | ||
} | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters