The MODX NewsPublisher snippet extra has been around for a very long time. Even before MODX Revolution existed, NewsPublisher was one of the most popular MODX extras (after Wayfinder and getResources). When MODX Revolution came out, people missed NewsPublisher, so I put together a Revolution version of it. Since then, NewsPublisher has gone through several upgrades and refactorings.
What Does NewsPublisher Do?
NewsPublisher lets user create and edit Resources and (optionally) their attached TVs in the front end of your site. The users log in to the front-end and, if they have the right permissions, they can create new resources for the web site or edit existing ones.
Why Would I Want That?
When users need to create or edit documents on a site, many naive MODX administrators will just put them in the Administrator user group and let them do the work in the MODX Manager without realizing the security implications of doing that.
Without careful management of the users' permissions and group memberships, the users may have the right to create, edit, or delete any page on the site. In fact, if they have the default administrator permissions, they can actually delete other users, change their information, or change their passwords.
Making sure this can't happen is tricky, and it's easy to make a mistake you won't find out about until some user accidentally (or on purpose) does something horrendous to your site.
Another problem is that unless you get deep into the weeds of Form Customization, users will be able to edit all fields of the resource, and all TVs attached to its template. You seldom want that, but it's tricky to prevent it.
NewsPublisher solves this problem by letting you keep those "editor" users out of the MODX Manager entirely, and letting you easily specify which fields and TVs they should have access to.
How Does it Work?
When users go to a page containing the NewsPublisher snippet, they'll see a form similar to the one shown in the manager with resource fields and TVs. In fact, with a little effort, you could style it to look exactly like the Manager form. The fields and TVs you want to show are listed in the NewsPublisher snippet tag. There's no way for the user to modify fields or TVs associated with the resource unless they're listed in the NewsPublisher snippet tag.
Here's an example NewsPublisher snippet tag:
[[!NewsPublisher? &show=`pagetitle,content,description,pub_date,introtext,TV1,TV2` &initrte=`1` &rtcontent=`1` &rtsummary=`1` &initdatepicker=`1` &initfilebrowser=`1` &parentid=`12` &published=`1` &captions=`content:Enter Post,introtext:Summary,description:Give a brief description` ]]
In the example above, the
&show property determines that the user will see a form showing the
introtext fields (in that order) and
The next property
&initrte, means that some fields will be using the Rich Text Editor, TinyMCE.
The two properties after that,
&rtsummary, indicate that the content and introtext (summary) fields will use the rich text editor.
The next two properties,
&initfilebrowser, activate the date picker widget (for the
pub_date field) and the file browser (to allow adding images in the rich-text fields and handling any image TVs).
&parentid property means that any new pages the user creates (if they have that permission) will be children of the resource with the ID of 12. (If that property is left out, they will be children of the page with the NewsPublisher snippet tag.)
As you might guess, the
&published property means that any new pages will be published
&captions property sets custom captions for the fields listed. By default, the actual field names are used in the captions, but in this example, the
content field will have "Enter Post" as its caption.
How do the Users Get to the NewsPublisher page?
There are several ways to direct the user to a page with the NewsPublisher snippet on it. You can have a direct link to the page on some other page that will send the users to the NewsPublisher page. You can set things up so that if the user is not logged in, the user will be directed to the Login page, and once they're logged in, they'll be directed to the NewsPublisher page.
Another method is to use the NpEditThisButton tag on pages the user might want to edit. That tag will be replaced by an "Edit" button. When the user clicks on the button, they'll be redirected to the page with the NewsPublisher snippet on it, and will automatically be editing the page with the edit button on it. You can even fix things so that the edit button will only appear for users in certain user groups, or only appear when the user is the original author of the page with the NpEditThisButton tag on it. We'll see how that works in the next article.
If you want to know more about the NewsPublisher snippet and its options, you can visit the NewsPublisher documentation page.
Bob Ray is the author of the MODX: The Official Guide and dozens of MODX Extras including QuickEmail, NewsPublisher, SiteCheck, GoRevo, Personalize, EZfaq, MyComponent and many more. His website is Bob’s Guides. It not only includes a plethora of MODX tutorials but there are some really great bread recipes there, as well.