Skip to content

Commit 8547953

Browse files
committed
INT-18599: Implements formatting changeover when using the advanced editor
1 parent 8a7288b commit 8547953

File tree

8 files changed

+47
-6
lines changed

8 files changed

+47
-6
lines changed

post.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
$messagecontent = optional_param('msgcontent', '', PARAM_TEXT);
4040
$subjectcontent = optional_param('subcontent', '', PARAM_TEXT);
4141

42+
$prefilledpost = optional_param('post', '', PARAM_TEXT);
43+
$prefilledpostformat = optional_param('postformat', FORMAT_MOODLE, PARAM_INT);
44+
4245
$PAGE->set_url('/mod/hsuforum/post.php', array(
4346
'reply' => $reply,
4447
'forum' => $forum,
@@ -219,6 +222,14 @@
219222
print_error("activityiscurrentlyhidden");
220223
}
221224

225+
$preferredformat = editors_get_preferred_format();
226+
// Only if there are prefilled contents coming.
227+
if (!empty($messagecontent)) {
228+
// If the prefilled post is not HTML and the preferred format is HTML, convert to it.
229+
if ($prefilledpostformat != FORMAT_HTML and $preferredformat == FORMAT_HTML) {
230+
$messagecontent = format_text($messagecontent, $prefilledpostformat, ['context' => $modcontext]);
231+
}
232+
}
222233
// Load up the $post variable.
223234

224235
$post = new stdClass();
@@ -231,6 +242,7 @@
231242
$post->subject = $parent->subject;
232243
$post->userid = $USER->id;
233244
$post->message = '';
245+
$post->messageformat = '';
234246

235247
$post->groupid = ($discussion->groupid == -1) ? 0 : $discussion->groupid;
236248

styles.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,11 @@ body:not(.theme_snap) li.modtype_hsuforum .afterlink .hsuforum-recent .snap-medi
10111011
float: left;
10121012
}
10131013

1014+
body:not(.theme_snap) li.modtype_hsuforum .activity-item .activity-basis .activity-info {
1015+
padding-top: 1rem;
1016+
padding-left: 0;
1017+
}
1018+
10141019
div.hsuforum-thread-header > div.hsuforum-thread-meta > div.hsuforum-thread-participants > span,
10151020
div.hsuforum-post-body > .hsuforum-post-byline > span {
10161021
width: 2rem;

tests/behat/advanced_editor_pass_data_to_new_page.feature

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ Feature: Users see their typed information in the advanced editor view when clic
6262
And I follow "Test forum name"
6363
And I follow "Test discussion 1 to be cancelled"
6464
And I wait until the page is ready
65+
And I set editable div ".hsuforum-textarea" "css_element" to "Test discussion 1 to be cancelled description"
6566
And I click on ".hsuforum-post.depth0 .hsuforum-reply-link" "css_element"
6667
Then I should see "Reply to Student 1"
67-
And I set editable div ".hsuforum-post.depth0 .hsuforum-textarea" "css_element" to "This is a reply"
68+
And I set editable div with break line ".hsuforum-post.depth0 .hsuforum-textarea" "css_element" to "This is a reply \n This is a new line"
6869
And I click on ".hsuforum-post.depth0 .hsuforum-use-advanced" "css_element"
6970
And I wait until the page is ready
71+
And ".text_to_html br" "css_element" should exist
7072
And I should see "Your reply"
7173
And I set the field with xpath "//*[@id='id_messageeditable']" to "This is a reply"

tests/behat/behat_mod_hsuforum.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,25 @@ public function i_set_editable_div_to ($ellocator, $selectortype, $value) {
137137
$div->setValue($value);
138138
}
139139

140+
/**
141+
* Set regular field (not moodle form field) to a specific value.
142+
*
143+
* @Given /^I set editable div with break line "([^"]*)" "([^"]*)" to "([^"]*)"$/
144+
* @param string $ellocator
145+
* @param string $selectortype
146+
* @param string $value
147+
* @throws \Behat\Mink\Exception\ElementException
148+
*/
149+
public function i_set_editable_div_with_line_break($ellocator, $selectortype, $value) {
150+
// Getting Mink selector and locator.
151+
list($selector, $locator) = $this->transform_selector($selectortype, $ellocator);
152+
153+
// Will throw an ElementNotFoundException if it does not exist.
154+
$div = $this->find($selector, $locator);
155+
$value = str_replace('\n', behat_keys::ENTER, $value);
156+
$div->setValue($value);
157+
}
158+
140159
/**
141160
* Sets the specified value to the field.
142161
*

yui/build/moodle-mod_hsuforum-article/moodle-mod_hsuforum-article-debug.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,9 +761,10 @@ Y.extend(FORM, Y.Base,
761761
var message = Y.one('div[id^=editor-target-container-]');
762762
var subject = Y.one('input[name=subject]');
763763
var link = e.target.getAttribute('href');
764+
var strmessage = encodeURIComponent(message.get('innerText'));
764765
if (!link.includes('post.php?edit')) {
765766
e.target.setAttribute('href', e.target.getAttribute('href') + '&msgcontent=' +
766-
message.get('textContent') + '&subcontent=' + subject.get('value'));
767+
strmessage + '&subcontent=' + subject.get('value'));
767768
}
768769
},
769770
/**

yui/build/moodle-mod_hsuforum-article/moodle-mod_hsuforum-article-min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

yui/build/moodle-mod_hsuforum-article/moodle-mod_hsuforum-article.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,9 +755,10 @@ Y.extend(FORM, Y.Base,
755755
var message = Y.one('div[id^=editor-target-container-]');
756756
var subject = Y.one('input[name=subject]');
757757
var link = e.target.getAttribute('href');
758+
var strmessage = encodeURIComponent(message.get('innerText'));
758759
if (!link.includes('post.php?edit')) {
759760
e.target.setAttribute('href', e.target.getAttribute('href') + '&msgcontent=' +
760-
message.get('textContent') + '&subcontent=' + subject.get('value'));
761+
strmessage + '&subcontent=' + subject.get('value'));
761762
}
762763
},
763764
/**

yui/src/article/js/form.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,10 @@ Y.extend(FORM, Y.Base,
259259
var message = Y.one('div[id^=editor-target-container-]');
260260
var subject = Y.one('input[name=subject]');
261261
var link = e.target.getAttribute('href');
262+
var strmessage = encodeURIComponent(message.get('innerText'));
262263
if (!link.includes('post.php?edit')) {
263264
e.target.setAttribute('href', e.target.getAttribute('href') + '&msgcontent=' +
264-
message.get('textContent') + '&subcontent=' + subject.get('value'));
265+
strmessage + '&subcontent=' + subject.get('value'));
265266
}
266267
},
267268
/**

0 commit comments

Comments
 (0)