Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0] Check on the component if the categories support is available #20692

Merged
merged 15 commits into from
Jul 13, 2018

Conversation

laoneo
Copy link
Member

@laoneo laoneo commented Jun 8, 2018

Pull Request for Issue #20667.

Summary of Changes

Adds a check function if associations is available for categories of the current component.

Testing Instructions

  • Enable the Language filter plugin and make sure Associations is set to Yes
  • Display Articles Categories Manager

Expected result

The Associations column should display.

Actual result

No Associations column is displayed.

if ($component instanceof AssociationServiceInterface)
{
$assoc = $component->hasAssociationsCategorySupport();
return $assoc;
Copy link
Member

@carlitorweb carlitorweb Jun 8, 2018

Choose a reason for hiding this comment

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

[CS] Add an empty line before the return

@@ -326,15 +327,22 @@ public function getAssoc()
if (!$assoc || !$component || !$cname)
{
$assoc = false;
return $assoc;
Copy link
Member

@carlitorweb carlitorweb Jun 8, 2018

Choose a reason for hiding this comment

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

[CS] Add an empty line before the return

@@ -1281,15 +1284,22 @@ public function getAssoc()
if (!$assoc || !$component || !$cname)
{
$assoc = false;
return $assoc;
Copy link
Member

Choose a reason for hiding this comment

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

[CS] Add an empty line before the return

if ($component instanceof AssociationServiceInterface)
{
$assoc = $component->hasAssociationsCategorySupport();
return $assoc;
Copy link
Member

Choose a reason for hiding this comment

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

[CS] Add an empty line before the return

@carlitorweb
Copy link
Member

I have tested this item ✅ successfully on b2f878b


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

@infograf768
Copy link
Member

@laoneo
Will test but I do not understand what is going on here. Can you explain how
\JLoader::register($hname, JPATH_SITE . '/components/' . $component . '/helpers/association.php');
may work when there is no such file for com_content as you moved and changed the file, its name and its class?

*
* @since __DEPLOY_VERSION__
*/
public function hasAssociationsCategorySupport()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you really need this method in the interface/trait? You can't just have code do the instanceof check without relying on an interface to be able to say you can do this instanceof check?

Copy link
Member Author

Choose a reason for hiding this comment

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

If every component which has associations and categories integrated, does also have associations for the category automatically, then yes. Wasn't sure about it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I just don't get what the difference is in using $component instanceof CategoriesServiceInterface versus $component->hasAssociationsCategorySupport() is all. Like why does this has method need to be part of an interface? Unless you've got a plan for being able to dynamically toggle this support it just feels like adding an interface method for the sake of having it.

Copy link
Member Author

@laoneo laoneo Jun 9, 2018

Choose a reason for hiding this comment

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

Actually the component has control to decide if categories associations is supported, what the trait does is just to add default behavior. As I said if we can guarantee that when a component implements the AssociationsServiceInterface and Categories that associations for categories is then also working for the component. Then I'm more that happy to remove it. I just don't know that detail. Perhaps @infograf768 can shed some light here.

@mbabker
Copy link
Contributor

mbabker commented Jun 8, 2018

may work when there is no such file for com_content as you moved and changed the file, its name and its class?

Simple. That code path won't execute in the case of com_content because of the checks above it. So if a component follows the service architecture, it'll get what it needs from that and return. If it doesn't, then it'll try to locate the class and file the "old" way.

@infograf768
Copy link
Member

@laoneo

I just don't know that detail. Perhaps @infograf768 can shed some light here.

What was done when was implemented com_associations was to make sure to define for each component its possible associations.

For example for com_contacts in the administrator/components/com_contact/helpers/associations.php the getType()` method (and also in getAssociations() and getItem() methods btw). Same for com_newsfeeds and also in its specific repo for weblinks.

If you look at com_menus similar file, you will see that category is not part of the code.

For com_content you moved the file and changed the class: similar methods are present in administrator/components/com_content/Helper/AssociationsHelper.php

My question above would have been more clear is I had asked why you decided to change the former structure for com_content ONLY as it was working perfectly OK and is still doing so for the other components. The Service Architecture is rather Tibetan for me ( https://en.wikipedia.org/wiki/Service-oriented_architecture ) as you may guess 😃 .
Or, if I understand well, it means you will also change the way it is done for the other components in core in the near future as it would look unclean to me.

@infograf768
Copy link
Member

BTW, patch works fine in admin everywhere where we display/edit categories.

@laoneo
Copy link
Member Author

laoneo commented Jun 9, 2018

Yes, the strategy is to bring com_content into a state where we can say it is the way to go for all extensions and then I will convert the rest. Don't worry about different set ups between core components for now.
What my question is, does have a component associations support for categories automatically when it implements associations for its entities and uses categories? Because then we can remove the mentioned check by @mbabker. Otherwise not.

@infograf768
Copy link
Member

does have a component associations support for categories automatically when it implements associations for its entities and uses categories?

As I said, if it is coded such in the component association helper, it will. Nothing is automatic. Not sure I understand what you exactly mean otherwise.

@laoneo
Copy link
Member Author

laoneo commented Jun 9, 2018

I'm not talking about how it is implemented but more about the set up. Lats try it differently. Can a component has associations and categories but not associations support for categories?

@infograf768
Copy link
Member

infograf768 commented Jun 9, 2018

Can a component has associations and categories but not associations support for categories?

If it has, it means that it is wrongly coded. There is no reason to do so and I don't know of any.
When a component has categories and support associations generally speaking, then associations SHOULD work for categories.

@laoneo
Copy link
Member Author

laoneo commented Jun 9, 2018

Because when I remove the check function now, it is not possible (or only with an effort which we can avoid now) to add it later when J4 is released. That's why I want to have confirmation on this.

@infograf768
Copy link
Member

TBH: if someone coding a multingual aware component which uses categories does not add the necessary code to also associate categories, this coder should just be eliminated from the surface of the Earth by any means, even illegal ones. 😃

@infograf768
Copy link
Member

@laoneo
Looks like we have some places where we need also some changes
The language filter plugin is an example
https://github.com/joomla/joomla-cms/blob/4.0-dev/plugins/system/languagefilter/languagefilter.php#L786-L794

@laoneo
Copy link
Member Author

laoneo commented Jun 9, 2018

Moved the helper function getAssociations to the extension helper class which is accessible through the service. This comes with the cost of a BC break. An alternative would be to introduce a new helper interface and a function in AssociationServiceInterface like:
public function getAssociationsHelper(): AssociationHelperInterface;.

Additionally all of this must be set from the service provider down to the component class. Not sure if we want to go that way. What do you guys think?

@infograf768
Copy link
Member

infograf768 commented Jun 9, 2018

This still does not work for multilingual associations between content categories for example (I guess also articles).
$cassociations is always NULL in this code

			if ($component instanceof AssociationServiceInterface)
			{
				$associations = $component->getAssociationsExtension()->getAssociationsForItem();
			}
			else
			{
				$cName = StringHelper::ucfirst(StringHelper::str_ireplace('com_', '', $option)) . 'HelperAssociation';
				JLoader::register($cName, JPath::clean(JPATH_COMPONENT_SITE . '/helpers/association.php'));

				if (class_exists($cName) && is_callable(array($cName, 'getAssociations')))
				{
					$cassociations = call_user_func(array($cName, 'getAssociations'));
				}
			}

We need $cassociations further down

					// Component association
					case (isset($cassociations[$i])):
						$language->link = Route::_($cassociations[$i] . '&lang=' . $language->sef);
						break;

@infograf768
Copy link
Member

infograf768 commented Jun 9, 2018

I tested changing in mod_languages as well as languagefilter
$associations = $component->getAssociationsExtension()->getAssociationsForItem();
to
$cassociations = $component->getAssociationsExtension()->getAssociationsForItem();
and it looks like it solves my issues., i.e. when no specific menu item to display an associated article or an associated category, we can switch OK (not so nice URLS but it works):

For example the display of a sub category
http://localhost:8888/newfolder/joomla40/fr/component/content/category/10-catfrenchsub
will give when using the lang switcher to en-GB
http://localhost:8888/newfolder/joomla40/en/component/content/category/11-catenglishsub

I am rather expecting (as I have a hidden List All Categories menu item for each language with alias categories) something like
http://localhost:8888/newfolder/joomla40/en/categories/11-catenglishsub in en-GB
and
http://localhost:8888/newfolder/joomla40/fr/categories/10-catfrenchsub in fr-FR

But I guess this is due to the "modern router" in 4.0 (as it does work fine in staging)

@Bakual
Copy link
Contributor

Bakual commented Jun 16, 2018

Hard to say. I've only rewritten it for Joomla 4.0 alpha from last year and the release is from january. There were quite a lot of major changes to the repo since then. I'm not constantely adjusting it to the latest changes in architecture :)

@laoneo
Copy link
Member Author

laoneo commented Jun 16, 2018

Try it with the j3 version as we should support them and we need to make sure these versions do work. Not one which is made for J4 alpha 1.

@Bakual
Copy link
Contributor

Bakual commented Jun 16, 2018

The J3 version likely doesn't work as it uses various deprecated functions.
My plan was to get it working in J4 and then "backport" whatever is needed to get a "transition" version that works both in 3.10 and 4.0.
But that obviously failed as I started to early 😄

@wilsonge
Copy link
Contributor

@laoneo can you fix the conflicts with this one so I can merge it please?

@laoneo
Copy link
Member Author

laoneo commented Jun 26, 2018

Merged upstream and fixed conflicts.

@richard67
Copy link
Member

richard67 commented Jun 30, 2018

I have tested this item ✅ successfully on 720f944

Tested on current 4.0-dev + this PR applied.
Associations column in categories manager is shown.
Associations tab in category edit view is shown.
Category associations can be added/changed/edited/used as it should be.


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

@infograf768
Copy link
Member

@wilsonge Can this be merged?

@infograf768
Copy link
Member

I have tested this item ✅ successfully on 720f944

May be incomplete, but without it in core we can't test associations at least for com_content.

Please, again, @wilsonge , merge.


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

@infograf768
Copy link
Member

RTC


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

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jul 13, 2018
@infograf768
Copy link
Member

Updated branch to allow merging.

@infograf768
Copy link
Member

Restarting drone.

@brianteeman
Copy link
Contributor

@infograf768 i have no idea what that error is but its been there for a while - i did ask what it was but got no response

@laoneo laoneo merged commit 77c731f into joomla:4.0-dev Jul 13, 2018
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jul 13, 2018
@laoneo laoneo deleted the j4/fix/associations branch July 13, 2018 12:57
@laoneo
Copy link
Member Author

laoneo commented Jul 13, 2018

Going to merge this one to move on with associations testing. Thanks to the testers. Please provide the routing patch in a new pr.

@infograf768
Copy link
Member

Thanks @laoneo
We certainly will need quite a few modifications/improvements specially for legacy but at least people working on multilang will have one possible test.

@laoneo
Copy link
Member Author

laoneo commented Jul 13, 2018

For legacy everything should work as before. We just extended it with services.

@infograf768
Copy link
Member

@laoneo

I still get issues in back-end com_associations for com_contact for example (who has its associations class in a different file/location and with a different type of class name).

Here I still get for single contact

Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/installmulti/joomla40/administrator/components/com_associations/Helper/AssociationsHelper.php on line 578
and
Undefined index: language in /Applications/MAMP/htdocs/installmulti/joomla40/administrator/components/com_associations/Field/ItemlanguageField.php on line 55
and
Call to a member function checkin() on null

Did not test but I guess it will be the same for newsfeeds.

@infograf768
Copy link
Member

I suggest to solve this one before modifying these components to use services.

@laoneo
Copy link
Member Author

laoneo commented Jul 13, 2018

Please open a new issue as I don't think it is related to services at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet