astridx/boilerplate

Why plural componen names?

Closed this issue · 9 comments

Just out of curiosity: why is the component name plural? Why 'com_foos' and not 'com_foo'?

There are some specific naming conventions that Joomla uses for its default "magic" implementation.

For example: By default, Joomla assumes, you have two views. One being the list view and one the single item view. The list view has the same name as the single one, but with a pluralization ( in most cases 's' at the end).

You can override this view names in your controllers constructor. The properties $this->view_list and $this->view_item hold this names. Have a look at JControllerForm to see what it does: https://github.com/joomla/joomla-cms/blob/73ae0235c25a489bac64613ba3d4837aec406fda/libraries/src/MVC/Controller/FormController.php#L136

This is not important for the name of the component. Since the component manages several (not just a single) elements, I have given it the name plural. Because this continues the Jooma logic - in my opinion.

Does this answer your question

Thanx for the elaborate explanation. I have done a few components and other extensions myself, so I was aware of the singular vs plural 'convention over code' thingy :)

My question was aimed at the name of the component.

Since the component manages several (not just a single) elements, ...

You are probably right in many or even most of the cases, but not necessarily all of them. After all, a component could manage just one element. Theoretically a component does not even have to mange any elements at all. It could just provide some arbitrary functionality like com_cpanel or com_joomlaupdate for instance.. Components can also manage more than just one type of element. So in my humble opinion, a component's name does not necessarily have to reflect the element type(s) it manages. com_content is a nice example of such a component, although one could argue that com_articles would have been a more appropriate name :)

Is this all very important? I think not. After all, the boilerplate has to be renamed anyway. The reason I brought this up, has to do with the boilerplate in PhpStorm. Even when I specify a singular name for the folder location, plural component names are being generated. That's somewhat annoying. Because I saw your name pop up in a discussion with Roland, who crafted the Joomla! 3 PhpStorm boilerplates, I thought the Joomla! 4 PhpStorm component boilerplate came from you. On second thought, that does not seem to be the case.

After all, the boilerplate has to be renamed anyway. The reason I brought this up, has to do with the boilerplate in PhpStorm. Even when I specify a singular name for the folder location, plural component names are being generated. That's somewhat annoying. Because I saw your name pop up in a discussion with Roland, who crafted the Joomla! 3 PhpStorm boilerplates, I thought the Joomla! 4 PhpStorm component boilerplate came from you. On second thought, that does not seem to be the case.

I do not know PhpStorm. Maybe that's why I don't fully understand the problem.

My idea is that I adapt the boilerplate for components. When I manage books I search for foo and replace it with book. For example, in one command (case sensitive), FooModel becomes BookModel and FoosModel becomes BooksModel. com_foos will be replaced with com_books, that's OK, isn't it?

I believe @roland-d used an early version of this repo for PHPStorm. in the meantime i have expanded things and made adjustments to changes in joomla 4.

What do you suggest?

I do not know PhpStorm.
PhpStorm is a great IDE with cool Joomla! support. It improved my PHP productivity enormously. It may be worth your while to check it out :)

Maybe that's why I don't fully understand the problem.
Maybe 'problem' is overstated. 'Nuisance' might be more appropriate.

My idea is that I adapt the boilerplate for components. When I manage books I search for foo and replace it with book. For example, in one command (case sensitive), FooModel becomes BookModel and FoosModel becomes BooksModel. com_foos will be replaced with com_books, that's OK, isn't it?
It definitely sounds OK and it's exactly how I used Roland's boilerplates before they were integrated into PhpStorm. But now days PhpStorm allows you to create new projects based on one of the Joomla! boilerplates. PhpStorm then somehow takes care of the renaming, which is quite cool and productive. But like I mentioned, my singular project name is turned into plural component names, So if I specify my new project as '[some path]/mycomponent' (singular), PhpStorm creates '[some path]/components/com_mycomponents' and '[some path]/administrator/components/com_mycomponents' (plural) . That's not what I want. It's up to me to decide if my component name should be singular or plural, not up to PhpStorm.

As long as your boilerplates are only available from your repo and not as new project boilerplates in PhpStorm, it is not an issue. But if they eventually do wind up in PhpStorm, I would appreciate it appreciate it if component names are not to be tampered with and the singular/plural rules only apply to the appropriate MVC elements.

As far as your current component boilerplate is concerned, there is a minor issue. Suppose I want to rename 'com_foos' into 'com_stuff' but my MVC elements into 'thing', so that 'FooModel' becomes 'ThingModel', 'FoosModel' becomes 'ThingsModel', etc. Currently that's quite a challenge, because if I rename 'foo' into 'stuff', both the component and the MVC elements will be renamed. This might be prevented by differentiating between component name and MVC element names. Maybe something like 'foo_component' and 'foo_item(s)'. It would make it easy peasy to rename one without interfering with the other. Obviously there is a downside: you will have to do two renames instead of just the one.

By the way, I don't try to be judgemental about your boilerplates. On the contrary. I haven't even looked at Joomla! 4 yet, let alone try to develop an extension for it. From what I have seen, there is a lot I must learn all over again. That's exactly how I ended up in your boilerplate repo :) So I very much appreciate and respect the work you put into it.

@pjdevries Thanks for your suggestions. When I check the next time, if every branch/part is still working, I will rethinking the renamin/naming.

For this I leave this open.

As I wrote I do not know what Roland plans with PHPStorm.

Does anyone ever know what Rolan'd plans are? :D

Even Roland doesn't know what his plans are 😃

I believe @roland-d used an early version of this repo for PHPStorm. in the meantime i have expanded things and made adjustments to changes in joomla 4.
What do you suggest?

PhpStorm uses the Joomla boilerplate repo breanch 2019.3 Yes, I used a copy of this repo. Ideally I would like to see this branch updated for the j4component folder, that way everybody using PhpStorm can enjoy the up-to-date codebase.

If it is OK with you Astrid, we update the boilerplate code with your new changes.

@roland-d

If it is OK with you Astrid, we update the boilerplate code with your new changes.

That's okay for me. Would it help you if I rename the component? I didn't understand exactly what @pjdevries meant by this.

All changes are in the branch tutorial. But you can see that I'm building up step by step (branch t0, t1, t2 ..). If you don't like everything, you can also use "previous" branches.

I am currently working on the template, but so far there are only the positions (I like to make it step by step too). So it is work in process.

I would also like to switch everything to use https://github.com/Digital-Peak/DPDocker. At the moment I'm still struggling with the basics of docker and not brave enough to change everything. If I'm brave enough, the directory structure could change a bit. Would that be a problem for you? At the moment I have set up everything so that the directory structure is like in Joomla. This makes it easier to symlink. DPDocker creates a zip file like the one here https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Developing_a_Basic_Component

I'll close here. I would like to keep the name as it is. If you like, you can change the name using the file https://github.com/astridx/boilerplate/blob/t43/duplicate.sh.