���ѧۧݧ�ӧ�� �ާ֧ߧ֧էا֧� - ���֧էѧܧ�ڧ��ӧѧ�� - /home3/cpr76684/public_html/textarea.tar
���ѧ٧ѧ�
tests/behat/field.feature 0000644 00000004115 15152206241 0011430 0 ustar 00 @customfield @customfield_textarea @javascript Feature: Managers can manage course custom fields textarea In order to have additional data on the course As a manager I need to create, edit, remove and sort custom fields Background: Given the following "custom field categories" exist: | name | component | area | itemid | | Category for test | core_course | course | 0 | And I log in as "admin" And I navigate to "Courses > Course custom fields" in site administration Scenario: Create a custom course textarea field When I click on "Add a new custom field" "link" And I click on "Text area" "link" And I set the following fields to these values: | Name | Test field | | Short name | testfield | And I click on "Save changes" "button" in the "Adding a new Text area" "dialogue" Then I should see "Test field" And I log out Scenario: Edit a custom course textarea field When I click on "Add a new custom field" "link" And I click on "Text area" "link" And I set the following fields to these values: | Name | Test field | | Short name | testfield | And I click on "Save changes" "button" in the "Adding a new Text area" "dialogue" And I click on "Edit" "link" in the "Test field" "table_row" And I set the following fields to these values: | Name | Edited field | And I click on "Save changes" "button" in the "Updating Test field" "dialogue" Then I should see "Edited field" And I should not see "Test field" And I log out Scenario: Delete a custom course textarea field When I click on "Add a new custom field" "link" And I click on "Text area" "link" And I set the following fields to these values: | Name | Test field | | Short name | testfield | And I click on "Save changes" "button" in the "Adding a new Text area" "dialogue" And I click on "Delete" "link" in the "Test field" "table_row" And I click on "Yes" "button" in the "Confirm" "dialogue" Then I should not see "Test field" And I log out tests/behat/default_value.feature 0000644 00000012136 15152206241 0013167 0 ustar 00 # This feature has Atto-specific steps. See MDL-75913 for further details. @customfield @customfield_textarea @javascript @_file_upload @editor_atto Feature: Default value for the textarea custom field can contain images In order to see images on custom fields As a manager I need to be able to add images to the default value Background: Given the following "users" exist: | username | firstname | lastname | email | | teacher | Teacher | 1 | teacher1@example.com | | manager | Manager | 1 | manager1@example.com | And the following "courses" exist: | fullname | shortname | format | | Course 1 | C1 | topics | And the following "course enrolments" exist: | user | course | role | | teacher | C1 | editingteacher | And the following "system role assigns" exist: | user | course | role | | manager | Acceptance test site | manager | And the following "custom field categories" exist: | name | component | area | itemid | | Category for test | core_course | course | 0 | And the following "blocks" exist: | blockname | contextlevel | reference | pagetypepattern | defaultregion | | private_files | System | 1 | my-index | side-post | # Upload an image into the private files. And I log in as "admin" And I follow "Manage private files" And I upload "lib/tests/fixtures/gd-logo.png" file to "Files" filemanager And I click on "Save changes" "button" And I navigate to "Courses > Course custom fields" in site administration And I click on "Add a new custom field" "link" And I click on "Text area" "link" And I set the following fields to these values: | Name | Test field | | Short name | testfield | | Default value | v | # Embed the image into Default value. And I select the text in the "Default value" Atto editor And I click on "Insert or edit image" "button" in the "Default value" "form_row" And I click on "Browse repositories..." "button" And I click on "Private files" "link" in the ".fp-repo-area" "css_element" And I click on "gd-logo.png" "link" And I click on "Select this file" "button" And I set the field "Describe this image for someone who cannot see it" to "Example" And I click on "Save image" "button" And I click on "Save changes" "button" in the "Adding a new Text area" "dialogue" And I log out Scenario: For the courses that existed before the custom field was created the default value is displayed When I am on site homepage Then the image at "//*[contains(@class, 'frontpage-course-list-all')]//*[contains(@class, 'customfield_textarea')]//img[contains(@src, 'pluginfile.php') and contains(@src, '/customfield_textarea/defaultvalue/') and @alt='Example']" "xpath_element" should be identical to "lib/tests/fixtures/gd-logo.png" Scenario: Teacher will see textarea default value when editing a course created before custom field was created # Teacher will see the image when editing existing course. And I log in as "teacher" And I am on "Course 1" course homepage And I navigate to "Settings" in current page administration And I expand all fieldsets Then "//img[contains(@src, 'draftfile.php') and contains(@src, '/gd-logo.png') and @alt='Example']" "xpath_element" should exist in the "Test field" "form_row" # Save the course without changing the default value. And I press "Save and display" And I log out # Now the same image is displayed as "value" and not as "defaultvalue". And I am on site homepage And "//img[contains(@src, '/customfield_textarea/defaultvalue/')]" "xpath_element" should not exist And the image at "//*[contains(@class, 'frontpage-course-list-all')]//*[contains(@class, 'customfield_textarea')]//img[contains(@src, 'pluginfile.php') and contains(@src, '/customfield_textarea/value/') and @alt='Example']" "xpath_element" should be identical to "lib/tests/fixtures/gd-logo.png" Scenario: Manager can create a course and the default value for textarea custom field will apply. When I log in as "manager" And I go to the courses management page And I click on "Create new course" "link" in the "#course-listing" "css_element" And I set the following fields to these values: | Course full name | Course 2 | | Course short name | C2 | And I expand all fieldsets Then "//img[contains(@src, 'draftfile.php') and contains(@src, '/gd-logo.png') and @alt='Example']" "xpath_element" should exist in the "Test field" "form_row" And I press "Save and display" And I log out # Now the same image is displayed as "value" and not as "defaultvalue". And I am on site homepage And the image at "//*[contains(@class, 'frontpage-course-list-all')]//*[contains(@class, 'customfield_textarea')]//img[contains(@src, 'pluginfile.php') and contains(@src, '/customfield_textarea/value/') and @alt='Example']" "xpath_element" should be identical to "lib/tests/fixtures/gd-logo.png" tests/plugin_test.php 0000644 00000017657 15152206241 0010772 0 ustar 00 <?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/>. namespace customfield_textarea; use core_customfield_generator; use core_customfield_test_instance_form; /** * Functional test for customfield_textarea * * @package customfield_textarea * @copyright 2019 Marina Glancy * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class plugin_test extends \advanced_testcase { /** @var stdClass[] */ private $courses = []; /** @var \core_customfield\category_controller */ private $cfcat; /** @var \core_customfield\field_controller[] */ private $cfields; /** @var \core_customfield\data_controller[] */ private $cfdata; /** * Tests set up. */ public function setUp(): void { $this->resetAfterTest(); $this->cfcat = $this->get_generator()->create_category(); $this->cfields[1] = $this->get_generator()->create_field( ['categoryid' => $this->cfcat->get('id'), 'shortname' => 'myfield1', 'type' => 'textarea']); $this->cfields[2] = $this->get_generator()->create_field( ['categoryid' => $this->cfcat->get('id'), 'shortname' => 'myfield2', 'type' => 'textarea', 'configdata' => ['required' => 1]]); $this->cfields[3] = $this->get_generator()->create_field( ['categoryid' => $this->cfcat->get('id'), 'shortname' => 'myfield3', 'type' => 'textarea', 'configdata' => ['defaultvalue' => 'Value3', 'defaultvalueformat' => FORMAT_MOODLE]]); $this->courses[1] = $this->getDataGenerator()->create_course(); $this->courses[2] = $this->getDataGenerator()->create_course(); $this->courses[3] = $this->getDataGenerator()->create_course(); $this->cfdata[1] = $this->get_generator()->add_instance_data($this->cfields[1], $this->courses[1]->id, ['text' => 'Value1', 'format' => FORMAT_MOODLE]); $this->cfdata[2] = $this->get_generator()->add_instance_data($this->cfields[1], $this->courses[2]->id, ['text' => 'Value2', 'format' => FORMAT_MOODLE]); $this->setUser($this->getDataGenerator()->create_user()); } /** * Get generator * @return core_customfield_generator */ protected function get_generator() : core_customfield_generator { return $this->getDataGenerator()->get_plugin_generator('core_customfield'); } /** * Test for initialising field and data controllers */ public function test_initialise() { $f = \core_customfield\field_controller::create($this->cfields[1]->get('id')); $this->assertTrue($f instanceof field_controller); $f = \core_customfield\field_controller::create(0, (object)['type' => 'textarea'], $this->cfcat); $this->assertTrue($f instanceof field_controller); $d = \core_customfield\data_controller::create($this->cfdata[1]->get('id')); $this->assertTrue($d instanceof data_controller); $d = \core_customfield\data_controller::create(0, null, $this->cfields[1]); $this->assertTrue($d instanceof data_controller); } /** * Test for configuration form functions * * Create a configuration form and submit it with the same values as in the field */ public function test_config_form() { $this->setAdminUser(); $submitdata = (array)$this->cfields[3]->to_record(); $submitdata['configdata'] = $this->cfields[3]->get('configdata'); $submitdata = \core_customfield\field_config_form::mock_ajax_submit($submitdata); $form = new \core_customfield\field_config_form(null, null, 'post', '', null, true, $submitdata, true); $form->set_data_for_dynamic_submission(); $this->assertTrue($form->is_validated()); $form->process_dynamic_submission(); } /** * Test for instance form functions */ public function test_instance_form() { global $CFG; require_once($CFG->dirroot . '/customfield/tests/fixtures/test_instance_form.php'); $this->setAdminUser(); $handler = $this->cfcat->get_handler(); // First try to submit without required field. $submitdata = (array)$this->courses[1]; core_customfield_test_instance_form::mock_submit($submitdata, []); $form = new core_customfield_test_instance_form('POST', ['handler' => $handler, 'instance' => $this->courses[1]]); $this->assertFalse($form->is_validated()); // Now with required field. $submitdata['customfield_myfield2_editor'] = ['text' => 'Some text', 'format' => FORMAT_HTML]; core_customfield_test_instance_form::mock_submit($submitdata, []); $form = new core_customfield_test_instance_form('POST', ['handler' => $handler, 'instance' => $this->courses[1]]); $this->assertTrue($form->is_validated()); $data = $form->get_data(); $this->assertNotEmpty($data->customfield_myfield1_editor); $this->assertNotEmpty($data->customfield_myfield2_editor); $handler->instance_form_save($data); } /** * Test that instance form save empties the field content for blank values */ public function test_instance_form_save_clear(): void { global $CFG; require_once("{$CFG->dirroot}/customfield/tests/fixtures/test_instance_form.php"); $this->setAdminUser(); $handler = $this->cfcat->get_handler(); // Set our custom field to a known value. $submitdata = (array) $this->courses[1] + [ 'customfield_myfield1_editor' => ['text' => 'I can see it in your eyes', 'format' => FORMAT_HTML], 'customfield_myfield2_editor' => ['text' => 'I can see it in your smile', 'format' => FORMAT_HTML], ]; core_customfield_test_instance_form::mock_submit($submitdata, []); $form = new core_customfield_test_instance_form('post', ['handler' => $handler, 'instance' => $this->courses[1]]); $handler->instance_form_save($form->get_data()); $this->assertEquals($submitdata['customfield_myfield1_editor']['text'], \core_customfield\data_controller::create($this->cfdata[1]->get('id'))->export_value()); // Now empty our non-required field. $submitdata['customfield_myfield1_editor']['text'] = ''; core_customfield_test_instance_form::mock_submit($submitdata, []); $form = new core_customfield_test_instance_form('post', ['handler' => $handler, 'instance' => $this->courses[1]]); $handler->instance_form_save($form->get_data()); $this->assertEmpty(\core_customfield\data_controller::create($this->cfdata[1]->get('id'))->export_value()); } /** * Test for data_controller::get_value and export_value */ public function test_get_export_value() { $this->assertEquals('Value1', $this->cfdata[1]->get_value()); $this->assertEquals('<div class="text_to_html">Value1</div>', $this->cfdata[1]->export_value()); // Field without data but with a default value. $d = \core_customfield\data_controller::create(0, null, $this->cfields[3]); $this->assertEquals('Value3', $d->get_value()); $this->assertEquals('<div class="text_to_html">Value3</div>', $d->export_value()); } /** * Deleting fields and data */ public function test_delete() { $this->cfcat->get_handler()->delete_all(); } } lib.php 0000644 00000006201 15152206241 0006020 0 ustar 00 <?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/>. /** * Callbacks * * @package customfield_textarea * @copyright 2018 Marina Glancy * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die; /** * Serve the files from the customfield_textarea file areas * * @param stdClass $course the course object * @param stdClass $cm the course module object * @param context $context the context * @param string $filearea the name of the file area * @param array $args extra arguments (itemid, path) * @param bool $forcedownload whether or not force download * @param array $options additional options affecting the file serving * @return bool false if the file not found, just send the file otherwise and do not return */ function customfield_textarea_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { global $DB; $itemid = array_shift($args); if ($filearea === 'value') { // Value of the data, itemid = id in data table. $datarecord = $DB->get_record(\core_customfield\data::TABLE, ['id' => $itemid], '*', MUST_EXIST); $field = \core_customfield\field_controller::create($datarecord->fieldid); $data = \core_customfield\data_controller::create(0, $datarecord, $field); $handler = $field->get_handler(); if ($field->get('type') !== 'textarea' || !$handler->can_view($field, $data->get('instanceid')) || $data->get_context()->id != $context->id) { send_file_not_found(); } } else if ($filearea === 'defaultvalue') { // Default value of the field, itemid = id in the field table. $field = \core_customfield\field_controller::create($itemid); $handler = $field->get_handler(); if ($field->get('type') !== 'textarea' || $handler->get_configuration_context()->id != $context->id) { send_file_not_found(); } } else { send_file_not_found(); } $filename = array_pop($args); // The last item in the $args array. $filepath = '/' . ($args ? implode('/', $args) . '/' : ''); // Retrieve the file from the Files API. $fs = get_file_storage(); $file = $fs->get_file($context->id, 'customfield_textarea', $filearea, $itemid, $filepath, $filename); if (!$file) { send_file_not_found(); } // We can now send the file back to the browser - in this case with a cache lifetime of 1 day and no filtering. send_file($file, 86400, 0, $forcedownload, $options); } version.php 0000644 00000002022 15152206241 0006734 0 ustar 00 <?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/>. /** * Customfield text area plugin * * @package customfield_textarea * @copyright 2018 David Matamoros <toni@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'customfield_textarea'; $plugin->version = 2022112800; $plugin->requires = 2022111800; classes/field_controller.php 0000644 00000012371 15152206241 0012242 0 ustar 00 <?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/>. /** * Customfield textarea plugin * * @package customfield_textarea * @copyright 2018 David Matamoros <davidmc@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace customfield_textarea; defined('MOODLE_INTERNAL') || die; /** * Class field * * @package customfield_textarea * @copyright 2018 David Matamoros <davidmc@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class field_controller extends \core_customfield\field_controller { /** * Const type */ const TYPE = 'textarea'; /** * Before delete bulk actions */ public function delete() : bool { global $DB; $fs = get_file_storage(); // Delete files in the defaultvalue. $fs->delete_area_files($this->get_handler()->get_configuration_context()->id, 'customfield_textarea', 'defaultvalue', $this->get('id')); // Delete files in the data. We can not use $fs->delete_area_files_select() because context may be different. $params = ['component' => 'customfield_textarea', 'filearea' => 'value', 'fieldid' => $this->get('id')]; $where = "component = :component AND filearea = :filearea AND itemid IN (SELECT cfd.id FROM {customfield_data} cfd WHERE cfd.fieldid = :fieldid)"; $filerecords = $DB->get_recordset_select('files', $where, $params); foreach ($filerecords as $filerecord) { $fs->get_file_instance($filerecord)->delete(); } $filerecords->close(); // Delete data and field. return parent::delete(); } /** * Prepare the field data to set in the configuration form * * Necessary if some preprocessing required for editor or filemanager fields * * @param \stdClass $formdata */ public function prepare_for_config_form(\stdClass $formdata) { if (!empty($formdata->configdata['defaultvalue'])) { $textoptions = $this->value_editor_options(); $context = $textoptions['context']; $record = new \stdClass(); $record->defaultvalue = $formdata->configdata['defaultvalue']; $record->defaultvalueformat = $formdata->configdata['defaultvalueformat']; file_prepare_standard_editor($record, 'defaultvalue', $textoptions, $context, 'customfield_textarea', 'defaultvalue', $formdata->id); $formdata->configdata['defaultvalue_editor'] = $record->defaultvalue_editor; } } /** * Add fields for editing a textarea field. * * @param \MoodleQuickForm $mform */ public function config_form_definition(\MoodleQuickForm $mform) { $mform->addElement('header', 'header_specificsettings', get_string('specificsettings', 'customfield_textarea')); $mform->setExpanded('header_specificsettings', true); $desceditoroptions = $this->value_editor_options(); $mform->addElement('editor', 'configdata[defaultvalue_editor]', get_string('defaultvalue', 'core_customfield'), null, $desceditoroptions); } /** * Options for editor * * @param \context|null $context context if known, otherwise configuration context will be used * @return array */ public function value_editor_options(\context $context = null) { global $CFG; require_once($CFG->libdir.'/formslib.php'); if (!$context) { $context = $this->get_handler()->get_configuration_context(); } return ['maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'context' => $context]; } /** * Saves the field configuration */ public function save() { $configdata = $this->get('configdata'); if (!array_key_exists('defaultvalue_editor', $configdata)) { $this->field->save(); return; } if (!$this->get('id')) { $this->field->save(); } // Store files. $textoptions = $this->value_editor_options(); $tempvalue = (object) ['defaultvalue_editor' => $configdata['defaultvalue_editor']]; $tempvalue = file_postupdate_standard_editor($tempvalue, 'defaultvalue', $textoptions, $textoptions['context'], 'customfield_textarea', 'defaultvalue', $this->get('id')); $configdata['defaultvalue'] = $tempvalue->defaultvalue; $configdata['defaultvalueformat'] = $tempvalue->defaultvalueformat; unset($configdata['defaultvalue_editor']); $this->field->set('configdata', json_encode($configdata)); $this->field->save(); } } classes/privacy/provider.php 0000644 00000007156 15152206241 0012230 0 ustar 00 <?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/>. /** * Privacy Subsystem implementation for customfield_textarea. * * @package customfield_textarea * @copyright 2018 Daniel Neis Araujo <danielneis@gmail.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace customfield_textarea\privacy; use core_customfield\data_controller; use core_customfield\privacy\customfield_provider; use core_privacy\local\request\writer; defined('MOODLE_INTERNAL') || die(); /** * Privacy Subsystem for customfield_textarea implementing null_provider. * * @copyright 2018 Daniel Neis Araujo <danielneis@gmail.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class provider implements \core_privacy\local\metadata\null_provider, customfield_provider { /** * Get the language string identifier with the component's language * file to explain why this plugin stores no data. * * @return string */ public static function get_reason() : string { return 'privacy:metadata'; } /** * Preprocesses data object that is going to be exported * * @param data_controller $data * @param \stdClass $exportdata * @param array $subcontext */ public static function export_customfield_data(data_controller $data, \stdClass $exportdata, array $subcontext) { $context = $data->get_context(); $exportdata->value = writer::with_context($context) ->rewrite_pluginfile_urls($subcontext, 'customfield_textarea', 'value', $exportdata->id, $exportdata->value); writer::with_context($context) ->export_data($subcontext, $exportdata) ->export_area_files($subcontext, 'customfield_textarea', 'value', $exportdata->id); } /** * Allows plugins to delete everything they store related to the data (usually files) * * @param string $dataidstest * @param array $params * @param array $contextids * @return mixed|void */ public static function before_delete_data(string $dataidstest, array $params, array $contextids) { $fs = get_file_storage(); foreach ($contextids as $contextid) { $fs->delete_area_files_select($contextid, 'customfield_textarea', 'value', $dataidstest, $params); } } /** * Allows plugins to delete everything they store related to the field configuration (usually files) * * The implementation should not delete data or anything related to the data, since "before_delete_data" is * invoked separately. * * @param string $fieldidstest * @param array $params * @param array $contextids */ public static function before_delete_fields(string $fieldidstest, array $params, array $contextids) { $fs = get_file_storage(); foreach ($contextids as $contextid) { $fs->delete_area_files_select($contextid, 'customfield_textarea', 'defaultvalue', $fieldidstest, $params); } } } classes/data_controller.php 0000644 00000015333 15152206241 0012071 0 ustar 00 <?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/>. /** * Customfields textarea plugin * * @package customfield_textarea * @copyright 2018 Daniel Neis Araujo <daniel@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace customfield_textarea; defined('MOODLE_INTERNAL') || die; /** * Class data * * @package customfield_textarea * @copyright 2018 Daniel Neis Araujo <daniel@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class data_controller extends \core_customfield\data_controller { /** * Return the name of the field where the information is stored * @return string */ public function datafield() : string { return 'value'; } /** * Options for the editor * * @return array */ protected function value_editor_options() { /** @var field_controller $field */ $field = $this->get_field(); return $field->value_editor_options($this->get('id') ? $this->get_context() : null); } /** * Returns the name of the field to be used on HTML forms. * * @return string */ public function get_form_element_name() : string { return parent::get_form_element_name() . '_editor'; } /** * Add fields for editing a textarea field. * * @param \MoodleQuickForm $mform */ public function instance_form_definition(\MoodleQuickForm $mform) { $field = $this->get_field(); $desceditoroptions = $this->value_editor_options(); $elementname = $this->get_form_element_name(); $mform->addElement('editor', $elementname, $this->get_field()->get_formatted_name(), null, $desceditoroptions); if ($field->get_configdata_property('required')) { $mform->addRule($elementname, null, 'required', null, 'client'); } } /** * Saves the data coming from form * * @param \stdClass $datanew data coming from the form */ public function instance_form_save(\stdClass $datanew) { $fieldname = $this->get_form_element_name(); if (!property_exists($datanew, $fieldname)) { return; } $fromform = $datanew->$fieldname; if (!$this->get('id')) { $this->data->set('value', ''); $this->data->set('valueformat', FORMAT_MOODLE); $this->save(); } if (array_key_exists('text', $fromform)) { $textoptions = $this->value_editor_options(); $data = (object) ['field_editor' => $fromform]; $data = file_postupdate_standard_editor($data, 'field', $textoptions, $textoptions['context'], 'customfield_textarea', 'value', $this->get('id')); $this->data->set('value', $data->field); $this->data->set('valueformat', $data->fieldformat); $this->save(); } } /** * Prepares the custom field data related to the object to pass to mform->set_data() and adds them to it * * This function must be called before calling $form->set_data($object); * * @param \stdClass $instance the entity that has custom fields, if 'id' attribute is present the custom * fields for this entity will be added, otherwise the default values will be added. */ public function instance_form_before_set_data(\stdClass $instance) { $textoptions = $this->value_editor_options(); if ($this->get('id')) { $text = $this->get('value'); $format = $this->get('valueformat'); $temp = (object)['field' => $text, 'fieldformat' => $format]; file_prepare_standard_editor($temp, 'field', $textoptions, $textoptions['context'], 'customfield_textarea', 'value', $this->get('id')); $value = $temp->field_editor; } else { $text = $this->get_field()->get_configdata_property('defaultvalue'); $format = $this->get_field()->get_configdata_property('defaultvalueformat'); $temp = (object)['field' => $text, 'fieldformat' => $format]; file_prepare_standard_editor($temp, 'field', $textoptions, $textoptions['context'], 'customfield_textarea', 'defaultvalue', $this->get_field()->get('id')); $value = $temp->field_editor; } $instance->{$this->get_form_element_name()} = $value; } /** * Delete data * * @return bool */ public function delete() { get_file_storage()->delete_area_files($this->get('contextid'), 'customfield_textarea', 'value', $this->get('id')); return parent::delete(); } /** * Returns the default value as it would be stored in the database (not in human-readable format). * * @return mixed */ public function get_default_value() { return $this->get_field()->get_configdata_property('defaultvalue'); } /** * Returns value in a human-readable format * * @return mixed|null value or null if empty */ public function export_value() { global $CFG; require_once($CFG->libdir . '/filelib.php'); $value = $this->get_value(); if ($this->is_empty($value)) { return null; } if ($dataid = $this->get('id')) { $context = $this->get_context(); $processed = file_rewrite_pluginfile_urls($value, 'pluginfile.php', $context->id, 'customfield_textarea', 'value', $dataid); $value = format_text($processed, $this->get('valueformat'), ['context' => $context]); } else { $fieldid = $this->get_field()->get('id'); $configcontext = $this->get_field()->get_handler()->get_configuration_context(); $processed = file_rewrite_pluginfile_urls($value, 'pluginfile.php', $configcontext->id, 'customfield_textarea', 'defaultvalue', $fieldid); $valueformat = $this->get_field()->get_configdata_property('defaultvalueformat'); $value = format_text($processed, $valueformat, ['context' => $configcontext]); } return $value; } } lang/en/customfield_textarea.php 0000644 00000002201 15152206241 0013004 0 ustar 00 <?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/>. /** * Customfield textarea plugin * * @package customfield_textarea * @copyright 2018 Toni Barbera <toni@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); $string['pluginname'] = 'Text area'; $string['privacy:metadata'] = 'The Text area field type plugin doesn\'t store any personal data; it uses tables defined in core.'; $string['specificsettings'] = 'Text area field settings';
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | ���֧ߧ֧�ѧ�ڧ� ����ѧߧڧ��: 0 |
proxy
|
phpinfo
|
���ѧ����ۧܧ�