I'm excited that the October CMS recently added back-end functionality for sorting records in the list view. But I'm having some trouble getting it to work. The documentation is here. I've followed the direction like so:
In my controller, I implemented the ReorderController
:
<?PHP namespace BTruchan\Team\Controllers;
use Backend;
use BackendMenu;
use BackendAuth;
use Backend\Classes\Controller;
use System\Classes\SettingsManager;
class Members extends \Backend\Classes\Controller
{
public $implement = [
'Backend.Behaviors.FormController',
'Backend.Behaviors.ListController',
'Backend.Behaviors.ReorderController'
];
public $formConfig = 'config_form.yaml';
public $listConfig = 'config_list.yaml';
public $reorderConfig = 'config_reorder.yaml';
public $requiredPermissions = ['btruchan.team.manage'];
public function __construct()
{
parent::__construct();
BackendMenu::setContext('BTruchan.Team', 'team');
}
public function index()
{
$this->makeLists();
$this->makeView('reorder');
}
}
?>
I've created the reorder view file (reorder.htm
) which contains:
<?= $this->reorderRender() ?>
My config_reorder.yaml
file contains:
# ===================================
# Reorder Behavior Config
# ===================================
# Reorder Title
title: Reorder Members
# Attribute name
nameFrom: name
# Model Class name
modelClass: BTruchan\Team\Models\Members
# Toolbar widget configuration
#toolbar:
# Partial for toolbar buttons
# buttons: reorder_toolbar
You'll notice that the reorder_toolbar
partial is commented out. That's because I really don't know what's supposed to go in that toolbar. I haven't been able to find any documentation that shows the contents for the _reorder_toolbar.htm file.
Unsurprisingly, with the code commented out, it throws an error:
Undefined variable: reorderToolbarWidget
Some additional information:
It was suggested that I read up on list toolbars here.
So I added the following toolbar partial (named _reorder_toolbar.htm
):
<div data-control="toolbar">
<a
href="<?= Backend::url('btruchan/team/members/create') ?>"
class="btn btn-primary oc-icon-plus">
New Team Member
</a>
<button
class="btn btn-default oc-icon-trash-o"
disabled="disabled"
onclick="$(this).data('request-data', {
checked: $('.control-list').listWidget('getChecked')
})"
data-request="onDelete"
data-request-confirm="Delete Team Member: Are you sure?"
data-trigger-action="enable"
data-trigger=".control-list input[type=checkbox]"
data-trigger-condition="checked"
data-request-success="$(this).prop('disabled', false)"
data-stripe-load-indicator>
Delete
</button>
</div>
But I'm still getting an error:
Undefined variable: reorderToolbarWidget /var/www/terrasearch/public/modules/backend/Behaviors/reordercontroller/partials/_container.htm line 1
The code, in October CMS, which that error message is referring is:
<?php if ($reorderToolbarWidget): ?>
<!-- Reorder Toolbar -->
<div id="<?= $this->getId('reorderToolbar') ?>" class="reorder-toolbar">
<?= $reorderToolbarWidget->render() ?>
</div>
<?php endif ?>
<!-- Reorder List -->
<?= Form::open() ?>
<div
id="reorderTreeList"
class="control-treelist"
data-control="treelist"
I've tried to trace this error down. It seems like, in \public\modules\backend\behaviors\ReorderController.php
, the reorder()
function is not being called, which means that the prepareVars()
function is also not being called. This prevents the following code from being executed:
$this->vars['reorderToolbarWidget'] = $this->toolbarWidget;
ReorderController.php:: makeToolbarWidget() is being called and seems to be OK. I've checked $this->toolbarWidget, and it seems to contain perfectly good data. (It isn't NULL).
The ReorderController is a behavior, so it's meant to be called as a controller destination (e.g. example.com/backend/btruchan/team/members/reorder
). It's not coded to be called as a view the way you have it in your index
function.
In the ReorderController source, the reorder
function is the only method that calls the prepareVars
protected function which is the only place that the reorderToolbarWidget
is defined for the page. That prepareVars
function isn't available from the host controller.
So, rather than try to create a view with $this->makeView('reorder');
, create a toolbar button in the _list_toolbar.htm
partial that points to the reorder
destination url. For example:
<div data-control="toolbar">
<a href="<?= Backend::url('btruchan/team/members/create') ?>" class="btn btn-primary oc-icon-plus">New Member</a>
<a href="<?= Backend::url('btruchan/team/members/reorder') ?>" class="btn btn-primary oc-icon-sort">Reorder Members</a>
</div>
When you click on the "Reorder Members" button, you'll be directed to a new page with the records that can be reordered.
You can use the _reorder_toolbar.htm
partial to add anything you want at the top of the reorder page. Or, not use it at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With