Wunderbyte-GmbH/moodle-mod_datalynx

Pattern replace within attributes does not work anymore

Closed this issue · 17 comments

We used to have a possibility to display field value within attributes like that within the entry template
<div class="show-grid [[Phase]]@">

When using that with the latest version, the html gets destroyed like that:
<div class="show-grid <span class=" title="donotreplaceme">Fernlehre"&gt;

Would be great to fix that ASAP

Can reproduce this bug, I am operating under the assumption that the @ is important after the tag?
As a first feedback, this seems to be introduced with masking tags. First we mask tags so they don't get destroyed by moodles "FORMAT_HTML" and after we ran through unmask them. In the issue you are describing the masking (dontreplaceme) is messed up by FORMAT_HTML because it sees class tags inside a class tag.

Trying to find out why it was built like that and fixing as soon as possible :) Have a nice day.

...

here is the course with the problem.

@michaelpollak you have to remove the zip extension.

the @ is there for JavaScript not destroying the HTML.

maybe we dropped support for that in favor of the field renderer.

As far as I can see the code has not been altered for seven years so yes, might coincide with the introduction of field renderers.
https://github.com/Wunderbyte-GmbH/moodle-mod_datalynx/blame/2fdb12716fa272f4f577d213a39ee0c7d3043c30/view/view_class.php

Fixed this by adding an additional check to the regex. When a tag is followed by an @ it is not masked and behaves like you were expecting. So now you can use it within class definition by simply applying the @ after the field tag like you did in your example.

... funktioniert bei der Testinstanz nicht wirklich.

das masking funktioniert ja, aber das unmasking nicht.

$text = $this->unmask_tags($text);

public function unmask_tags($text) {

I've only tested with basic examples, so maybe I did miss something. The unmask should not be triggered at all because tags followed by @ are never masked.
Will import your backup tomorrow and test with this data. Thanks for the feedback David.

Tested with your backup, thank you for that. Still it works for me as expected, can you explain what other functionality you are looking for.
The goal is to use the content added by a user as a css class descriptor in the entry template - right?

Tried to reproduce this a few other ways but can't. Seems to work fine for me :)

You have to login as student. it does work with manager or teacher but not with student.

Just retested with different users to make sure, same result. What field type are you using?

grafik

<div class="show-grid [[Phase]]@">
    <div class="row-fluid">
        <div class="col-1 vertical-container [[Phase]]@">
            <div class="vertical-text">[[Phase]]</div>
        </div>
        <div class="col-6">[[Lernschritt||Überschrift]] [[Lernschritt Beschreibung]]</div>
        <div class="col-3"><span class="abschluss">Lehrende:</span>[[Lehrende]]
            <div style="text-align: left;"><br></div><span class="startdate">[[Startdatum:date]]</span><br><span class="enddate">[[Endddatum:date]]</span></div>
        <div class="col-1"><span class="abschluss" style="font-weight: bold;">WL </span><span class="workload">[[Workload]]</span><br><span class="abschluss" style="font-weight: bold;">LE </span><span class="lerneinheiten">[[Lerneinheiten (LE)]] </span></div>
        <div class="col-1"><span class="hidden editabschluss">#{{viewsesslink:Abschluss;_pixicon:i/edit:Edit;editentries=##entryid##|eids=##entryid##;}}#</span><span class="editlink">##edit##</span> ##delete## </div>
    </div>
</div>

Phase is of type "Select". Maybe because it is there 2 times?

Thaaaat's what I missed... Thank you David! :) The patch should fix your issue, we only preg replace tags that are not followed by an @ but allow in the same entry view to have the same tag replaced.

Thank you. Looks great!