website page name validation

40 views
Skip to first unread message

samuli....@gmail.com

unread,
Dec 22, 2021, 2:01:06 AM12/22/21
to user...@magnolia-cms.com

Hi,

 

I was wondering what would be the simplest way to validate website page names more strictly than pages app does by default. I would like to basically allow only a subset of characters that is currently possible (e.g.  lower case letters and only ascii alphabets and numbers).

 

Looking at the code it seems that it is using same logic than every other workspace but with website the names end up in page URLs causing the need for encoding URLs. Technically encoding is not an issue but encoded URLs are sometimes directly visible to users and look like garbage. One idea is to add custom validators to pages-app but that needs to be done in multiple places as there are multiple editors that allow editing the page name.

 

BR, Samuli

Roman Kovařík

unread,
Dec 22, 2021, 3:28:03 AM12/22/21
to Magnolia User Mailing List, samuli....@gmail.com
Hey Samuli,

... but with website the names end up in page URLs causing the need for encoding URLs. 


If UTF-8 page names are not working for you, here are createPage and rename page dialogs you can decorate. nodeNameValidator has pattern property which should do the trick.

Hope that helps
Roman
 

Jordie Diepeveen

unread,
Dec 22, 2021, 5:11:31 AM12/22/21
to Magnolia User Mailing List, samuli....@gmail.com
Hi Samuli,

What we always do is using a decoration for the createPage and renamePage dialogs so we can set our own url format validator.

1. Create a new file with the name 'createPage.yaml' in /[module]/decorations/pages-app/dialogs/
2. Use e.g. the following content:

---
form:
  properties: !override
    jcrName:
      validators:
        urlFormat:
          $type: regexpValidator
          pattern: ^[a-z0-9-._]+$
          errorMessage: Invalid URL format. The URL can only contain lowercase digits, Latin letters and the following symbols: ._-
    mgnl:template:

3. Create the file renamePage.yaml inside the same folder
4. Use e.g. the following content:

---
form:
  properties: !override
    jcrName:
      required: true
      validators:
        urlFormat:
          $type: regexpValidator
          pattern: ^[a-z0-9-._]+$
          errorMessage: Invalid URL format. The URL can only contain lowercase digits, Latin letters and the following symbols: ._-

Regards,
Jordie

Op woensdag 22 december 2021 om 08:01:06 UTC+1 schreef samuli....@gmail.com:

samuli....@gmail.com

unread,
Dec 22, 2021, 6:41:59 AM12/22/21
to Jordie Diepeveen, Magnolia User Mailing List

Hi, and thanks for responses.

 

Roman: utf8 technically works but I still want to limit the user to a subset to avoid encoded URLs showing up. Persons creating the webpages are often somewhat untechnical and unaware of the implications of using letters like ‘ä’ in page names.

 

And reading from Jordies response “we always do” might implicate that this is maybe a common requirement. 😊

 

Thanks for the help. This confirms that decorating the pages-app is the way to go.

 

Happy holidays, Samuli

Reply all
Reply to author
Forward
0 new messages