Skip to content

Create new Category from Article edit form#8623

Closed
pe7er wants to merge 16 commits intojoomla:stagingfrom
pe7er:article-freecategory
Closed

Create new Category from Article edit form#8623
pe7er wants to merge 16 commits intojoomla:stagingfrom
pe7er:article-freecategory

Conversation

@pe7er
Copy link
Copy Markdown
Contributor

@pe7er pe7er commented Dec 8, 2015

Sometimes Joomla's workflow can be a bit confusing for new users:
Usually you have to create a category "X", create some articles that you assign to that category "X", create a menu item of type Category Blog to display the articles from category "X".

This PR adds a new functionality to the Article edit form that makes it possible to create & assign a new Category on the fly.

Huge thanks to @roland-d who helped me with developing this functionality at the Joomla Code Sprint at Roompot in Weert(NL).

Testing Instructions

Before the PR

Go to Content > Article
Create a new article (Title) and select an existing Category.

After the PR

Go to Content > Article
Create a new article (Title) and click on the Category dropdown.

article1

The Category dropdown now has an option to add a new Category name.

article2

Don't forget to click on to select your newly created Category.

article3

The new Category will be on the bottom of the list, but only saved when the article is saved.

@joomla-cms-bot joomla-cms-bot added Language Change This is for Translators PR-staging labels Dec 8, 2015
@brianteeman
Copy link
Copy Markdown
Contributor

Is it always a root level category?

@pe7er
Copy link
Copy Markdown
Contributor Author

pe7er commented Dec 8, 2015

Yes, that's right.
If you want to change the Categories (which you'll probably will later on), you can do that later in the Category Manager.

@brianteeman
Copy link
Copy Markdown
Contributor

Thanks for clarifying @pe7er just wanted to double check before testing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of requiring the model and table we should use the relevent JModelLegacy::addIncludePath (https://github.com/joomla/joomla-cms/blob/3.5.0-beta/libraries/legacy/model/legacy.php#L81) and JTable::addIncludePath (https://github.com/joomla/joomla-cms/blob/3.5.0-beta/libraries/joomla/table/table.php#L319)

@wilsonge
Copy link
Copy Markdown
Contributor

wilsonge commented Dec 9, 2015

OK Several "smaller" comments and a "larger" comment (the plugin thing) but overall nice work. This is a really positive feature :)

@coolcat-creations
Copy link
Copy Markdown
Contributor

What about having a field "parent category" and a second field "child category"
This would improve 2 things:

  1. On pages with complex structure it´s easier to find the categories inside the list
  2. This great new feature would be able to add categories to existing parent categories

thanks for this great feature!

@brianteeman
Copy link
Copy Markdown
Contributor

Without commenting on the code aspects that @wilsonge mentioned

  1. Creating categories and alias works (although I did manage at one point to rename an existing category but cant replicate that anymore)
  2. As it stands its a bit of a hidden secret. I would suggest updating the tooltip similar to the one for the tags
  3. @wilsonge comment that this functionality should be available to all components that use categories makes sense to me. Just as tags works consistently across all uses so should category selection and creation
    This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8623.

@brianteeman
Copy link
Copy Markdown
Contributor

Also what about the acl.
If the user doesnt have access to create a root level category what happens. (Sorry I havent tested this as I am useless setting up the ACL)


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8623.

@brianteeman
Copy link
Copy Markdown
Contributor

Sorry me again

Front end editing
While you can create a new tag on the frontend you cant create a new category


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8623.

@pe7er
Copy link
Copy Markdown
Contributor Author

pe7er commented Dec 9, 2015

Thanks for your constructive feedback @wilsonge !
I've made some changes, e.g. moved the code to category helper file so that it can be reused with other extensions that use com_categories categories. IMHO it's better to use the helper file and not a plugin.
Roland (thanks @roland-d !) helped me with refactoring the allowAdd to the field.php library.

@pe7er
Copy link
Copy Markdown
Contributor Author

pe7er commented Dec 9, 2015

Thanks for your feedback @designbengel !
I've tried to keep it as simple as possible.
IMHO people can use the Category Manager to further (re)organize their category structure.
The categories created from articles are all assigned to parent level & easy to find.

Maybe we could add a message about that after creating a new category?
For example: "You've created a new category. To organize your categories go to the [Category Manager]" with [Category Manager] linked to the category manager?

@brianteeman
Copy link
Copy Markdown
Contributor

Simple is always best

@pe7er
Copy link
Copy Markdown
Contributor Author

pe7er commented Dec 9, 2015

Thanks for your feedback @brianteeman
I'll indeed add this functionality to other components that make use of Categories. Now that the Category Creation method is in the helper file, it's easier to reuse by other components.

Thanks for your tooltip suggestion, I've added it to this PR.

@pe7er
Copy link
Copy Markdown
Contributor Author

pe7er commented Dec 9, 2015

I've reproduced the front-end problem with this PR that @brianteeman reported.
I'll try to fix that...

@infograf768
Copy link
Copy Markdown
Member

Please alpha order
+JGLOBAL_ADD_CUSTOM_CATEGORY="Add new Category"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this stuff needs to go into the categoryedit.php file not in the global form field settings here :) Again look at JFormFieldPassword (it's the right code - just the wrong place!)

@Gerlof
Copy link
Copy Markdown

Gerlof commented Dec 11, 2015

I have tested this item ✅ successfully on cf87097


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8623.

@pe7er
Copy link
Copy Markdown
Contributor Author

pe7er commented Dec 12, 2015

Thanks for testing @Gerlof

Thanks @infograf768 for your comment about this PR & ACL.
This can be a problem indeed, will check it...

@joomla-cms-bot
Copy link
Copy Markdown

This PR has received new commits.

CC: @Gerlof


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8623.

@pe7er
Copy link
Copy Markdown
Contributor Author

pe7er commented Dec 12, 2015

I've tested the issue with front-end ACL that @infograf768 described:
It was possible for an author to create (unlimited) new categories, however their articles were all created with publish state "unpublished".
IMHO that's unwanted behavior, so I removed the possibility on the front-end to add new categories.

@rogerhoen
Copy link
Copy Markdown

I have tested this item ✅ successfully on c055379

Very usable to end-users AND administrators. Tested multi-lingual. Worked fine!


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8623.

@FeikeMulder
Copy link
Copy Markdown

I have tested this item ✅ successfully on c055379

Tested successfully.
Verry Nice feature.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8623.

@superknutsel
Copy link
Copy Markdown

I have tested this item ✅ successfully on c055379

@test tested succesfully, nice feature!


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8623.

@wilsonge wilsonge modified the milestone: Joomla! 3.6.0 Dec 12, 2015
@rogerhoen rogerhoen mentioned this pull request Dec 13, 2015
@infograf768
Copy link
Copy Markdown
Member

@pe7er
Do we still need the new strings in frontend?

@anibalsanchez
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on c055379

Test OK


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8623.

@brianteeman
Copy link
Copy Markdown
Contributor

RTC - thanks


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8623.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jan 12, 2016
@infograf768
Copy link
Copy Markdown
Member

@pe7er
I still think we do not need the new language strings in frontend.

@wilsonge
Copy link
Copy Markdown
Contributor

wilsonge commented Apr 9, 2016

Merged with b853b6b

@wilsonge wilsonge closed this Apr 9, 2016
@ggppdk
Copy link
Copy Markdown
Contributor

ggppdk commented Apr 9, 2016

With a quick look at the code

  • i did not find the ACL check on core.create for the categoryedit form element
  • only an attribute 'allowAdd' to enable the feature, ok but that also needs to be complemented with an ACL core.create check

so i decided to test this feature in 3.6.x

Indeed the categoryedit form element does not check it

How to test

  • Edit permissions of "manager" usergroup and deny the create at global configuration (and allow to backend access)
  • Login as a "manager" user to backend, and edit any article
  • Type "Test" into the categoryedit form element, and you see it allows you to add new category
  • After saving the article new category is not created which is expected but ... the article category is reset to 1 aka to ROOT category

The problem is that after checking the allowAdd attibute,
we need to go further and also make an core.create ACL check on
the extension (since we are creating a category at root level right ?)

https://github.com/pe7er/joomla-cms/blob/c05537939099d815ec49fb9676c955ec18d61e85/administrator/components/com_categories/models/fields/categoryedit.php#L59

$this->allowAdd = isset($this->element['allowAdd']) ? $this->element['allowAdd'] : '';

if ($this->allowAdd)
{
    $jinput = JFactory::getApplication()->input;
    $user = JFactory::getUser();
    $extension = $this->element['extension'] ? (string) $this->element['extension'] : (string) $jinput->get('extension', 'com_content');
    $this->allowAdd = $user->authorise('core.create', $extension);
}

no_privilege_create
no_privilege_create2

@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Apr 9, 2016
@ggppdk
Copy link
Copy Markdown
Contributor

ggppdk commented Apr 9, 2016

@wilsonge
@pe7er

can you test this ?

@JoshJourney
Copy link
Copy Markdown

Now if only this option was available on the frontend, communities could create all sorts of structures with this!

@chrisdavenport
Copy link
Copy Markdown
Contributor

@JoshuaLewis What could possibly go wrong!? ;-)

@JoshJourney
Copy link
Copy Markdown

If it was permission based (whether ACL or through a menu item) it could be managed through a select group of people via Joomla's user groups. If the easy creation of categories could be assigned to a parent category, someone attempting to wreck havoc wouldn't be hard to spot and wouldn't really mess up the site structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Language Change This is for Translators

Projects

None yet

Development

Successfully merging this pull request may close these issues.