The fork system
Regenerate and keep your customizations. Using this feature, you will be able to re-install a fresh downloaded component structure, and all your customs will be kept. Simply install the new component over. As simple as that. How it works ?It is using the native PHP classes overrides, and take advantage of the JLoader class. Some files are for the moment excluded of this features :
During the upgrade of your component, the fork directory will not be overriden. How to use it ?When you download your component, Cook furnish you an empty fork file for every php class. Located in /_fork directory. Pick up the concerned file to fork from this given list. All your customs will be written behind the 'fork' directories from concerned client side (site or admin) Also, your fork files will be organised the same way than your component root, but will only contains the concerned files that have been modified. Structure of the empty fork file// no direct access defined('_JEXEC') or die('Restricted access'); class HellomyworldViewProduct extends HellomyworldCkViewProduct { } Fork itCopy the original function and paste it in the fork file. a. Fork to replaceclass HellomyworldViewProduct extends HellomyworldCkViewProduct { protected function displayProduct($tpl = null) { echo("Forked"); // Fork and replace the original function } } b. Fork to execute beforeclass HellomyworldViewProduct extends HellomyworldCkViewProduct { protected function displayProduct($tpl = null) { // Read the ACL of the current user $acl = HellomyworldHelper::getActions(); if ($acl->get('core.admin')) { // Call another Layout $this->displayAdminLayout(); // Do not execute the original layout return; } // Call the original function return parent::displayProduct($tpl); } } c. Fork to execute afterclass HellomyworldViewProduct extends HellomyworldCkViewProduct { protected function displayProduct($tpl = null) { // Execute the native function $result = parent::displayProduct($tpl); // Execute after $document = JFactory::getDocument(); $document->title = "Forked title - " . $document->title; return $result; } } Forking the Non-PHP filesCSSBoth original + Fork are loaded. ImagesBasicly, it is not possible to fork a static image. Your component is not checking image fork presence. Javascript filesYour alternative scripts must implicit be called from a forked file. JDomJDom has its own system of overrides. You can override JDom files in many ways.
Good practicesOverride only the strict necessaryKeep in mind the less you fork, the easiest is to upgrade the component. parent, selfThe fork feature has a limitation with the parent and self keywords. Some trick functions like JView::_parentDisplay() permit to avoid this problem. For example when you override a view file, instead of calling : parent::display(); //Infinite loop Replace by one of the following possibilities $this->_parentDisplay(); self::_parentDisplay(); // Static call return self::_parentDisplay(); //Static call with returning value XML files.JForms XML can be forked, but only to ADD or OVERRIDE fields. You cannot remove an existing field. For the moment, the fork system does not apply on the others XML files. (manifest, config, layouts)
Known issueThe forked XML does not recognize sub items.
DisclaimerWhen you reinstall a fresh scaffolding you must know the last Cook changes and reprocess all the tests to know if your forks are still working. This fork system is not guaranteed at all because it depends how you implement your forks. It cannot replace a versioning system or a comparison tool. Finalize your component. Merge the forks into the structure.Once you've finished developing and are ready for production, you can merge (manually) your forks into their respective files, and suppress the fork directories. Resulting in a clean component ready to distribute. Obviously, you can also keep those fork directories forever if you want. |
|