mirror of
https://github.com/humhub/humhub.git
synced 2025-02-12 03:26:25 +01:00
Enh #4191: Added SortOrder Form Input Field
This commit is contained in:
parent
5ebaa01686
commit
8a12acd122
@ -13,6 +13,7 @@ use humhub\modules\content\widgets\richtext\RichTextField;
|
|||||||
use humhub\modules\file\components\FileManager;
|
use humhub\modules\file\components\FileManager;
|
||||||
use humhub\modules\ui\form\widgets\DatePicker;
|
use humhub\modules\ui\form\widgets\DatePicker;
|
||||||
use humhub\modules\ui\form\widgets\MultiSelect;
|
use humhub\modules\ui\form\widgets\MultiSelect;
|
||||||
|
use humhub\modules\ui\form\widgets\SortOrderField;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\helpers\Html;
|
use yii\helpers\Html;
|
||||||
use yii\widgets\ActiveField;
|
use yii\widgets\ActiveField;
|
||||||
@ -261,7 +262,7 @@ class HForm extends \yii\base\Component
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'multiselectdropdown':
|
case 'multiselectdropdown':
|
||||||
$field = $this->form->field($model, $name)->widget(MultiSelect::class, [
|
$field = $this->form->field($model, $name)->widget(MultiSelect::class, [
|
||||||
'items' => $definition['items'],
|
'items' => $definition['items'],
|
||||||
'options' => $definition['options']
|
'options' => $definition['options']
|
||||||
]);
|
]);
|
||||||
@ -293,7 +294,7 @@ class HForm extends \yii\base\Component
|
|||||||
$field = $this->form->field($model, $name)->checkboxList($definition['items'], $options);
|
$field = $this->form->field($model, $name)->checkboxList($definition['items'], $options);
|
||||||
break;
|
break;
|
||||||
case 'textarea':
|
case 'textarea':
|
||||||
if(isset($definition['class'])) {
|
if (isset($definition['class'])) {
|
||||||
$options['class'] = $definition['class'];
|
$options['class'] = $definition['class'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,11 +339,14 @@ class HForm extends \yii\base\Component
|
|||||||
|
|
||||||
$field = $this->form->field($model, $name)->widget(RichTextField::class, $options);
|
$field = $this->form->field($model, $name)->widget(RichTextField::class, $options);
|
||||||
break;
|
break;
|
||||||
|
case 'sortOrder':
|
||||||
|
$field = $this->form->field($model, $name)->widget(SortOrderField::class, $options);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return "Field Type " . $definition['type'] . " not supported by Compat HForm";
|
return "Field Type " . $definition['type'] . " not supported by Compat HForm";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($definition['hint']) && $field instanceof ActiveField) {
|
if (!empty($definition['hint']) && $field instanceof ActiveField) {
|
||||||
$field->hint(Html::encode($definition['hint'], false));
|
$field->hint(Html::encode($definition['hint'], false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,3 +13,4 @@ HumHub Change Log
|
|||||||
- Chg #4158: Cleanup post table removed unused column
|
- Chg #4158: Cleanup post table removed unused column
|
||||||
- Fix #4182: Native edge password reveal icons interferes with custom one
|
- Fix #4182: Native edge password reveal icons interferes with custom one
|
||||||
- Fix #4173: Notification overview HTML compliant issue
|
- Fix #4173: Notification overview HTML compliant issue
|
||||||
|
- Enh #4191: Added SortOrder Form Input Field
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use humhub\modules\ui\form\widgets\SortOrderField;
|
||||||
use yii\widgets\ActiveForm;
|
use yii\widgets\ActiveForm;
|
||||||
use yii\helpers\Url;
|
use yii\helpers\Url;
|
||||||
use yii\helpers\Html;
|
use yii\helpers\Html;
|
||||||
@ -44,7 +45,7 @@ use humhub\modules\space\widgets\SpacePickerField;
|
|||||||
<?= $form->field($group, 'show_at_registration')->checkbox(); ?>
|
<?= $form->field($group, 'show_at_registration')->checkbox(); ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?= $form->field($group, 'show_at_directory')->checkbox(); ?>
|
<?= $form->field($group, 'show_at_directory')->checkbox(); ?>
|
||||||
<?= $form->field($group, 'sort_order'); ?>
|
<?= $form->field($group, 'sort_order')->widget(SortOrderField::class) ?>
|
||||||
|
|
||||||
<?= CHtml::submitButton(Yii::t('AdminModule.user', 'Save'), ['class' => 'btn btn-primary', 'data-ui-loader' => ""]); ?>
|
<?= CHtml::submitButton(Yii::t('AdminModule.user', 'Save'), ['class' => 'btn btn-primary', 'data-ui-loader' => ""]); ?>
|
||||||
|
|
||||||
@ -55,4 +56,4 @@ use humhub\modules\space\widgets\SpacePickerField;
|
|||||||
?>
|
?>
|
||||||
<?php ActiveForm::end(); ?>
|
<?php ActiveForm::end(); ?>
|
||||||
</div>
|
</div>
|
||||||
<?php $this->endContent(); ?>
|
<?php $this->endContent(); ?>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use humhub\modules\ui\form\widgets\ActiveForm;
|
use humhub\modules\ui\form\widgets\ActiveForm;
|
||||||
|
use humhub\modules\ui\form\widgets\SortOrderField;
|
||||||
use humhub\modules\user\models\ProfileFieldCategory;
|
use humhub\modules\user\models\ProfileFieldCategory;
|
||||||
use humhub\widgets\Button;
|
use humhub\widgets\Button;
|
||||||
use yii\helpers\Url;
|
use yii\helpers\Url;
|
||||||
@ -23,11 +24,8 @@ use humhub\libs\Html;
|
|||||||
<?php $form = ActiveForm::begin(); ?>
|
<?php $form = ActiveForm::begin(); ?>
|
||||||
|
|
||||||
<?= $form->field($category, 'title') ?>
|
<?= $form->field($category, 'title') ?>
|
||||||
|
|
||||||
<?= $form->field($category, 'description')->textarea(['rows' => 5]) ?>
|
<?= $form->field($category, 'description')->textarea(['rows' => 5]) ?>
|
||||||
|
<?= $form->field($category, 'sort_order')->widget(SortOrderField::class) ?>
|
||||||
<?= $form->field($category, 'sort_order') ?>
|
|
||||||
|
|
||||||
<?= $form->field($category, 'translation_category') ?>
|
<?= $form->field($category, 'translation_category') ?>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
@ -36,7 +34,7 @@ use humhub\libs\Html;
|
|||||||
|
|
||||||
<?php if (!$category->isNewRecord && !$category->is_system): ?>
|
<?php if (!$category->isNewRecord && !$category->is_system): ?>
|
||||||
<?= Button::danger(Yii::t('AdminModule.user', 'Delete'))
|
<?= Button::danger(Yii::t('AdminModule.user', 'Delete'))
|
||||||
->link(Url::to(['delete-category', 'id' => $category->id]))->confirm()->right()?>
|
->link(Url::to(['delete-category', 'id' => $category->id]))->confirm()->right() ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php ActiveForm::end(); ?>
|
<?php ActiveForm::end(); ?>
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use humhub\modules\ui\form\widgets\SortOrderField;
|
||||||
use humhub\widgets\ModalButton;
|
use humhub\widgets\ModalButton;
|
||||||
use humhub\widgets\ModalDialog;
|
use humhub\widgets\ModalDialog;
|
||||||
use yii\bootstrap\ActiveForm;
|
use yii\bootstrap\ActiveForm;
|
||||||
@ -18,7 +19,7 @@ use yii\bootstrap\ActiveForm;
|
|||||||
<?php $form = ActiveForm::begin() ?>
|
<?php $form = ActiveForm::begin() ?>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<?= $form->field($model, 'name')?>
|
<?= $form->field($model, 'name')?>
|
||||||
<?= $form->field($model, 'sort_order')->textInput( ['type' => 'number'])?>
|
<?= $form->field($model, 'sort_order')->widget(SortOrderField::class) ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<?= ModalButton::submitModal()?>
|
<?= ModalButton::submitModal()?>
|
||||||
|
61
protected/humhub/modules/ui/form/widgets/SortOrderField.php
Normal file
61
protected/humhub/modules/ui/form/widgets/SortOrderField.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @link https://www.humhub.org/
|
||||||
|
* @copyright Copyright (c) 2020 HumHub GmbH & Co. KG
|
||||||
|
* @license https://www.humhub.com/licences
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace humhub\modules\ui\form\widgets;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
use yii\bootstrap\InputWidget;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SortOrderField is a uniform form field for setting a numeric sort order for model classes.
|
||||||
|
*
|
||||||
|
* The label and hint text is set automatically and it is not necessary to implement a attributeLabel or attributeHint
|
||||||
|
* in the model class.
|
||||||
|
*
|
||||||
|
* Future implementations of this class could also output a slider (or similar) instead of a text input field.
|
||||||
|
*
|
||||||
|
* Example usage:
|
||||||
|
*
|
||||||
|
* ```php
|
||||||
|
* <?= $form->field($model, $attribute)->widget(SortOrderField::class, [
|
||||||
|
* // configure additional widget properties here
|
||||||
|
* ]) ?>
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @since 1.6
|
||||||
|
* @package humhub\modules\ui\form\widgets
|
||||||
|
*/
|
||||||
|
class SortOrderField extends InputWidget
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int the default value
|
||||||
|
*/
|
||||||
|
public $defaultValue = 100;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$this->field->label(Yii::t('UiModule.form', 'Sort Order'));
|
||||||
|
$this->field->hint(Yii::t('UiModule.form', 'Value between 0 and 50000, usually in steps of 100.'));
|
||||||
|
|
||||||
|
$model = $this->model;
|
||||||
|
$attribute = $this->attribute;
|
||||||
|
|
||||||
|
if ($this->defaultValue !== null && !is_numeric($model->$attribute)) {
|
||||||
|
$model->$attribute = $this->defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->options['type'] = 'number';
|
||||||
|
return $this->renderInputHtml('text');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -188,7 +188,7 @@ class ProfileField extends ActiveRecord
|
|||||||
'class' => 'form-control',
|
'class' => 'form-control',
|
||||||
],
|
],
|
||||||
'sort_order' => [
|
'sort_order' => [
|
||||||
'type' => 'text',
|
'type' => 'sortOrder',
|
||||||
'maxlength' => 32,
|
'maxlength' => 32,
|
||||||
'class' => 'form-control',
|
'class' => 'form-control',
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user