Jump to content

Output formatting of admin messages changed


winston
 Share

Recommended Posts

I used to be able to include a link in module messages, like this:

$this->message("Page <a href='$url'>$title</a> generated");

In recent versions, the message gets the htmlspecialchars treatment before output, and the link doesn't work.

I tried looking but couldn't find where the messages get output formatted.

Thanks for your help!

Link to comment
Share on other sites

I don't think I ever tried to output html in messages in the existing message/error system, but with the new notifications system, it is easy:

$this->user->notifications->message("Message Title")->html("Message details including a <a href=''>link</a>");

You will need to enable the new core notifications module.

  • Like 2
Link to comment
Share on other sites

Thanks, Adrian. The new notifications system will be interesting, but in the meantime I took a break, then found what I was looking for in Notices.php.

The answer is:

$this->message("This message contains <a href=''>a link</a>", Notice::allowMarkup);

The code from Notices.php couldn't be clearer:

    /**
     * Flag indicates the notice is allowed to contain markup and won't be automatically entity encoded
     *
     * Note: entity encoding is done by the admin theme at output time.
     *
     */
    const allowMarkup = 32;

    /**
     * Create the Notice
     *
     * @param string $text
     * @param int $flags
     *
     */
    public function __construct($text, $flags = 0) {
        $this->set('text', $text);
        $this->set('class', '');
        $this->set('timestamp', time());
        $this->set('flags', $flags);
    }

  • Like 7
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...