Packages in 5.4
Permalink 2 users found helpful
Can someone help me with packages, I'd like to get to the bottom of this.
I have included the contents of concrete/elements/users in a package as elements/users at my package root, and modified to suit my needs.
I cannot get the modified code to run when the package is installed. However, if I paste the users folder into the elements folder of my install it runs fine.
The documentation has screen grabs of package folder trees which include "elements" and the documentation itself states:-
"As of concrete 5.4, the following items may be bundled into a package:
Libraries
Models
Elements
Tools
Block Types
Page Types
Page Controllers
Single Pages
Mail Helpers
Mail Importers
Attribute Keys
Attribute Categories
Attribute Types
Attribute Sets
Dashboard Modules
Configuration Values
Themes
Task Permissions
Jobs"
Either this isn't correct, or I'm missing something fundamental. I know blocks need installing, as do themes when included in a package, but I thought C5 would pick up my substitute files automatically.
Please help, this is really holding me back now.
I have included the contents of concrete/elements/users in a package as elements/users at my package root, and modified to suit my needs.
I cannot get the modified code to run when the package is installed. However, if I paste the users folder into the elements folder of my install it runs fine.
The documentation has screen grabs of package folder trees which include "elements" and the documentation itself states:-
"As of concrete 5.4, the following items may be bundled into a package:
Libraries
Models
Elements
Tools
Block Types
Page Types
Page Controllers
Single Pages
Mail Helpers
Mail Importers
Attribute Keys
Attribute Categories
Attribute Types
Attribute Sets
Dashboard Modules
Configuration Values
Themes
Task Permissions
Jobs"
Either this isn't correct, or I'm missing something fundamental. I know blocks need installing, as do themes when included in a package, but I thought C5 would pick up my substitute files automatically.
Please help, this is really holding me back now.
Thanks Mnkras. But where do I use that syntax?
I have just tried this in the install and on_start methods of my package, and no joy.
I have just tried this in the install and on_start methods of my package, and no joy.
## ## Loader::packageElement('users/search_results', $pkgHandle); ## ##
After burning a day on this I'm about ready to conclude that you can't override concrete5 core functionality from a package even in 5.4.1.
The limited number of free application packages I've been able to look at all use the folders mentioned above to extend C5 not override the any of the core.
Please can someone confirm if this is the case, or tell me how it can be done.
Thanks
The limited number of free application packages I've been able to look at all use the folders mentioned above to extend C5 not override the any of the core.
Please can someone confirm if this is the case, or tell me how it can be done.
Thanks
no you cannot, :( what people have been doing in packages, is doing an if file exists check (like on /helpers/html.php) and if it doesn't exist copy the file from the package to there
Was about to resort to copying the file - there is scope for conflicts either way I suppose.
Think the docs could be clearer, the packages docs and some of the loader docs drew me into thinking this possible.
Thanks Mnkras. At least I know.
Think the docs could be clearer, the packages docs and some of the loader docs drew me into thinking this possible.
Thanks Mnkras. At least I know.
if you need to use most of a helper's functionality but you need tweaking something(like say the json helper), then you could do in your code:
Loader::helper('json'); class OllieJsonHelper extends JsonHelper{ /** * Decodes a JSON string * pass $assoc false if you want? it should be true unless overwise specified */ public function decode($string,$assoc = true) { if (function_exists('json_decode')) { return json_decode($string,$assoc); } else { Loader::library('3rdparty/JSON/JSON'); $sjs = new Services_JSON(); return $sjs->decode($string, $assoc); } }
Viewing 15 lines of 18 lines. View entire code block.
Scott. Thanks appreciate this can be done, though the file elements/users/ search_results.php isn't a class, this is the file I was trying to drop into the package and have C5 use, in preference to the concrete/elements/users/ version.
But your method could work, if I move back from the the elements file and extend the controller class that feeds search_results.php.
I'd normally do that in any other PHP OOP application, just got drawn into the convenience of file substitution with C5.
Thanks for the suggestion, will try it and report back.
But your method could work, if I move back from the the elements file and extend the controller class that feeds search_results.php.
I'd normally do that in any other PHP OOP application, just got drawn into the convenience of file substitution with C5.
Thanks for the suggestion, will try it and report back.
This isn't going to work when I think about it.
If I extend a controller I'll need to call the overidden method, which would be fine for use in my own application, but in this instance want I want to do is have the core use my extended method in place of the method it is currently calling.
Without adding code outside of the package, (which needs to be portable), I don't see how I go this route.
Am I missing something.
Thanks for all your help guys, so far copying in the file out the package to the root tree looks to be about the only way.
If I extend a controller I'll need to call the overidden method, which would be fine for use in my own application, but in this instance want I want to do is have the core use my extended method in place of the method it is currently calling.
Without adding code outside of the package, (which needs to be portable), I don't see how I go this route.
Am I missing something.
Thanks for all your help guys, so far copying in the file out the package to the root tree looks to be about the only way.
No, you're not missing anything. Unfortunately, you can't override an element currently from a package in concrete5 – only by copying the element from either the core concrete/ directory (or a package) into the root elements/ directory.
We'd like to do something about this, but it'd probably have to also work with things like libraries and models. We will keep it on our radar. sorry for the confusion.
We'd like to do something about this, but it'd probably have to also work with things like libraries and models. We will keep it on our radar. sorry for the confusion.
Any change on this? Would like to override an elements file from a package
No. It's really not easy to do. In large part because there's no way to allow more than one package to do this at a time without conflict.
I have two packages that have needed to override helpers, and I've been successful at writing an install routine that checks for the existence of the file and, if not exists, then copies the package version over, providing messages where it's not successful.
James
I have two packages that have needed to override helpers, and I've been successful at writing an install routine that checks for the existence of the file and, if not exists, then copies the package version over, providing messages where it's not successful.
James
you can do that with anything that uses loader