October: Extending Lists widget functionality

Created on 21 Oct 2016  路  4Comments  路  Source: octobercms/october

I want to extend the lists widget to add the double click functionality.

My best approach right now it's to find a way to override the /modules/backend/widgets/lists/partials/_list_body_row.htm to add a call to a new additional method in that partial, since thanks to the cool feature of extensions I can already add dynamically methods and properties with

Lists::extend(function($lists){
 // add dynamic method and property
});

That way I'll be able to add the logic and change the lists partials to call that new logic the same way the one click way works.

Another approach would be (that would require changing the core of octoberCMS) adding a new alias called "List" (for example) and change all the calls to makeWidget from Backend\Widgets\Lists to the defined alias (for instance, the ListController behavior in the makeList method).

That way I'll be able to extend literally the lists widget and use it alongside the ListController behavior. Also, I think that extending this alias approach to the rest of widgets in the core system would add a lot of flexibility to the system, unless it's considered a bad technique.

October build:
365

Completed Enhancement

Most helpful comment

This enhancement is complete. You can now override all the views used by the List, see new docs for further details. Available in Build 377+. Enjoy 馃槃

Overriding views

The ListController behavior has a main container view that you may override by creating a special file named _list_container.htm in your controller directory. The following example will add a sidebar to the list:

<?php if ($toolbar): ?>
    <?= $toolbar->render() ?>
<?php endif ?>

<?php if ($filter): ?>
    <?= $filter->render() ?>
<?php endif ?>

<div class="row row-flush">
    <div class="col-sm-3">
        [Insert sidebar here]
    </div>
    <div class="col-sm-9 list-with-sidebar">
        <?= $list->render() ?>
    </div>
</div>

The behavior will invoke a Lists widget that also contains numerous views that you may override. This is possible by specifying a customViewPath option as described in the list configuration options. The widget will look in this path for a view first, then fall back to the default location.

# Custom view path
customViewPath: $/acme/blog/controllers/reviews/list

Note: It is a good idea to use a sub-directory, for example list, to avoid conflicts.

All 4 comments

If there's no way of making the extension right now. It would be advisable to make the changes in the code for the aliases in makeWidget ? I can do it personally and send a Pull Request.

This enhancement is complete. You can now override all the views used by the List, see new docs for further details. Available in Build 377+. Enjoy 馃槃

Overriding views

The ListController behavior has a main container view that you may override by creating a special file named _list_container.htm in your controller directory. The following example will add a sidebar to the list:

<?php if ($toolbar): ?>
    <?= $toolbar->render() ?>
<?php endif ?>

<?php if ($filter): ?>
    <?= $filter->render() ?>
<?php endif ?>

<div class="row row-flush">
    <div class="col-sm-3">
        [Insert sidebar here]
    </div>
    <div class="col-sm-9 list-with-sidebar">
        <?= $list->render() ?>
    </div>
</div>

The behavior will invoke a Lists widget that also contains numerous views that you may override. This is possible by specifying a customViewPath option as described in the list configuration options. The widget will look in this path for a view first, then fall back to the default location.

# Custom view path
customViewPath: $/acme/blog/controllers/reviews/list

Note: It is a good idea to use a sub-directory, for example list, to avoid conflicts.

Totally did not see this! Im going to try it out now!

edit: Not that I'm groaning about that, but, I'd like to know your oppinion about the use of aliases for widgets, like List or ListWidget.

It seems to work perfectly! Thanks!

Was this page helpful?
0 / 5 - 0 ratings