Allow the model attribute name to be specified from config

This commit is contained in:
Samuel Georges 2015-08-22 16:39:09 +10:00
parent 6d1673c4b3
commit e3e8fb35c7
2 changed files with 21 additions and 2 deletions

View File

@ -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

View File

@ -3,7 +3,7 @@
<li data-record-id="<?= $record->id ?>" data-record-sort-order="<?= $record->sort_order ?>">
<div class="record">
<a href="javascript:;" class="move"></a>
<span><?= $record->title ?></span>
<span><?= $this->reorderGetRecordName($record) ?></span>
<input name="record_ids[]" type="hidden" value="<?= $record->id ?>" />
</div>