mirror of
https://github.com/humhub/humhub.git
synced 2025-01-16 21:58:17 +01:00
Fix: Properly sort language and country select by users locale
Enh: Allow search in country profile field dropdown
This commit is contained in:
parent
3b227af3ff
commit
9681319c97
@ -79,7 +79,7 @@ class HForm extends \yii\base\Component
|
||||
|
||||
$this->trigger(self::EVENT_AFTER_VALIDATE);
|
||||
|
||||
return !$hasErrors;
|
||||
return !$hasErrors;
|
||||
}
|
||||
|
||||
public function clearErrors()
|
||||
@ -139,7 +139,7 @@ class HForm extends \yii\base\Component
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function renderForm($element)
|
||||
@ -174,12 +174,12 @@ class HForm extends \yii\base\Component
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function renderField($name, $definition, $forms)
|
||||
{
|
||||
if (isset($definition['isVisible']) && !$definition['isVisible'] ) {
|
||||
if (isset($definition['isVisible']) && !$definition['isVisible']) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -219,23 +219,27 @@ class HForm extends \yii\base\Component
|
||||
$options['label'] = $definition['label'];
|
||||
}
|
||||
|
||||
if (isset($definition['htmlOptions']) && is_array($definition['htmlOptions'])) {
|
||||
$options = array_merge($options, $definition['htmlOptions']);
|
||||
}
|
||||
|
||||
$showLabel = !isset($definition['label']) || $definition['label'] !== false;
|
||||
|
||||
if (isset($definition['type'])) {
|
||||
switch ($definition['type']) {
|
||||
case 'text':
|
||||
$field = $this->form->field($model, $name)->textInput($options);
|
||||
if(!$showLabel) {
|
||||
if (!$showLabel) {
|
||||
$field->label(false);
|
||||
}
|
||||
return $field;
|
||||
case 'multiselectdropdown':
|
||||
return \humhub\widgets\MultiSelectField::widget([
|
||||
'form' => $this->form,
|
||||
'model' => $model,
|
||||
'attribute' => $name,
|
||||
'items' => $definition['items'],
|
||||
'options' => $definition['options']
|
||||
'form' => $this->form,
|
||||
'model' => $model,
|
||||
'attribute' => $name,
|
||||
'items' => $definition['items'],
|
||||
'options' => $definition['options']
|
||||
]);
|
||||
case 'dropdownlist':
|
||||
return $this->form->field($model, $name)->dropDownList($definition['items'], $options);
|
||||
@ -249,14 +253,14 @@ class HForm extends \yii\base\Component
|
||||
$options['disabled'] = 'disabled';
|
||||
}
|
||||
$value = $model->$name;
|
||||
if(is_string($value)) {
|
||||
if (is_string($value)) {
|
||||
$model->$name = explode(',', $model->$name);
|
||||
}
|
||||
|
||||
return $this->form->field($model, $name)->checkboxList($definition['items'], $options);
|
||||
case 'textarea':
|
||||
$field = $this->form->field($model, $name)->textarea($options);
|
||||
if(!$showLabel) {
|
||||
if (!$showLabel) {
|
||||
$field->label(false);
|
||||
}
|
||||
return $field;
|
||||
@ -275,14 +279,14 @@ class HForm extends \yii\base\Component
|
||||
return $this->form->field($model, $name)->widget(\yii\jui\DatePicker::className(), [
|
||||
'dateFormat' => $format,
|
||||
'clientOptions' => [
|
||||
'changeYear' => true,
|
||||
'yearRange' => $yearRange,
|
||||
'changeMonth' => true,
|
||||
'disabled' => (isset($options['readOnly']) && $options['readOnly'])
|
||||
],
|
||||
'changeYear' => true,
|
||||
'yearRange' => $yearRange,
|
||||
'changeMonth' => true,
|
||||
'disabled' => (isset($options['readOnly']) && $options['readOnly'])
|
||||
],
|
||||
'options' => [
|
||||
'class' => 'form-control']
|
||||
]);
|
||||
'class' => 'form-control']
|
||||
]);
|
||||
case 'markdown':
|
||||
$options['id'] = $name;
|
||||
$returnField = $this->form->field($model, $name)->textarea($options);
|
||||
|
@ -28,6 +28,9 @@ HumHub Change Log
|
||||
- Fixed #2560: Markdown profile field editable flag not working
|
||||
- Fix: Hide also header (space, profile) counts when following system is disabled
|
||||
- Fix: Perma link to space contents broken when space homepage was changed
|
||||
- Fix: Properly sort language and country select by users locale
|
||||
- Enh: Allow search in country profile field dropdown
|
||||
|
||||
|
||||
1.2.0 (April 16, 2017)
|
||||
--------------------------------
|
||||
|
@ -120,7 +120,12 @@ class AccountController extends BaseAccountController
|
||||
return $this->redirect(['edit-settings']);
|
||||
}
|
||||
|
||||
return $this->render('editSettings', array('model' => $model, 'languages' => Yii::$app->i18n->getAllowedLanguages()));
|
||||
// Sort countries list based on user language
|
||||
$languages = Yii::$app->i18n->getAllowedLanguages();
|
||||
$col = new \Collator(Yii::$app->language);
|
||||
$col->asort($languages);
|
||||
|
||||
return $this->render('editSettings', array('model' => $model, 'languages' => $languages));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,6 +5,7 @@
|
||||
* @copyright Copyright (c) 2015 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\modules\user\models\fieldtype;
|
||||
|
||||
use humhub\modules\user\models\User;
|
||||
@ -28,18 +29,18 @@ class CountrySelect extends Select
|
||||
public function getFormDefinition($definition = array())
|
||||
{
|
||||
return parent::getFormDefinition(array(
|
||||
get_class($this) => array(
|
||||
'type' => 'form',
|
||||
'title' => Yii::t('UserModule.models_ProfileFieldTypeSelect', 'Supported ISO3166 country codes'),
|
||||
'elements' => array(
|
||||
'options' => array(
|
||||
'type' => 'textarea',
|
||||
'label' => Yii::t('UserModule.models_ProfileFieldTypeSelect', 'Possible values'),
|
||||
'class' => 'form-control',
|
||||
'hint' => Yii::t('UserModule.models_ProfileFieldTypeSelect', 'Comma separated country codes, e.g. DE,EN,AU')
|
||||
get_class($this) => array(
|
||||
'type' => 'form',
|
||||
'title' => Yii::t('UserModule.models_ProfileFieldTypeSelect', 'Supported ISO3166 country codes'),
|
||||
'elements' => array(
|
||||
'options' => array(
|
||||
'type' => 'textarea',
|
||||
'label' => Yii::t('UserModule.models_ProfileFieldTypeSelect', 'Possible values'),
|
||||
'class' => 'form-control',
|
||||
'hint' => Yii::t('UserModule.models_ProfileFieldTypeSelect', 'Comma separated country codes, e.g. DE,EN,AU')
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
@ -51,7 +52,7 @@ class CountrySelect extends Select
|
||||
public function getSelectItems()
|
||||
{
|
||||
$items = [];
|
||||
|
||||
|
||||
// if no options set basically return a translated map of all defined countries
|
||||
if (empty($this->options) || trim($this->options) == false) {
|
||||
$items = iso3166Codes::$countries;
|
||||
@ -60,15 +61,19 @@ class CountrySelect extends Select
|
||||
}
|
||||
} else {
|
||||
foreach (explode(",", $this->options) as $code) {
|
||||
|
||||
|
||||
$key = trim($code);
|
||||
$value = iso3166Codes::country($key, true);
|
||||
if (! empty($key) && $key !== $value) {
|
||||
if (!empty($key) && $key !== $value) {
|
||||
$items[trim($key)] = trim($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Sort countries list based on user language
|
||||
$col = new \Collator(Yii::$app->language);
|
||||
$col->asort($items);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
@ -84,11 +89,22 @@ class CountrySelect extends Select
|
||||
{
|
||||
$internalName = $this->profileField->internal_name;
|
||||
$value = $user->profile->$internalName;
|
||||
|
||||
if (! $raw) {
|
||||
|
||||
if (!$raw) {
|
||||
return \yii\helpers\Html::encode(iso3166Codes::country($value));
|
||||
}
|
||||
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getFieldFormDefinition()
|
||||
{
|
||||
$definition = parent::getFieldFormDefinition();
|
||||
$definition[$this->profileField->internal_name]['htmlOptions'] = ['data-ui-select2' => true];
|
||||
return $definition;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user