[#33415] [imp] layout improvements and base system for fields#3231
[#33415] [imp] layout improvements and base system for fields#3231phproberto wants to merge 20 commits intojoomla:stagingfrom phproberto:layouts-field
Conversation
|
I owe you so so so many beers :D :D |
libraries/cms/form/field/user.php
Outdated
There was a problem hiding this comment.
Whilst it should be impossible to get here I think we should be returning an empty string here rather than null - as people often echo the contents of the input
There was a problem hiding this comment.
You can echo a returned null.
There was a problem hiding this comment.
For semantic reasons, wouldn't it make sense to return false? I do recall there being some discussion about this in the past and I think we currently have a mix of both.
|
I'll review travis errors tomorrow 🎯 |
|
I think you forgot to include the layout for the vote plugin? Vote doesn't show currently. About the stats collecting. If I saw this correct you're doing that always? Wouldn't it make sense to only do that when debug is enabled? Otherwise we just generate overhead here for no reason. About the prefix, I'm not sure I understand the intention here:
As I understand it, the prefix (as well as suffixes, autolanguage and others) is set by the extension. How does that help a template? Or is that something a template could set globally? Generally speaking, while I like what you did here, I fear this PR got a bit big which makes it harder to test. Especially since there are so many places one would have to test things. If you could for example split it up into a part for the basic enhancement (maybe with the plugin) and another for the JForm part, that would help. If the JForm one does depend on the basic one, it may be better to do it incrementally. |
|
Would we be able to integrate into the JForm class a method to add a prefix/suffix to the layouts for all form fields? So if I want to say load bootstrap 2/3 classes or even frameworky. I can load that for all fields in the form instead of having to override the layout path for each individual field? Just to be an arse :D |
|
Sorry I forgot to answer before closing the PR. Thanks for checking it. @Bakual :
Yes. I forgot the vote layout. Thanks for pointing it. I added it before closing this to be sure I have all ready here.
It's not a overhead to store 10 vars (counters) in an array. There is no performance issue for having it enabled it just increases counters and get microtimes. Maybe in the future if the system ges complex it will make sense. I invite you to waste your time doing performance tests. About prefixes, suffixes: they are there for anybody that wants to use them. Of course you have to use the tools in a good way. That's the main reason to have now the layouts debug. The caching system will also help. I'll appreciate that the next time I propose something (with the tools to test it) you waste your time testing it before suggesting issues.
This is something that needed to go together. The system was done to be a first step into the right direction and to start using the tools in the right way at the same time. 3.3 release was next week and you knew it. I know it's not something easy to test. It wasn't to code and double check it. That's why I closed the PR. I'm not ready to rush during a week to explain why I use I have lost a lot of sleeping time to get this done. I won't lose more. @wilsonge I faced that problem but I'm not sure modifying JForm is a good move. Probably the best move here would be to search the way to allow form XML overriding. This will solve this and many other issues. |
|
@phproberto I certainly didn't want to demotivate you and I am sorry if it came across like this. |
|
I've sent a new commit to add layout support for views. It's intended to replace the old system (template folders are the same). So we cannot use it on core components for now because BC but we can start using it for new views and start encouraging extension developers to use it. To switch to the new system you have to replace in your view parent::display($tpl);with: echo $this->getRenderer('default')->render(
array(
'items' => $this->items,
'pagination' => $this->pagination,
'state' => $this->state,
'user' => $this->user
)
); |
|
I removed the new mvc view path. For classes that use the Branch rebased |
libraries/legacy/view/legacy.php
Outdated
There was a problem hiding this comment.
Just some small inconsistency which jumped me here: You first used "/" and second '/' on the same line.
There was a problem hiding this comment.
hahahahaha are you kidding me?? OMFG
|
OK awesome :) I've been really busy today but I'll have this tested tomorrow (afternoon/evening) :D |
Review all extended JFormFieldList fieldsTo fully ensure BC I will review that all the fields that extend JFormFieldList work.
|
|
I converted |
|
👍 |
|
Rebased vs latest staging to resolve conflicts |
|
Roberto - somethings weird. I can't seem to use pagination in the article manager (it works in a clean 3.2.3 install so not sure what the hell is going on) - I don't understand at all why your changes would affect that specific pagination though :/ |
|
Further to the above it also appears in banners (and is related to the search tools - as these are the two components where search tools appears to be used) - it would appear that everytime to press anything in pagination for some reason unpublish is being selected in the search tools - even when it's not open - god knows why |
libraries/joomla/form/field.php
Outdated
There was a problem hiding this comment.
Much more minor thing but shouldn't this return true if there are no requirements?
There was a problem hiding this comment.
Definitely. Fixed it. Thanks!
|
Thanks for testing @wilsonge The problem with pagination was that it was identifying "" as 0. That's why unpublished was always selected |
|
Ahh I see. I've just hit a PR into your branch that starts to deal with the unit test failures. Not sure how you want to deal with the layout changes - whether in the JLayout or in the unit tests themselves. Updates look good on a quick run through in localhost but will test more thoroughly tomorrow as pretty tired right now :) |
|
I'm not sure neither but maybe in the unit tests is better no? To compare field properties |
|
Hmm probably. Not quite sure how we'd go about comparing the properties though other than doing some nasty preg_replace checks or something like that :/ Will have a ponder. At least the unit test failures now are just due to the spacings in the fields In the meantime I've found an absolutely _critical_ bug. See my PR :P |
|
Does anyone know what's happening with this PR? Also, does this work with all form fields or just lists? |
|
Sorry been meaning to reply to you on the mailing list! Basically we decided to expand the scope a bit and to implement it for the majority of form fields here: https://github.com/joomla-projects/cms-naked However as you can probably see it lost popularity pretty quick. Me and @phproberto need to chat about what we're gonna do with it! |
|
Oh okay, it's just that as it stands it's not possible to override the template (without a plugin) to accommodate any other CSS library that BS 2.3. Would it be possible to just add layouts for the form fields? I can't see any b/c issues in doing this? Can you point to any examples of where this has been done so that I can see the correct format / style for the overrides etc. I might be able to add them and put in a PR or two if I know what needs to be done. |
|
Just use this PR as a base example with the rendering of the layouts. Or make a similar PR into the cms-naked branch and I have permissions there to merge that. I completely agree by the way! I've hacked this into one of my sites to get integrations sorted in the frontend for the editing views. |
|
Sorry @adster101 I should also jump into the issue. I was waiting for v3.5 but I think we have to start making that naked CMS. I'll update the PR against the naked repo tonight and link it here so @wilsonge and me can use it as a starting point to also receive feedback. Thanks! |
|
What is 'naked' CMS? Is it just a place to add the layouts that will be merged into the staging branch at some point or something else? @phproberto did you find time to update the repo? Thanks. |
|
Yeah so it's a place where we're gonna work on the next layer of making Joomla override-able. Firstly moving as much hardcoded stuff into JLayouts. But also thinking ahead a bit - adding in a getRenderer function (https://github.com/joomla-projects/cms-naked/blob/master/libraries/cms/plugin/plugin.php#L153 ) so that we can investigate not even being dependent on JLayouts. The idea was that this would go into 3.5 (coming out ~now) but as you probably know 3.4 is being mega late so not quite sure where this is gonna fit in |
|
Can you elaborate a bit on how the renderer would break the JLayout dependency? I mean what would the other rendering options be? Is there any reason why this PR can't be merged with 3.4, when it's ready? |
Imho the longtime idea is that you could also use Twig or similar for rendering purposes. At least I understood it like this.
It could go into 3.4 in theory, but that would be something the release manager (currently for 3.4 that's David Hurley) has to decide. For 3.4, the main focus is a different one and since we're already delayed I wouldn't focus on this one. But if it gets ready in time, maybe it can be merged already. |
|
I am a bit play with new Have couple suggestions: 1 Posibility to get fullpath without rendering the layout file, something like: public function getFullPath()
{
if (!is_null($this->fullPath))
{
return $this->fullPath;
}
// Search
return $this->getPath();
}2 Throw Exception in 3 What about ability use the priority in Example, I want add own fallback path, so I do $layout->addIncludePath('/root/path/my/fallback/path');And got: 'includePaths' =>
array (
0 => string '/root/path/my/fallback/path'
1 => string '/root/path/templates/isis/html/layouts'
2 => string '/root/path/layouts'
)That not really what I want, because I want that my fallback work only when no layout found in the template (or component) folder. added: public function addIncludePathToPosition($path, $position = 0)
{
array_splice($this->includePaths, $position, 0, $path);
return $this;
} |
|
Hi, please ckeck out review of the code of class JLayoutFile
$this->fullPath = JPath::find($this->includePaths, $rawPath);
if ($this->fullPath = JPath::find($this->includePaths, $rawPath))
{
$this->addDebugMessage('<strong>Found layout:</strong> ' . $this->fullPath);
}
else
{
$this->addDebugMessage('<strong>Unable to find layout: </strong> ' . $this->layoutId);
}
|
|
What is the decision on this one? If it is ready to commit I would like to bring the fields user, media and content history (versions) to layouts and use bootstrap modal (for protostar and isis) and thus drop completely the loading of mootools on joomla core... |
|
The decision is that it is being held back for Joomla 3.5 - but the JLayout conversion will be centre feature of that release |
|
Sounds good, thanks George |
|
one more note, suggested search with prefixes is: so I think would be better make search like: |
|
@phproberto why did you close this one? There’s another approach/solution/code for this? |
Feature tracker: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=33415
This also fixes this issue:
http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=33618
This pull request introduces some new
JLayoutbased features:JLayout improvements
1. Chainable methods
I have added the option to chain methods when possible. Now you can do:
2. Suffixes improvements
Version 3.2 already supported suffixes but I created some improvements.
2.1 Add suffixes dynamically
Now suffixes can be added dynamically with
setSuffixes($suffixes)method. Example:2.2 Automatic version suffixes
Most extended suffixes use was for having different versions for Joomla 2.5 & Joomla 3.x. I've added an automatic mode that will load the default version suffixes:
Will automatically load this suffixes when executed on Joomla 3.2.3:
So it will search for a layout in this priority order:
This is mainly intended to be used on classes that extend
JLayoutFilebecause sadly layouts are not available on Joomla 2.5.x series (they are included on FOF now).For example an extended class running the same code on Joomla 2.5.18 will search layouts on:
As you can see is useful to have layout specific for a Joomla version.
2.3 Automatic language suffixes
This is an automatic suffix mode language oriented. Example:
It will automatically add this suffixes when executed on a site with
en-GBlanguage active.So you can create a layout for:
Good examples would be addresses that are ordered differently on different languages or layouts specifics to
RTL(Right To Left) languages3. Prefixes support
Now
JLayoutFilealso supports prefixes. This is mainly to group different prefixes under the same prefix. In the practice a prefix is a main folder that stores all that layouts. Example:It will search layouts in this order when called from the article view:
So for example if you are on a template that supports both bootstrap2 & bootstrap3 mode you can put in the layouts/bootstrap3 folder the specific layouts for bootstrap3.
4. Cached file searches
When a layout is already searched in a specific list of include paths the final path is saved on cache. Next time the layout is searched in that list of include paths the cached path will be returned.
5. Statistics
Now
JLayoutFilestores statistics about its use. To get the stats you have to use:It will return something like:
All the stats in a single array.
5.1 Stats details
$stats['fileSearches']: Number of layout searches performed$stats['fileSearchesCached']: Number of layout searches returning cached paths$stats['fileSearchesSkipped']: Number of layout searches skipped because they share same instance with same params$stats['times']: Array containing different times tracked$stats['times']['fileSearching']: Total time spent searching layouts on file system$stats['times']['fileRendering']: Total time spent rendering layouts$stats['times'][$path]: System stores also time spent rendering each layout. This includes the global rendering time of rendering all appearences of this layout.$stats['layoutsRendered']: Array containing the list of layouts rendered (array key) and the times it has been rendered ( value).6. Better includepaths handling
In the previous versions you could not specify a list of include paths. The layout paths were always calculated automatically. Now you have total control over them
6.1 setIncludePaths
Will search for layouts on:
6.1 resetIncludePaths
Delete the include paths information
will search in this include paths:
6.2 loadDefaultIncludePaths
It will load the automatically calculated paths.
JFormField improvements
1. Field requirements support
This adds the option for fields to specify requirements that will prevent the field from being loaded.
There are only 2 main requirements defined at this point:
Note: This adds the support but most of the fields will require to modify the geInput() method to add the
$this->validateRequirements()call. So don't expect it works on all fields out of the box. It should only work on labels and on text field.A sample field definition:
You can specify more than one requirement:
You can easily extend requirements for your field like:
2. Layouts support
This adds support to use
JLayoutFileto render form fields. This is added inJFormFieldbut it doesn't change most of the existing fields to ensure BC. So don't expect it to work out of the box on all the fields. Included fields are:Now layouts can be defined inside fields setting the property
$layout:But they also can be overriden on form. Thanks to this we can save to create new fields when the logic to get the data is the same and only the logic to render it changes. Examples would be to load
select2on a field for example:Or imagine that you have a layout to render a filed loading
typeahead.jsfield:You can also set a specific layout for the label and layout prefixes/suffixes on your field class:
or in your form XML file:
3. Overridable getRenderer
If you want to change the default paths or load your extended class instead of
JLayoutFileyou can nor override the getRenderer method:This gives a very flexible tool to developers.
Plugins improvements
1. Layout support
Now in your plugin you can do something like:
It will search a
default.phplayout on:Note: All the plugins are still using the old hardcoded method. Only the plugin
content/votehas been converted for testing purposes.2. Layouts information on debug
Now the debug console shows all the information of the layouts loaded in the current page:
Testing
Required tests include: