Article creation - can we override categories drop-down

251 views
Skip to first unread message

Rob Sykes

unread,
Nov 30, 2012, 8:43:49 AM11/30/12
to joomla-de...@googlegroups.com
Hi folks,
 
In my User Article Manager extension
 
 
users have the ability to create new articles from the front end (using what ever editor has been set in the back end) using the same mechanism as the standard Create New Article Joomla menu item - ie user is sent to http://<website>/index.php/component/content/?task=article.add...
 
Is it possible to add parameters to the URL to
 
1) select a given category for the article (and initially display it in the category dropdown)
2) force the editor to only recognise a given category (ignoring all others)
 
I'm guessing that 1) is possible as the back-end article editor will use the filters to pre-populate a new article but I'm not sure that 2) is possible.
 
Perhaps it may be better to fire up an instance of the editor programmatically (but I really haven't a clue about doing this) and overriding the category drop down that way
 
Cheers
 
Rob
 

Donald Gilbert

unread,
Nov 30, 2012, 9:45:25 AM11/30/12
to joomla-de...@googlegroups.com
I've done something similar, where I wanted all blog content to be in the blog category, and all page content to be in the pages category. My client just wanted a button that said "add blog post" or "add new page" instead of selecting which category to put it in.

If I remember right, I just created a link that pointed to index.php?component=com_content&task=article.add&catid=X with X specifying the id of the category I wanted to direct them to. The ID get's recognized by the app, and then set in the editor as the category.

Ove

unread,
Nov 30, 2012, 10:05:49 AM11/30/12
to joomla-de...@googlegroups.com, Rob Sykes
Hi Rob,
What do you mean by back-end/front-end editor? = back-end/front-end view?

I myself struggle with the category dropdowns though not within the
content component . I can't find any good flexibility. I'm not sure if
Bootstrap is the problem but so far any disabled category vanish from
the list. Someone with an idea?

For your view I would 1) try to just override the frontend view template
(layout). You may want to include other fields not available in the
front-end edit layout. 2) Use of the beloved plug ins to manipulate the
article edit form. You may have to make sure the plug in only handles
"your" layout! or 3) as it's tricky to override JForm fields directly in
the layout I guess an own model extending the article model could be
used to manipulate the JForm object.

There was a bug for manipulating "form fields with options" introduced
in 2.5.x I reported it but have not checked if it has bin corrected.

Might give an idea.

Ove


Rob Sykes skrev 30.11.2012 14:43:
> Hi folks,
> In my User Article Manager extension
> http://extensions.joomla.org/extensions/news-production/content-submission/18412
> users have the ability to create new articles from the front end
> (using what ever editor has been set in the back end) using the same
> mechanism as the standard Create New Article Joomla menu item - ie
> user is sent to
> http://<website>/index.php/component/content/?task=article.add
> <http://%3Cwebsite%3E/index.php/component/content/?task=article.add>...
> Is it possible to add parameters to the URL to
> 1) select a given category for the article (and initially display it
> in the category dropdown)
> 2) force the editor to only recognise a given category (ignoring all
> others)
> I'm guessing that 1) is possible as the back-end article editor will
> use the filters to pre-populate a new article but I'm not sure that 2)
> is possible.
> Perhaps it may be better to fire up an instance of the editor
> programmatically (but I really haven't a clue about doing this) and
> overriding the category drop down that way
> Cheers
> Rob
> --
> You received this message because you are subscribed to the Google
> Groups "Joomla! General Development" group.
> To view this discussion on the web, visit
> https://groups.google.com/d/msg/joomla-dev-general/-/xzgTBEP-l78J.
> To post to this group, send an email to
> joomla-de...@googlegroups.com.
> To unsubscribe from this group, send email to
> joomla-dev-gene...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/joomla-dev-general?hl=en-GB.

elin

unread,
Dec 2, 2012, 7:36:31 PM12/2/12
to joomla-de...@googlegroups.com, Rob Sykes

The big thing is to make sure you unset any front end fields that you won't be saving from your form otherwise they will be wiped.

In terms of selecting a category the other thing you could do is make a custom field to replace the regular category field and just have the one category, which you could even make hidden perhaps.

Elin

Ove

unread,
Dec 3, 2012, 8:02:46 AM12/3/12
to joomla-de...@googlegroups.com
elin skrev 03.12.2012 01:36:
>
> The big thing is to make sure you unset any front end fields that you
> won't be saving from your form otherwise they will be wiped.
>

I don't think you have to unset anything. The same form-xml and the same
model is used in backend and frontend. e.g. it should be easy to add the
new multi lingual item associations to a frontend edit layout override,
if you like to, as they are available in the JForm object.

> In terms of selecting a category the other thing you could do is make
> a custom field to replace the regular category field and just have the
> one category, which you could even make hidden perhaps.
>

I think Donalds idea "
index.php?component=com_content&task=article.add&catid=X" works but only
as a predefined category that you can change. I suppose your suggestions
includes a plug in?

My own problem is how to get a personalised category list using as much
Joomla as possible. I get a correct <select><option> list from the JForm
field but as it gets "translated" by Joomla any disabled option
disappears. I want the complete category list structure to show. So I
believe a <select><option> in J 3.0 is not backward compatible with 2.5.
I just checked in 2.5 and there I get it as I want. to :)

Ove

Rob Sykes

unread,
Dec 5, 2012, 6:36:21 AM12/5/12
to joomla-de...@googlegroups.com, Rob Sykes

> On Friday, 30 November 2012 15:05:49 UTC, over wrote:
> Hi Rob,
> What do you mean by back-end/front-end editor? = back-end/front-end view?
 
In this context, yes. In the back-end article management, you can set a category filter; when you then create a new article, the category field in the edit screen is pre-populated with the filter value. This would answer question 1) of the original post
 
I'm interested in the custom form idea but this is where my Joomla knowledge is lacking. Would I have to maintain an altered copy of the com_content code in my UAM package or could I impose an 'UAM form' on the com_content code as it is currently installed? Any clarification or pointers to examples would be greatly appreciated.
 
Cheers
 
Rob
 

Ove

unread,
Dec 5, 2012, 8:40:20 AM12/5/12
to joomla-de...@googlegroups.com, Rob Sykes
Hi Rob,

Rob wrote:
>>
In this context, yes. In the back-end article management, you can set a category filter; when you then create a new article, the category field in the edit screen is pre-populated with the filter value. This would answer question 1) of the original post
 
I'm interested in the custom form idea but this is where my Joomla knowledge is lacking. Would I have to maintain an altered copy of the com_content code in my UAM package or could I impose an 'UAM form' on the com_content code as it is currently installed? Any clarification or pointers to examples would be greatly appreciated.
 <<

Didn't  what Donald wrote work??
>>index.php?component=com_content&task=article.add&catid=X with X specifying the id of the category I wanted to direct them to.<<

For the language there is a &forcedLanguage. Should be nice to also have a &forcedCategory uri parameter.


Coincidental I, in this moment, work on a similar issue. How to use code from another component. I need a modal view of the categories to choose categories for component items. A select list is not very userfriendly if you have 100+ language dependent categories  to choose among.  And so far I could not manipulate the category select list to something useful.

In the first step I created this modal layout in com_categories and with a JForm field in my component to check that this works. It does! Now the interesting part comes. I'll move this view/layout to my own component. My guess and hope is that it'll work if I add a model that extends the categories model. I'll know after testing it.

There may be a difference as com_categories is written to support other components. What you need is also the save to be done by com_content. 

You can have a look in com_content frontend form.php model. The question is what happens if you adopt or extend this into your own component. You can use component models in modules so why not give it a test in components?

This idea might cross the border of what is possible. Anyway I'll let you know if my modal view idea works.

Regards
Ove


Rob Sykes

unread,
Dec 5, 2012, 11:45:44 AM12/5/12
to Joomla! General Development
On Dec 5, 11:36 am, Rob Sykes <robsyke...@gmx.com> wrote:
>
> I'm interested in the custom form idea but this is where my Joomla
> knowledge is lacking. Would I have to maintain an altered copy of the
> com_content code in my UAM package or could I impose an 'UAM form' on the
> com_content code as it is currently installed? Any clarification or
> pointers to examples would be greatly appreciated.
>

Replying to myself here but the URI

index.php?component=com_content&task=article.add...

gets transformed to

index.php/component/content/?view=form&layout=edit&...

when the edit screen is displayed. Now in the com_content component
file structure we do have (under views) a 'form' directory and under
that (in tmpl) an 'edit.php' file which looks scarily like the file
which displays the edit form. Now I'm naively thinking that I should
copy the 'form' directory to 'uam' say and modify to my heart's
content and then create the article via the URL

index.php/component/content/?view=uam&layout=edit&...

Would be nice if this were the way

Cheers

Rob

Ove

unread,
Dec 5, 2012, 12:48:13 PM12/5/12
to joomla-de...@googlegroups.com, Rob Sykes

> index.php/component/content/?view=uam&layout=edit&...
>
> Would be nice if this were the way
>
Would be nice but how can Joomla and/or com_content find your view
somewhere on the system?

I've solved my modal view for categories. It works. Own model extends
the categories model and a view in my own component is used for the
modal display. Filtering, sorting and pagination works. Still have some
tests left e.g. that the Acl rules are correctly handled. A least I am
happy. 8-)

Ove

Rob Sykes

unread,
Dec 6, 2012, 10:41:33 AM12/6/12
to joomla-de...@googlegroups.com, Rob Sykes

On Wednesday, 5 December 2012 17:48:13 UTC, over wrote:

> index.php/component/content/?view=uam&layout=edit&...
>
> Would be nice if this were the way
>
Would be nice but how can Joomla and/or com_content find your view
somewhere on the system?
 
Indeed. My naive view was too naive but it was another learning experience. I'm experimenting with using "catid=X" in the URL and it certainly pre-populates the category in the way you would expect. The standard Joomla 'Create an Article' menu link has an option to use a single category so I'm taking a look at that as well.
 
 
I've solved my modal view for categories. It works. Own model extends
the categories model and a view in my own component is used for the
modal display. Filtering, sorting and pagination works. Still have some
tests left e.g. that the Acl rules are correctly handled. A least I am
happy. 8-)

Good stuff.  

Rob Sykes

unread,
Dec 22, 2012, 9:03:38 AM12/22/12
to joomla-de...@googlegroups.com, Rob Sykes
Well, after a little experimentation using the "&catid=" approach seems to do just about what I need
 
Using a vanilla Joomla 2.5.8 install, the behaviour of the editor appears to be the following
 
User in 'Author' group: editor only shows the specified category in the dropdown so we can't move anywhere else
User in 'Editor' group: the same
User in 'Publisher' group: editor starts with the specified category in the dropdown but allows the user to select any other available category
 
I can work with this
 
Rob
Reply all
Reply to author
Forward
0 new messages