Skip to content

Conversation

@thednp
Copy link
Contributor

@thednp thednp commented Sep 30, 2020

Pull Request for Issue #30272.

Summary of Changes

As discussed in the #30272 report, Joomla does not support namespaced templates, this commit solves that.

  • the create() method now checks for namespaced template extension types
  • the getNamespaces() method properly recognize Administrator and Site templates; in addition, it will look for templateDetails.xml file instead of extensionName.xml and read the designated namespace (Line 182)

Testing Instructions

In order to enable namespace for templates, here are the few steps, we'll use the default site template:

  • open site/templates/cassiopeia/templateDetails.xml and add between <description> and <files> the following
<namespace path="src">Joomla\Template\Cassiopeia</namespace>
  • delete site/administrator/cache/autoload_psr4.php
  • login to your site/administrator
  • open the newly created site/administrator/cache/autoload_psr4.php, the last element of the return object should be
'Joomla\\Template\\Cassiopeia\\Site\\' => [JPATH_SITE . '/templates/cassiopeia/src']
  • optional: create a custom field in site/templates/cassiopeia/src/Field folder and add it to the templateDetails.xml along with addfieldprefix="Joomla\Template\Cassiopeia\Site\Field" attribute added to the parent <fieldset>
  • optional try and call the newly added custom field from your namespaced template into a module/plugin, test it out

Actual result BEFORE applying this Pull Request

The namespacemap.php class had no support for Site Templates / Administrator Templates. addfieldpreffix couldn't be used with template defined custom fields.

Expected result AFTER applying this Pull Request

Site Templates / Administrator Templates can be developed with namespace features.

Documentation Changes Required

Yes. (I wish I knew where)

Questions

  • should I commit this change to the 4.1-dev branch as well?
  • should I commit this change to the staging branch? If yes, where is the namespacemap.php file?

Pull Request for Issue #30272.

### Summary of Changes
As discussed in the #30272 report, Joomla does not support namespaced templates, this commit solves that.

* the `create()` method now checks for namespaced `template` extension types
* the `getNamespaces()` method properly recognize *Administrator* and *Site* templates; in addition, it will look for `templateDetails.xml` file instead of `extensionName.xml` and read the designated namespace (Line 182)

**Other change**
* replaced `defined('_JEXEC') or die;` with `defined('JPATH_PLATFORM') or die;`, perhaps this change was also expected? Either way, it was my best guess.

### Testing Instructions
In order to enable namespace for templates, here are the few steps, we'll use the default site template:
* open `site/templates/cassiopeia/templateDetails.xml` and add between `<description>` and `<files>` the following
```markup
<namespace path="src">Joomla\Template\Cassiopeia</namespace>
```
* delete `site/administrator/cache/autoload_psr4.php`
* login to your `site/administrator`
* open the newly created `site/administrator/cache/autoload_psr4.php`, the last element of the return object should be
```
'Joomla\\Template\\Cassiopeia\\Site\\' => [JPATH_SITE . '/templates/cassiopeia/src']
```
* *optional*:  create a custom field in `site/templates/cassiopeia/src/Field` folder and add it to the `templateDetails.xml` along with `addfieldprefix="Joomla\Template\Cassiopeia\Site\Field"` attribute added to the parent `<fieldset>`
* *optional* try and call the newly added custom field from your namespaced template into a module/plugin, test it out


### Actual result BEFORE applying this Pull Request
The `namespacemap.php` class had no support for Site Templates / Administrator Templates. `addfieldpreffix` couldn't be used with template defined custom fields.


### Expected result AFTER applying this Pull Request
Site Templates / Administrator Templates can be developed with namespace features.


### Documentation Changes Required
Yes. (I wish I knew where)

### Questions
* should I commit this change to the `4.1-dev` branch as well?
* should I commit this change to the `staging` branch? If yes, where is the `namespacemap.php` file?
@SharkyKZ
Copy link
Contributor

SharkyKZ commented Sep 30, 2020

This doesn't work well because templates support copy function.

@thednp
Copy link
Contributor Author

thednp commented Sep 30, 2020

@SharkyKZ what do you suggest?

@thednp
Copy link
Contributor Author

thednp commented Sep 30, 2020

@SharkyKZ I can confirm, using the template defined custom fields in the options of a plugin doesn't work, so please what do we need to change to make it work? I really think this is important.

@SharkyKZ
Copy link
Contributor

SharkyKZ commented Oct 1, 2020

This works fine, just not when copying templates. If it doesn't work for you at all, the issue must be elsewhere.

@thednp
Copy link
Contributor Author

thednp commented Oct 1, 2020

What do you mean "when copying templates" please? You mean multiple template styles? If that's what you mean, I tested that as well, no issue at all.

@SharkyKZ
Copy link
Contributor

SharkyKZ commented Oct 1, 2020

I mean copying the template using Copy Template button.

@thednp
Copy link
Contributor Author

thednp commented Oct 1, 2020

Well, after a Copy Template I'm getting some strange errors:

JInstaller: :Install: File does not exist site\tmp\template_copy_5f7581c597a87\Field
Template Install: Could not copy files from the files source.

Error installing template
Unable to install new template from temporary folder.

After correcting the folder structure, (I moved Field folder inside src and updated templateDetails.xml) (facepalm) the installation went fine. I think I understand your concern, the new template still keeps the old namespace for it's custom fields and other functionality, if you delete the original template, the new template will throw lots of crits.

I'm now going forward with testing custom fields defined with modules and see how they work across extensions, I suspect it's going to work the same as for the templates (template defined custom fields don't work in plugin options) given both types have same namespace logic.

@SharkyKZ
Copy link
Contributor

SharkyKZ commented Oct 1, 2020

Modules don't have the same issue because there's no function for copying module extensions.

@thednp
Copy link
Contributor Author

thednp commented Oct 1, 2020

Yea, I can confirm, custom fields defined within modules work across extensions. I don't know how to make it work for templates but at this point, I'm happy the template defined fields work inside its back-end panel.

I'm now going forward with testing if Helper from src folder work properly in template index.php and html + html/layouts overrides. If this test is successful, I think we're good. Would you agree?

Obviously we need to document this limitation if this change goes through.

@SharkyKZ
Copy link
Contributor

SharkyKZ commented Oct 1, 2020

No. This is not acceptable in its current state. Eventually we could remove copy template functionality completely. But until then I suggest to use a plugin for registering template namespaces.

@thednp
Copy link
Contributor Author

thednp commented Oct 1, 2020

In my view adding a plugin to host libraries, helpers, fields and other resources is just like a template framework, which is not the point I'm trying to make. I was initially a template developer, I used to work with all these frameworks, but after some more experience I came to the point where templates can do anything a framework like T3/T4/Helix can do, and without the troubles of maintenance. I want to avoid bloatware and corruptible code as much as possible, clearly Joomla can & should do without.

On the other side, I stand by you. I really hope we implement this feature, I think we can bring back people to Joomla with awesome templates.

@thednp thednp changed the title Add namespace support for templates [4.0] Add namespace support for templates Oct 1, 2020
@thednp
Copy link
Contributor Author

thednp commented Oct 2, 2020

@SharkyKZ what is the resolution for this issue?

@SharkyKZ
Copy link
Contributor

SharkyKZ commented Oct 2, 2020

My opinion hasn't changed since the last comment.

@thednp
Copy link
Contributor Author

thednp commented Oct 2, 2020

Would be a pity to have Joomla 4 without namespaced templates.

@thednp
Copy link
Contributor Author

thednp commented Oct 5, 2020

Please who else has a say in this? Is this feature never gonna come to Joomla 4?

@brianteeman, @PhilETaylor @eddieajau @wilsonge ?

@PhilETaylor

This comment was marked as abuse.

@thednp
Copy link
Contributor Author

thednp commented Oct 5, 2020

I was looking at commit authors and figured you could have a say in it. Thanks for your input.

What is more important for Joomla: namespaced templates or copy template functionality?

@zero-24
Copy link
Contributor

zero-24 commented Oct 5, 2020

Well what holds us back merging what is in this PR and check on the copy feature whether that is a namespaced template and than point to documentation how to copy such templates. I would say this would be a fair compromise what does others think?

@thednp
Copy link
Contributor Author

thednp commented Oct 5, 2020

@zero-24 for some reason, the classes defined within namespaced template (mostly fields) cannot autoload in plugins or other extensions, this is, as @SharkyKZ pointed out, related to copy template functionality. I can confirm with my tests.

@zero-24
Copy link
Contributor

zero-24 commented Oct 5, 2020

@zero-24 for some reason, the classes defined within namespaced template (mostly fields) cannot autoload in plugins or other extensions, this is, as @SharkyKZ pointed out, related to copy template functionality. I can confirm with my tests.

Yes that is the reason i suggested to not allow namespaced templates to be copied than via the GUI. So both ways are possible the only disadvantage for namespaced templates is that there is no simple copy feature anymore from the backend for the reasons pointed out here.

@thednp
Copy link
Contributor Author

thednp commented Oct 5, 2020

Sounds good for me. Imma make a great template without any framework, and you will love it :)

@SharkyKZ
Copy link
Contributor

SharkyKZ commented Oct 5, 2020

What is more important for Joomla: namespaced templates or copy template functionality?

Copy function could be removed completely. Maybe too late for 4.0. But certainly in 5.0.

And templates can already be namespaced, but without using the namespace mapper.

@zero-24
Copy link
Contributor

zero-24 commented Oct 5, 2020

What is more important for Joomla: namespaced templates or copy template functionality?

Copy function could be removed completely. Maybe too late for 4.0. But certainly in 5.0.

And templates can already be namespaced, but without using the namespace mapper.

Why should we not allow using the namespace mapper + add that condition to the copy feature?

@SharkyKZ
Copy link
Contributor

SharkyKZ commented Oct 5, 2020

I didn't say we shouldn't. Just clearing the misconception that templates can't be namespaced already.

@zero-24
Copy link
Contributor

zero-24 commented Oct 5, 2020

I didn't say we shouldn't. Just clearing the misconception that templates can't be namespaced already.

Ok so this (merging here and add a condition to the copy feature) would be a good way to go forward right?

@richard67
Copy link
Member

Back to pending due to merge conflicts after rebase.


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

@richard67 richard67 added Conflicting Files PR-4.2-dev Ready to take over This is an abandoned feature which can be taken over by another person to finish it. and removed Ready to take over This is an abandoned feature which can be taken over by another person to finish it. labels Feb 1, 2022
@richard67
Copy link
Member

@thednp We had to rebase the PR to 4.2-dev, which has caused merge conflicts now.

As I can see you have meanwhile deleted the branch for this PR. Does that mean you won't continue this PR and someone else shall take it over? Or are you still available to work on it?

In the latter case you would have to restore the patch-2 branch and update it to latest 4.2-dev. We could help with that if necessary. Or you redo the PR with a new branch for 4.2-dev.

Just let us know if you continue or someone shall take it over.

Thanks in advance.

@dgrammatiko
Copy link
Contributor

It's a pity that this didn't make it with the new mode templates...

@thednp
Copy link
Contributor Author

thednp commented Feb 1, 2022

@richard67 my Joomla PRs, especially the color-picker one, have taken so much of my time I don't even know anymore. @dgrammatiko you referring to child templates? Is this PR crucial for that feature?

@dgrammatiko
Copy link
Contributor

@thednp child templates don't depend on the namespaces but it would have been great to have them right from the start fro the new templates that support child templates. It will happen at some point because there's a need for namespaces...
Also sorry that the cooler picker is still not merged and the project has to rely on an abandoned/non maintained script for the picker... 🤷‍♂️

@thednp
Copy link
Contributor Author

thednp commented Feb 1, 2022

I hope I will have news for you @dgrammatiko soon, I finally found some time and context to learn about custom element slots and I'm planning to release an improved color-picker version to npm (you will also be mentioned), so anyone interested in implementing it in Joomla / Wordpress etc should have a painless transition from what ever color-picker to possibly the best color picker you could ever dream of.

As a side note, I wish these improvements would have been implemented into J4.0 already. We're talking small bits of QOL that could make a big difference for our users. Lots of wasted potential.

@laoneo
Copy link
Member

laoneo commented Feb 1, 2022

The only problem which blocks namespaces for templates is the copy function. Right? Can this be removed with child templates?

@dgrammatiko
Copy link
Contributor

dgrammatiko commented Feb 1, 2022

Can this be removed with child templates?

You cannot (by design) copy neither a parent or a child template, so this was never an issue

For a parent template the toolbar is like:
Screenshot 2022-02-01 at 17 20 21

For a child template is like:
Screenshot 2022-02-01 at 17 20 30

Both toolbars missing (on purpose, because I had big hopes for this PR) the Copy Template button. Anyways maybe in 4.2...

@laoneo
Copy link
Member

laoneo commented Feb 1, 2022

I mean the whole copy template function
image

@dgrammatiko
Copy link
Contributor

dgrammatiko commented Feb 1, 2022

I mean the whole copy template function

The button exists only for Legacy templates because nobody wanted to break B/C in a minor. For the templates that either support child templates or are child templates the button is not available (I've updated my previous comment). Also the idea was to have them only in the new mode, eg the template needs to support child templates to be able to use namespaces (not in this PR, maybe thus the confusion)

@dgrammatiko
Copy link
Contributor

@laoneo what I'm trying (probably poorly) to say is that the changes in this PR from the libraries/namespacemap.php is all it's needed for the templates that support child templates.

@laoneo
Copy link
Member

laoneo commented Feb 1, 2022

Partially agree as I would like to see a bootTemplate function which uses the service provider as well.

@dgrammatiko
Copy link
Contributor

Ok, where do we disagree?

@laoneo
Copy link
Member

laoneo commented Feb 1, 2022

@laoneo what I'm trying (probably poorly) to say is that the changes in this PR from the libraries/namespacemap.php is all it's needed for the templates that support child templates.

No disagree, here I would go one step further.

@dgrammatiko
Copy link
Contributor

No disagree, here I would go one step further.

Can you explain that step?

@laoneo
Copy link
Member

laoneo commented Feb 25, 2022

To load a template by service provider.

@dgrammatiko
Copy link
Contributor

To load a template by service provider.

@laoneo could you write some pseudo code for the provider? I struggle to figure out how the boot process would look like (I mean not for a helper, that would be probably the same as it is for modules but for the entry points like index.php, component.php, etc). Maybe I'm missing the file/folder structure that such templates should follow...

@HLeithner HLeithner changed the base branch from 4.2-dev to 4.3-dev October 21, 2022 10:20
@HLeithner
Copy link
Member

Since the original branch has been deleted I recreated the Pull request and updated it to a more proper version at #39011

I'm closing this for now, thanks

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.