joomla / joomla-cms

Home of the Joomla! Content Management System
https://www.joomla.org
GNU General Public License v2.0
4.79k stars 3.65k forks source link

[com_fields] Add options for fields rendering #13800

Closed SemaphoreOxalis closed 7 years ago

SemaphoreOxalis commented 7 years ago

Steps to reproduce the issue

When you need different rendering for same fields type (text for example)

Expected result

in templates style, need to be able to create fields override and new templates files in each fields configuration we need to have a template selector

Actual result

no possibility to get multiple renders of a same field type without coding (override+testing the id)

System information (as much as possible)

J3.7A2 PHP7

Additional comments

If this could be achive in other way sorry for this post.

Bakual commented 7 years ago

If it can be achieved using CSS, then you can already apply a CSS class for the edit form and the site rendering indivually.

If you need different templates (meaning not appearance but different HTML) for the same type of field (eg text), then my question would be why. What exactly is the usecase here. So I can think of a solution that may work. Having a layout selector for the field rendering does sound a bit like overengineering to me. Especially since a plugin may also contain more than one field type.

mbabker commented 7 years ago

It's a general thing with Joomla's form implementation. You can only style all text inputs one way or have some complex conditionals in the form/layout for per-field things (or just subclass it and change the field type). Without re-engineering the rendering engine to look for all sorts of different possibilities for a layout in a form (look up Symfony's form blocks as an example), it's not something that can be fixed.

SemaphoreOxalis commented 7 years ago

Yeah of course I talk about html not css modification ;-) @Bakual It's not because you do'nt see any application of a function that other ppl d'on t see somes ;-) Somes examples :

I know all of this because We (Web agency) already used these tricks with other CCK, plug-ins etc for our templates.

@mbabker : so plug-in overide can't be used as modules/component etc ? And yes we can use id detection for examle for changing the results.

After some try I'm very suprised the way the tmpl of fields plug-in render the output : The label is not a part of the rendering tmpl ! It seems the MVC is weirdly used there...

Last thing, Joomla offer the possibility to easily ovreride component, modules and layout but not plug-in in the template->style section. With a "simple" detection of the tmpl folder joomla could offer this don't you think ?

mbabker commented 7 years ago

Plugins which use the appropriate API in JPluginHelper for output (remember not all plugins are output based) do support layout overrides. Likewise, anything using JLayoutFile will too. If fields is doing something which makes that not work then it's a bug in the fields code.

With that said though, if fields is using JFormField objects for rendering, then the option basically boils down to override the JFormField output for that type or no override at all. Same as "normal" form use. It's not much different than components and modules anyway (those support alternate layout parameters which is a different thing, but you can't override the default.php layout for one view and set one menu item to use that with another using an unoverridden default.php file).

To be perfectly honest, I'm not sure it's worth adding the amount of complexity being called for here in the rendering system as a whole. Because if you do it in one place you're going to have to do it for everything. As pointed out, you can already accomplish this for the most part by making checks in a layout for certain data and wrapping things in if/else conditions, so it is possible, but this isn't a feature that's easy to either implement into the code system or offer a UI selection for.

SemaphoreOxalis commented 7 years ago

I understand but there is an issue for me : the actual render plug-in don't have all the HTML rendering work. For example It seems impossible without core hack to change the dd->span+span rendering... or i miss something ?

mbabker commented 7 years ago

The base FieldsPlugin class only scans for layouts in the templates directory for some method that I assume lets you choose a layout, but when rendering them it uses the correct JPluginHelper::getLayoutPath() API to look for the layout (which supports template overrides). So it doesn't support the alternate layout concept components and modules use, if that's what your issue is, but it does support template overrides.

laoneo commented 7 years ago

I think the only way you can do is to make a template override and add some if conditions to it like

if($fields->assigne_catd_id == 33) {//then do something special}
SemaphoreOxalis commented 7 years ago

Yeah I already get this. My issue is the override in the tmpl folder does'nt render the whole HTML ! When this file is called a lot of html is alredy buffered.

laoneo commented 7 years ago

The tmpl's in the plugins are there only for rendering the value. The container for the automatic display is rendered in JLayouts in https://github.com/joomla/joomla-cms/blob/staging/components/com_fields/layouts/fields/render.php and https://github.com/joomla/joomla-cms/blob/staging/components/com_fields/layouts/field/render.php.

SemaphoreOxalis commented 7 years ago

Yeah I've seen thsese files. Why separating the rendering ? These files can't be override because not a Joomla/MVC structure ? The whole thing don't seems to be coded as "joomla usual" Sorry I know you are at the origin and my lvl as coder is low but something sound wrong in the process of rendering like if theses custom fields have to used as they are and nobody have to modify them. For "playing" with this new toy we need more than a fixed rendering.

laoneo commented 7 years ago

For sure they can be overriden, it's a built in Joomla feature called JLayouts. Place the file layouts/fields/render.php into the folder templates/{your template}/html/layouts/com_fields/fields/render.php and do your changes. Joomla is full of overrideable layouts https://github.com/joomla/joomla-cms/tree/staging/layouts. They are there for exact such a use case we have in com_fields.

SemaphoreOxalis commented 7 years ago

Ok they are layout but not in the layout root folder. Maybe they could be put there for adding the overriding with the GUI (templates->style->overrides) Joomla have a lot of override posibility (maybe we could override helpers/controllers too !) it seems logical to use as much as possible the "new" GUI ?

laoneo commented 7 years ago

Ok they are layout but not in the layout root folder.

Becasue they are com_fields related and not globally for Joomla.

maybe we could override helpers/controllers too

You can override this classes already with some PHP knowledge. But I don't recommend to do it.

laoneo commented 7 years ago

So can we close this issue then as you can do your overrides?

SemaphoreOxalis commented 7 years ago

Yes I can do my override (from the beginning of this topic) but I post this PR for add some enhancment on this overrides so before closing you confirm :

If not of these are possible Joomla! Documentation team have to prepare some documentation on this and documentation on how to call spcific files in a com_content view as well.

Bakual commented 7 years ago

adding a alternative layout selector for each fields is not possible

Plugins are global things, there are no instances of a plugin like there are for modules or component views. So the same approach doesn't work here. You would have to hack something into the fields to allow selecting a different layout. So it's not impossible but needs some extra code, there is no such functionality present which could be reused. On the other hand, you can already do it in your template override of the field by using sublayouts and a toggle based on the ID or a CSS class. Whatever you like.

adding the possibility to create an override (of the plugin+component layout) from the overrides Joomla GUI is not possible as well ?

If someone codes it, everything is possible. I just don't know how that list of possible override locations is compiled. Maybe it's an easy thing, maybe not. I just don't know.