Extending Backend Lists Object
how could I extend the list items which are displayed in backend?
I am trying to use this function:
The thing is that I need to recreate the same object $records, but I want to add my custom data to it. For example my records is orders from JK Shop plugin. What I need is to take all the products from those orders and make each product as a different list item.
I could do these changes in this function and just return the $records, but how could I create a new object of items here? I tried using:
$new = new Production(); return $new;
But I get :
Call to undefined method October\Rain\Database\QueryBuilder::currentPage()
How could I make a new working Object which could be returned to the backend list?
Hmm, from your question you want to show
related items (products of order)
under theorder record` it self,
it seems its not possible using extension or may be it become more hard/complex if we use that thing
instead we can use
override partial for
list for that particular list, to do so we can use its
order list config add this additional option
.... toolbar: buttons: list_toolbar search: prompt: 'backend::lang.list.search_prompt' recordUrl: 'hardiksatasiya/demotest/demo/update/:id' // add customViewPath customViewPath: $/hardiksatasiya/demotest/controllers/demo/list_override
now here we override 2 partials (i have copied them from
i modify there content
<?php foreach ($records as $record): ?> <?= $this->makePartial('list_body_row', [ 'record' => $record, 'treeLevel' => $treeLevel, 'custom' => isset($custom) ? true : false]) ?> <?php endforeach ?>
<?php $expanded = $showTree ? $this->isTreeNodeExpanded($record) : null; $childRecords = $showTree ? $record->getChildren() : null; $treeLevelClass = $showTree ? 'list-tree-level-'.$treeLevel : ''; ?> <tr class="<?= $treeLevelClass ?> <?= $this->getRowClass($record) ?>"> <!-- we are using that custom variable here we dont want to show check box for our products--> <?php if ($showCheckboxes && $custom == false): ?> <?= $this->makePartial('list_body_checkbox', ['record' => $record]) ?> <?php endif ?> <?php if ($showTree): ?> <?= $this->makePartial('list_body_tree', [ 'record' => $record, 'expanded' => $expanded, 'childCount' => $record->getChildCount() ]) ?> <?php endif ?> <!-- we are using that custom variable here and make our row seperatly as we need for all item/product record this partial executed so we code it for single row it will be repeated through all product items automatically--> <?php if($custom): ?> <td> <!-- checkbox column we make it blank--> </td> <!-- colspan based on requirement you can fully customize your td tags from here --> <td colspan="<?= count($columns) ?&guirement you can fully customize your td tags from here --> <td colspan="<?= count($columns) ?>"> <a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="/backend/products/edit/<?= $record->id ?>"> <?= $record->name ?> </a></td> <?php else: ?> <?php $index = $url = 0; foreach ($columns as $key => $column): ?> <?php $index++; ?> <td class="list-cell-index-<?= $index ?> list-cell-name-<?= $column->getName() ?> list-cell-type-<?= $column->type ?> <?= $column->clickable ? '' : 'nolink' ?> <?= $column->cssClass ?>"> <?php if ($column->clickable && !$url && ($url = $this->getRecordUrl($record))): ?> <a <?= $this->getRecordOnClick($record) ?> target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="<?= $url ?>"> <?= $this->getColumnValue($record, $column) ?> </a> <?php else: ?> <?= $this->getColumnValue($record, $column) ?> <?php endif ?> </td> <?php endforeach ?> <?php endif; ?> <?php if ($showSetup): ?> <td class="list-setup"> </td> <?php endif ?> </tr> <?php if ($showTree && $expanded): ?> <?= $this->makePartial('list_body_rows', ['records' => $childRecords, 'treeLevel' => $treeLevel+1]) ?> <?php endif ?> <!-- you can customise this condition basde on your order have items or not i used simple relation condition here --> <?php if ($record->relation): ?> <?php $childRecords = is_array($record->relation) ? $record->relation : [$record->relation]; ?> <?php // currently as $childRecords i used relation but you can create your own model array // and pass here it will be received in next iteration // notice we are passing $custom variable and we also override // _list_body_rows.htm and it will loop through all records and pass // $custom variable and it will be true based on its existance // if we pass custom variable it will pass it also with true other wise // it will pass it false ?> <?= $this->makePartial('list_body_rows', ['records' => $childRecords, 'treeLevel' => $treeLevel+1, 'custom' => true]) ?> <?php endif ?>
it will give you output like this
i have also
added comments in
new paritals how to use them if you need mroe information please comment.
- → OctoberCMS Backend Loging Hash Error
- → "failed to open stream" error when executing "migrate:make"
- → OctoberCMS - How to make collapsible list default to active only on non-mobile
- → Create plugin that makes objects from model in back-end
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → How to install console for plugin development in October CMS
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → How to update data attribute on Ajax complete
- → October CMS - Conditionally Load a Different Page