Widgets customizing and overwriting of widgets

1 Overwriting default widget templates

You can easily overwrite widget views (=templates). This flexible solution was developed to allow clients to customize widget views for their needs.

To overwrite widget views you need to find the original view in common folder and copy it to custom folder in the same directory structure.

For example, you need to overwrite view /common/modules/comments/widgets/views/CommentsFormWidget.php

you need to copy it into

/custom/modules/comments/widgets/views/CommentsFormWidget.php

and change it there.

1.1 How disable widget’s views overwriting

Overwriting can be disabled in any time by specifying this option in the configuration:


'params' => array(
        //If true try to use view files from custom section
        'customViews' => false,
        ...................
        )

2 Overwriting widget classes

You can overwrite widget’s class definition also.

For example, you need to overwrite widget’s class common/modules/comments/widgets/CommentsFormWidget.php

you need to copy it into

custom/modules/comments/widgets/CommentsFormWidget.php

and change it there.

2.1 How disable widget’s class overwriting

Overwriting can be disabled in any time by setting this option as false in the configuration:


'params' => array(
        //If parameter is true portal tries to find called widget classes in custom section
        'customWidgets' => true,
        ...................
        )

3 Overwriting / enhance module model (data structure)

If you need to enahance the user model in the shopping cart, you can enchance a TmpUser model. In your portal you should find this example in the custom-area.

  • The basic model class should be copied to <portal>/custom/shoppingcart/models/basic/ and renamed to oldName+Basic, in our case it should be <portal>/custom/modules/shoppingcart/models/basic/TmpUserBasic.php (and the class name in the file should be changed in the same way)
  • Create a new model class (which includes your enhancements) in <portal>/custom/modules/shoppingcart/models/TmpUser.php. This class must inherite from the class mentioned in the paragraph 1, as following: class TmpUser by using “TmpUser extends TmpUserBasic”
  • The portal detects that the model should be overwritten with the class from the custom section and uses the new one instead of the same model from common section. Basic model is used because we need to keep the general functionality of the model and avoid name conflicts (it’s not allowed to declare two classes with the same name).