mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Allow the model attribute name to be specified from config
This commit is contained in:
parent
6d1673c4b3
commit
e3e8fb35c7
@ -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
|
||||
|
@ -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>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user