A Moodle course field for links: syllabus, timetable, recording

Moodle's text custom field takes any text, so course links break or point anywhere. Our free customfield_url accepts only web links, optionally only to your own domains.

Drawing of two chain links joined together, one painted blue.

Short answer: schools often add a “Syllabus” or “Timetable” custom field to every course and fill it with a link. Moodle 5.3 ships six custom field types (checkbox, date, number, select, text and textarea), and none of them is a link. A text field accepts anything: a typo, a link to a personal drive, or a javascript: address. Our free plugin, customfield_url, is a custom field type that only takes real web links and shows them as a link.

This is the sixth plugin in our series: one plugin for each Moodle plugin type, each one teaching DevLMS Studio, our AI plugin builder, how that type works.

What it does

  • Only http and https addresses are accepted. Anything else is refused with a clear message.
  • Allowed domains (optional): limit links to your own sites. school.edu also allows docs.school.edu, and refuses look-alikes such as school.edu.evil.com.
  • Link text (optional): show “Open syllabus” instead of a long address. Without it, the site name is shown.
  • Links open in a new tab, with rel="noopener noreferrer".

Add it under Site administration > Courses > Default settings > Course custom fields. It supports Moodle 4.5 LTS to 5.3 and is GPL. The code is on GitHub.

How a custom field type works

From Moodle 5.3’s custom field code and its built-in text type:

  1. A custom field type has two classes. The field controller holds the settings an admin picks when creating a field (ours: link text and allowed domains), saved as JSON in configdata.
  2. The data controller handles one value on one course: the input, validation, the default, and export_value(), which decides what is shown.
  3. datafield() picks which column of core’s customfield_data table stores the value. There are five: whole numbers, decimals, short text, text (we use this one) and long formatted text.
  4. Moodle does not decide what a link looks like for you. export_value() builds the HTML, so the plugin has to make it safe itself.

We tested it with PHPUnit (good links, bad schemes, allowed and look-alike domains, link text, safe HTML) and a Behat run where a link to the wrong domain is refused and the right one appears as “Open syllabus” in the course listing.

What Studio learned

The custom field guide is now in DevLMS Studio’s builder: the two controllers, the storage columns, and the test generator calls.

Need a course field of your own, like a credit value that must match your catalogue or a contact picked from staff? Describe it in DevLMS Studio and watch it built and tested in a real Moodle.

Need a plugin like this for your own Moodle?

Describe it in DevLMS Studio and watch it built and tested in a real Moodle, or ask our team for a fixed price.

Open DevLMS Studio