This plugin includes Form Widgets and Behaviors.
Form Widgets
- Button
- MapPicker
Behaviors
- AutosizeModel
- ModalController
- TrashController
Twig Extensions
- numberToWordfilter
Helpers
- array_map_recursive()function
See the Documentation tab for details.
This plugin includes Form Widgets and Behaviors
Form Widgets
Behaviors
Twig Extensions
Helpers
Documentation
Button FormWidget
In your fields.yaml of your plugin, define the field type button.
For official documentation go to OctoberCMS Docs page.
button - renders an html anchor element with .btn class.
    link_button:
        type: button
        text: Reload Items
        css: btn-default oc-icon-refresh
        loadingIndicator: true
        dataAttr:
            model-request: onReloadItems
| Option | Description | 
|---|---|
| text | Button Label | 
| css | Css class name (.btn is allways added). See OC Button Docs | 
| loadingIndicator | Render loading indicator when button is clicked | 
| dataAttr | Array with format key: value. Each item will be rendered asdata-{KEY}='{VALUE}' | 
If the form widget is used to request ajax call, use the documented data attributes, without the first data-.
    calculate_button
        type: button
        text: Calculate
        css: btn-primary oc-icon-calculator
        dataAttr:
            request: onCalculate
            request-update: "calcresult: '#result'"
If the form widget is used in Settings page, without a controller, the ajax request method must be in the model. In this case, use model-request instead of request.
Map Picker FormWidget

mappicker:
    type: mappicker
    fieldMap:
        location: address
        latitude: lat
        longitude: lng
        city: city
        state: state
        country: country
        country-long: country_long
fieldMap options must be in format key: value, where key is the map data element, and value is the form field name, where set value on change address.
The list of options:
- location
- latitude
- longitude
- city
- zip
- state
- country (can be a text field or options select)
- country-long
Autosize Model Behavior
Automatic resize uploaded images to pre configured max width/height.
The use is very simple, just add this line to your model.  
public $implement = [ 'PlanetaDelEste.Widgets.Behaviors.AutosizeModel' ]; public $autosizeRelation = 'relation_name';
In this example, extend the model RainLab\User\Models\User and add this behavior dynamically.
In your Plugin.php write this:  
use RainLab\User\Models\User;     
class Plugin extends PluginBase  
{
    public function boot() { 
      // Extend RainLab User model 
      User::extend( function (User $model) { 
          $model->addDynamicProperty('autosizeRelation', 'avatar'); 
          $model->implement[] = '@PlanetaDelEste.Widgets.Behaviors.AutosizeModel'; 
      } ); 
  }
}
And after model is saved, all images will be resized.
This plugin require
intervention/imagelibrary.
Modal Controller Behavior
This behavior is used to load create/update forms in modal window, from the lists view
Usage
1) - In controller add PlanetaDelEste.Widgets.Behaviors.ModalController to the $implementvar.  
    public $implement = [  
        'Backend.Behaviors.FormController', 'Backend.Behaviors.ListController',
        'PlanetaDelEste.Widgets.Behaviors.ModalController' 
    ];  
2) - In _list_toolbar.htm add the attribute onclick="return $.manageModal.createRecord()" to the create new button  
    <a  
        href="<?= Backend::url('acme/foo/categories/create') ?>"  
        onclick="return $.manageModal.createRecord()"  
        class="btn btn-primary oc-icon-plus">  
        <?= e(trans('acme.foo::lang.category.new')) ?>  
    </a>  
3) - From config_list.yaml comment the line recordUrl: ... and add recordOnClick: $.manageModal.clickRecord(:id)  
# =================================== # List Behavior Config # =================================== # Link URL for each record recordOnClick: $.manageModal.clickRecord(:id)

Trash Controller
Add a controller  to manage trashed records (Model with SoftDelete trait).
Usage
See the official documentation
In your Controller add this line to $implement: 
    /**
     * Implement the TrashController behavior
     */
    public $implement = [
        'PlanetaDelEste.Widgets.Behaviors.TrashController'
    ];
Or if you want to extend a controller from your plugin, add this lines to boot method
FooController::extend(function($controller) {
    // Implement behavior if not already implemented
    if (!$controller->isClassExtendedWith('PlanetaDelEste.Widgets.Behaviors.TrashController'))       
    {
        $controller->implement[] = 'PlanetaDelEste.Widgets.Behaviors.TrashController';
    }
    if(request()->segment(5) == 'trashed') {  
      $controller->addViewPath('$/planetadeleste/widgets/behaviors/trashcontroller/partials');  
    }
}
Number to Word
Twig filter to convert any number into world
{{ 8|numberToWord }}  
The example would output "eight"
Helpers
array_map_recursive()
array_map_recursive Applies the callback to the elements of the given arrays recursively
$array = [
    'users' => [
        ' Brian',
        'Shannon ',
        'Alec ',
    ],
    'features' => [
        'PHP ',
        'Ruby   ',
        'JavaScript ',
    ],
];
$array = array_map_recursive('trim', $array);
/*
[
    'users' => [
        'Brian',
        'Shannon',
        'Alec',
    ],
    'features' => [
        'PHP',
        'Ruby',
        'JavaScript',
    ],
];
*/
            - 
        This plugin has not been reviewed yet. 
- 
                        
| 1.0.11 | Add TrashController behavior May 30, 2018 | 
|---|---|
| 1.0.10 | Add Google api key setting Nov 12, 2017 | 
| 1.0.9 | Fix Riskihajar\Terbilang provider nameclass Feb 23, 2017 | 
| 1.0.8 | Use \System\Models\File::getLocalPath instead of \System\Models\File::getPath Feb 21, 2017 | 
| 1.0.7 | New auto apply of AutosizeBehavior for some known models Dec 08, 2016 | 
| 1.0.6 | Fix Unknown column 'autosizeRelation' error Oct 10, 2016 | 
| 1.0.5 | !!! This is an important update that contains breaking changes. AutoziseModel behavior require the property autosizeRelation. Oct 06, 2016 | 
| 1.0.4 | Add numberToWord twig filter Mar 08, 2016 | 
| 1.0.3 | Add AutoziseModel behavior Mar 08, 2016 | 
| 1.0.2 | Add Button form widget Mar 08, 2016 | 
| 1.0.1 | First version of Widgets Mar 08, 2016 | 
 
    
 
    