Update SortOrderField.php (#6046)

Allow custom label or hint.
E.g. if an attributeLabels is defined in the model for the `fieldName` attribute, `$form->field($model, 'fieldName')->widget(SortOrderField::class)` should render the label defined in the model and not the default `'Sort Order'`.
This commit is contained in:
Marc Farré 2023-01-16 13:30:45 +01:00 committed by GitHub
parent 81b1876e77
commit 9d88da246a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,12 +44,16 @@ class SortOrderField extends InputWidget
*/
public function run()
{
$this->field->label(Yii::t('UiModule.form', 'Sort Order'));
$this->field->hint(Yii::t('UiModule.form', 'Values between 0 and 10000, the existing elements usually use steps of 100.'));
$model = $this->model;
$attribute = $this->attribute;
if (!$model->getAttributeLabel($attribute)) {
$this->field->label(Yii::t('UiModule.form', 'Sort Order'));
}
if (!$model->getAttributeHint($attribute)) {
$this->field->hint(Yii::t('UiModule.form', 'Values between 0 and 10000, the existing elements usually use steps of 100.'));
}
if ($this->defaultValue !== null && !is_numeric($model->$attribute)) {
$model->$attribute = $this->defaultValue;
}