Skip to content

Conversation

@laoneo
Copy link
Member

@laoneo laoneo commented Apr 1, 2022

Pull Request for pr #37398.

Summary of Changes

Introduces a helper factory aware interface and converts the articles news site module to services. For backwards compatibility a new helper class was introduced and the old abstract one got deprecated.

Testing Instructions

  • Create an article
  • Create an Articles - Newsflash module

Actual result BEFORE applying this Pull Request

It works.

Expected result AFTER applying this Pull Request

It works.

@laoneo laoneo changed the title [4.2]Introduce helper factory aware interface and convert news module to services [4.2] Introduce helper factory aware interface and convert news module to services Apr 1, 2022
@laoneo laoneo mentioned this pull request Apr 1, 2022
@laoneo laoneo force-pushed the j4/modules/articlenews branch from 9e16db4 to 01c9bc8 Compare April 1, 2022 12:20
@dgrammatiko
Copy link
Contributor

@laoneo please add a line in the xml like <element>mod_article_news</element> so the module could be installable. Also remove the old file mod_article_news.php as it is moved inside the src folder, etc

@laoneo
Copy link
Member Author

laoneo commented Apr 1, 2022

@laoneo please add a line in the xml like <element>mod_article_news</element> so the module could be installable.

No module has such an element tag. Why should I add it?

@dgrammatiko
Copy link
Contributor

Because #33182

@laoneo
Copy link
Member Author

laoneo commented Apr 1, 2022

This should be enough 13c1cf6. #33182 is basically obsolete as it would already work without it, see here #36042 (comment). Just one entry needs a module attribute, doesn't mater which one.

@dgrammatiko
Copy link
Contributor

That's an undocumented hack and probably shouldn't be promoted! The docs are clear:
Screenshot 2022-04-01 at 15 33 18

https://docs.joomla.org/Manifest_files

@laoneo
Copy link
Member Author

laoneo commented Apr 1, 2022

Where do you see that in action the element tag? None of my extensions does have that element and the code which uses any of the file elements is there since Joomla 1.7, which do extensions use since ages. Your pr was for 4, so I guess you added a new behavior. I wouldn't call the original way a hack. Anyway, lets open an issue where we can discuss this in more deep if you want to get that sorted.

@dgrammatiko
Copy link
Contributor

I think the project should have one unique way for defining the element especially for the namespaced extensions. When I did that PR (that was before your discovery?) I thought that normalising the optional element field and move it to the required ones would be self explanatory and also if that was to be standardised then the name field could be left free to be any type of string (translatable or not). This was somehow bite me with 4.1 as the templates name field is not explicitly defined correctly, even for the core ones, (should be tmpl_cassiopeia and not cassiopeia). Anyways either keep adding attributes to a folder or explicitly asking for an element field should be standardised and needs to be noted in the docs. People shouldn't reverse engineer code to figure out how things are working. End of off topic comments

@laoneo
Copy link
Member Author

laoneo commented Apr 1, 2022

Show me one extension which exists before Joomla 4 was released that uses the element tag.

@dgrammatiko
Copy link
Contributor

I can't, apart from the one I edited in that PR but maybe this Unit can:

public function testgetElementFromElementTag()
{
$xml = file_get_contents(JPATH_ADMINISTRATOR . '/modules/mod_quickicon/mod_quickicon.xml');
// Insert a Joomla 4 <module/> tag
$xml = str_replace('<name>mod_quickicon</name>', '<name>mod_quickicon</name><element>mod_quickicon</element>', $xml);
$xml = simplexml_load_string($xml);
$this->moduleAdapter->setManifest($xml);
$this->assertNotNull($this->moduleAdapter->manifest);
$this->assertEquals('mod_quickicon', $this->moduleAdapter->getElement());
$this->assertEquals('somethingElse', $this->moduleAdapter->getElement('somethingElse'));
}

@laoneo
Copy link
Member Author

laoneo commented Apr 1, 2022

Ok, we leave the pr as it is for now.

@Ruud68
Copy link
Contributor

Ruud68 commented Apr 2, 2022

in your commit you have created a new ArticleNews.php in the src/Helper directory.
Will that replace the ArticleNewsHelper.php (as that file now only has the deprecated message)?

Asking because if that is the case, com_ajax is broken as it hardcoded looks for a module helperfile ending in 'Helper': so ArticleNewsHelper in this example.

@laoneo
Copy link
Member Author

laoneo commented Apr 2, 2022

@Ruud68 you are right. Reverted to the original helper file and made it none abstract and added a new getArticles function which is none static. What do you think?

On the other side also like this it still doesn't work with com_ajax, because the function needs to end with "Ajax" https://github.com/joomla/joomla-cms/blob/4.1-dev/components/com_ajax/ajax.php#L99.

@Ruud68
Copy link
Contributor

Ruud68 commented Apr 2, 2022

@Ruud68 you are right. Reverted to the original helper file and made it none abstract and added a new getArticles function which is none static. What do you think?

On the other side also like this it still doesn't work with com_ajax, because the function needs to end with "Ajax" https://github.com/joomla/joomla-cms/blob/4.1-dev/components/com_ajax/ajax.php#L99.

Cool, I think this will work. As for the Ajax in the function name that is not the issue. The issue was that the helperfile wasn't loaded. When that is loaded the method is called (ending in 'Ajax') so in the helper file you need to have that function otherwise you will get an error.

This is only relevant if you have a module that will service com_ajax requests because they have functionality that relies on that (which the Joomla core modules do not do)

What still 'bugs' me is that a module following this new approach will not work on J4.1 / 4.0.
For me as extension dev that complicates things as with every dependency on a Joomla version the 'market share' will drop :S
just saying :) should not hold back improvements.

@laoneo
Copy link
Member Author

laoneo commented Apr 3, 2022

If you leave the old module file from J3 and load the helper the same way in the dispatcher as the quickicon module, then you have compatibility down to J3.

@laoneo
Copy link
Member Author

laoneo commented Apr 4, 2022

@Ruud68 can you give this one here a test?

@Ruud68
Copy link
Contributor

Ruud68 commented Apr 5, 2022

@laoneo so just set up a new nightly 4.2 environment (april 5th), pulled this PR and copied the files over the new test environment.
when going to [domain]/index.php?option=com_ajax&module=articles_news&method=test&format=raw

I get the message: RuntimeException: The file at mod_articles_news/helper.php does not exist.

have not tried to troubleshoot this

@laoneo
Copy link
Member Author

laoneo commented Apr 5, 2022

Did you add the function testAjax to the helper?

@Ruud68
Copy link
Contributor

Ruud68 commented Apr 5, 2022

Hi, that is not necessary. com_ajax first tries to load the helper and when it does then it tries to load the method.
The error I got is for loading the helper > so it didn't get to the loading of the method (testAjax)

@laoneo
Copy link
Member Author

laoneo commented Apr 5, 2022

It does, but when the helper has no such function it tries the old way and when that doesn't succeed, it throws the old error message. You can see it here, it sets the result to null and doesn't throw an error message. If you want to add there an error, then a new pr is required.
Important for this pr is that you test the module on the ordinary way.

@Ruud68
Copy link
Contributor

Ruud68 commented Apr 5, 2022

sorry about that, you are completely right.
So the module works, the helper works and when adding testAjax com_ajax also works for modules in this way!

@Ruud68
Copy link
Contributor

Ruud68 commented Apr 5, 2022

I have tested this item ✅ successfully on b081abe


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

@richard67 richard67 added the PBF Pizza, Bugs and Fun label Apr 22, 2022
@SumCompanyInc
Copy link

I have tested this item ✅ successfully on 3ee5c32


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

1 similar comment
@Ruud68
Copy link
Contributor

Ruud68 commented Apr 26, 2022

I have tested this item ✅ successfully on 3ee5c32


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

@richard67
Copy link
Member

RTC


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

@richard67 richard67 removed the PBF Pizza, Bugs and Fun label Apr 26, 2022
@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Apr 26, 2022
@roland-d roland-d merged commit 0aba173 into joomla:4.2-dev Apr 26, 2022
@roland-d roland-d deleted the j4/modules/articlenews branch April 26, 2022 18:37
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Apr 26, 2022
@roland-d
Copy link
Contributor

Thanks everybody

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.

10 participants