Revolution: MODX resources can be "saved" without a pagetitle

Created on 18 Apr 2019  路  8Comments  路  Source: modxcms/revolution

Bug report

Summary

MODX resources can be "saved" without a pagetitle

Step to reproduce

  1. Create a resource with a "space" in the pagetitle field
  2. Save the resource
  3. Resource is automatically renamed to "Untitled Resource"
  4. Removed "Untitled Resource" text & replace with a "space"
  5. Save

Observed behavior

Resource is saved with no pagetitle

Expected behavior

User should be prompted to enter a pagetitle with real text (not just spaces) before being able to save.

Environment

MODX version, apache/nginx and version, mysql version, browser, etc. Any relevant information.

MODX 2.7.1

type-frontend bug

All 8 comments

The bug, as it turned out, is still relevant for Templates, Categories and Files. You can create them with spaces instead of a name (for a file there will be, for example: " .txt").

For MODX3, this problem is also relevant, although for resources the bug works slightly differently.

Please ignore the referenced pull above (#15146) ... I jumped the gun, so to speak, when replying that it addressed this particular issue. I removed my comment, but the pull reference remains.

OK, I'm going to jump in and work up a solution. One question: Should there _ever_ be an instance where a resource, element, or file name is allowed to begin with white space? My feeling is no. The answer to this question may inform how to go about making the change.

As I work on this, I find myself questioning the usefulness of auto-generating the "Untitled Resource" title and alias to begin with (at least in the way it currently happens). As I play with it (in both 2.x and 3.x), it seems to only apply when you happen to enter only whitespace into the pagetitle field. (Forgive me if I'm missing something in that regard.) As one would expect, an initially-empty field generates a validation error. So why would this not be the case for what is programatically-empty (i.e., only spaces)? Note that I realize there's a nuance in resource naming in that there's a use-case for allowing "0" as a pagetitle/alias, which is why the processors should test for null or an empty string rather than using php empty().

If the intention is to allow the saving of one or more untitled documents, then I'd argue it needs to be gone about in a different and more predictable way. Brainstorming it a bit, maybe ...

  1. Create a boolean system setting, such as "Auto-Generate Page Titles." If this was set to "Yes" then...
  2. Generate the "Untitled Resource" placeholder and create an indexed alias (to account for collisions that would otherwise occur when using FURLs and creating more than one untitled resource in the same container); the most sensible strategy might be to use the document id as the index, for example "untitled-resource-[resource id]"
  3. A couple nice ui features then would be to

    • provide warning when the resource is set to/changed to "published" and the pagetitle still contains the placeholder value

    • automatically replace the placeholder alias when an actual pagetitle is entered

What do you all think? If this functionality is warranted, I'd consider it more of a near-future enhancement and just fix the buggy behavior at this point.

For 2.x we should fix the buggy behavior, in 3.x we can improve the behavior if needed.

In general, for the 2.x branch, I made a solution, but only for resources https://github.com/modxcms/revolution/pull/14800 Although there is a problem for elements and files.
It would be great to fix this bug for 2.x. And for 3.x already add functionality, for example, with "untitled-resource- [resource id]".

See my comment here.

I'd be okay with preventing the empty pagetitle from being used in create (noting the special behavior when a resource is reloaded pre-save for switching templates) but don't really have too many strong feelings on the topic.

Was this page helpful?
0 / 5 - 0 ratings