From e3e8fb35c7b15e214833d8f5f4994f9ea88d70e0 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sat, 22 Aug 2015 16:39:09 +1000 Subject: [PATCH] Allow the model attribute name to be specified from config --- .../backend/behaviors/ReorderController.php | 21 ++++++++++++++++++- .../reordercontroller/partials/_records.htm | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/modules/backend/behaviors/ReorderController.php b/modules/backend/behaviors/ReorderController.php index 5b7356d24..6102b5500 100644 --- a/modules/backend/behaviors/ReorderController.php +++ b/modules/backend/behaviors/ReorderController.php @@ -28,6 +28,11 @@ class ReorderController extends ControllerBehavior */ public $model; + /** + * @var string Model attribute to use for the display name + */ + public $nameFrom = 'name'; + /** * @var bool Display parent/child relationships in the list. */ @@ -59,11 +64,16 @@ class ReorderController extends ControllerBehavior $this->config = $this->makeConfig($controller->reorderConfig, $this->requiredConfig); /* - * Form widgets + * Widgets */ if ($this->toolbarWidget = $this->makeToolbarWidget()) { $this->toolbarWidget->bindToController(); } + + /* + * Populate from config + */ + $this->nameFrom = $this->getConfig('nameFrom', $this->nameFrom); } // @@ -162,6 +172,15 @@ class ReorderController extends ControllerBehavior return $this->model = new $modelClass; } + /** + * Returns the display name for a record. + * @return string + */ + public function reorderGetRecordName($record) + { + return $record->{$this->nameFrom}; + } + /** * Validate the supplied form model. * @return void diff --git a/modules/backend/behaviors/reordercontroller/partials/_records.htm b/modules/backend/behaviors/reordercontroller/partials/_records.htm index fe29ef9c1..c85ac1814 100644 --- a/modules/backend/behaviors/reordercontroller/partials/_records.htm +++ b/modules/backend/behaviors/reordercontroller/partials/_records.htm @@ -3,7 +3,7 @@
  • - title ?> + reorderGetRecordName($record) ?>