Fix: Properly sort language and country select by users locale

Enh: Allow search in country profile field dropdown
This commit is contained in:
Lucas Bartholemy 2017-06-10 18:56:43 +02:00
parent 3b227af3ff
commit 9681319c97
4 changed files with 66 additions and 38 deletions

View File

@ -79,7 +79,7 @@ class HForm extends \yii\base\Component
$this->trigger(self::EVENT_AFTER_VALIDATE); $this->trigger(self::EVENT_AFTER_VALIDATE);
return !$hasErrors; return !$hasErrors;
} }
public function clearErrors() public function clearErrors()
@ -139,7 +139,7 @@ class HForm extends \yii\base\Component
} }
} }
return $output; return $output;
} }
public function renderForm($element) public function renderForm($element)
@ -174,12 +174,12 @@ class HForm extends \yii\base\Component
} }
} }
return $output; return $output;
} }
public function renderField($name, $definition, $forms) public function renderField($name, $definition, $forms)
{ {
if (isset($definition['isVisible']) && !$definition['isVisible'] ) { if (isset($definition['isVisible']) && !$definition['isVisible']) {
return; return;
} }
@ -219,23 +219,27 @@ class HForm extends \yii\base\Component
$options['label'] = $definition['label']; $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; $showLabel = !isset($definition['label']) || $definition['label'] !== false;
if (isset($definition['type'])) { if (isset($definition['type'])) {
switch ($definition['type']) { switch ($definition['type']) {
case 'text': case 'text':
$field = $this->form->field($model, $name)->textInput($options); $field = $this->form->field($model, $name)->textInput($options);
if(!$showLabel) { if (!$showLabel) {
$field->label(false); $field->label(false);
} }
return $field; return $field;
case 'multiselectdropdown': case 'multiselectdropdown':
return \humhub\widgets\MultiSelectField::widget([ return \humhub\widgets\MultiSelectField::widget([
'form' => $this->form, 'form' => $this->form,
'model' => $model, 'model' => $model,
'attribute' => $name, 'attribute' => $name,
'items' => $definition['items'], 'items' => $definition['items'],
'options' => $definition['options'] 'options' => $definition['options']
]); ]);
case 'dropdownlist': case 'dropdownlist':
return $this->form->field($model, $name)->dropDownList($definition['items'], $options); return $this->form->field($model, $name)->dropDownList($definition['items'], $options);
@ -249,14 +253,14 @@ class HForm extends \yii\base\Component
$options['disabled'] = 'disabled'; $options['disabled'] = 'disabled';
} }
$value = $model->$name; $value = $model->$name;
if(is_string($value)) { if (is_string($value)) {
$model->$name = explode(',', $model->$name); $model->$name = explode(',', $model->$name);
} }
return $this->form->field($model, $name)->checkboxList($definition['items'], $options); return $this->form->field($model, $name)->checkboxList($definition['items'], $options);
case 'textarea': case 'textarea':
$field = $this->form->field($model, $name)->textarea($options); $field = $this->form->field($model, $name)->textarea($options);
if(!$showLabel) { if (!$showLabel) {
$field->label(false); $field->label(false);
} }
return $field; return $field;
@ -275,14 +279,14 @@ class HForm extends \yii\base\Component
return $this->form->field($model, $name)->widget(\yii\jui\DatePicker::className(), [ return $this->form->field($model, $name)->widget(\yii\jui\DatePicker::className(), [
'dateFormat' => $format, 'dateFormat' => $format,
'clientOptions' => [ 'clientOptions' => [
'changeYear' => true, 'changeYear' => true,
'yearRange' => $yearRange, 'yearRange' => $yearRange,
'changeMonth' => true, 'changeMonth' => true,
'disabled' => (isset($options['readOnly']) && $options['readOnly']) 'disabled' => (isset($options['readOnly']) && $options['readOnly'])
], ],
'options' => [ 'options' => [
'class' => 'form-control'] 'class' => 'form-control']
]); ]);
case 'markdown': case 'markdown':
$options['id'] = $name; $options['id'] = $name;
$returnField = $this->form->field($model, $name)->textarea($options); $returnField = $this->form->field($model, $name)->textarea($options);

View File

@ -28,6 +28,9 @@ HumHub Change Log
- Fixed #2560: Markdown profile field editable flag not working - Fixed #2560: Markdown profile field editable flag not working
- Fix: Hide also header (space, profile) counts when following system is disabled - 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: 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) 1.2.0 (April 16, 2017)
-------------------------------- --------------------------------

View File

@ -120,7 +120,12 @@ class AccountController extends BaseAccountController
return $this->redirect(['edit-settings']); 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));
} }
/** /**

View File

@ -5,6 +5,7 @@
* @copyright Copyright (c) 2015 HumHub GmbH & Co. KG * @copyright Copyright (c) 2015 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences * @license https://www.humhub.com/licences
*/ */
namespace humhub\modules\user\models\fieldtype; namespace humhub\modules\user\models\fieldtype;
use humhub\modules\user\models\User; use humhub\modules\user\models\User;
@ -28,18 +29,18 @@ class CountrySelect extends Select
public function getFormDefinition($definition = array()) public function getFormDefinition($definition = array())
{ {
return parent::getFormDefinition(array( return parent::getFormDefinition(array(
get_class($this) => array( get_class($this) => array(
'type' => 'form', 'type' => 'form',
'title' => Yii::t('UserModule.models_ProfileFieldTypeSelect', 'Supported ISO3166 country codes'), 'title' => Yii::t('UserModule.models_ProfileFieldTypeSelect', 'Supported ISO3166 country codes'),
'elements' => array( 'elements' => array(
'options' => array( 'options' => array(
'type' => 'textarea', 'type' => 'textarea',
'label' => Yii::t('UserModule.models_ProfileFieldTypeSelect', 'Possible values'), 'label' => Yii::t('UserModule.models_ProfileFieldTypeSelect', 'Possible values'),
'class' => 'form-control', 'class' => 'form-control',
'hint' => Yii::t('UserModule.models_ProfileFieldTypeSelect', 'Comma separated country codes, e.g. DE,EN,AU') 'hint' => Yii::t('UserModule.models_ProfileFieldTypeSelect', 'Comma separated country codes, e.g. DE,EN,AU')
)
)
) )
)
)
)); ));
} }
@ -63,12 +64,16 @@ class CountrySelect extends Select
$key = trim($code); $key = trim($code);
$value = iso3166Codes::country($key, true); $value = iso3166Codes::country($key, true);
if (! empty($key) && $key !== $value) { if (!empty($key) && $key !== $value) {
$items[trim($key)] = trim($value); $items[trim($key)] = trim($value);
} }
} }
} }
// Sort countries list based on user language
$col = new \Collator(Yii::$app->language);
$col->asort($items);
return $items; return $items;
} }
@ -85,10 +90,21 @@ class CountrySelect extends Select
$internalName = $this->profileField->internal_name; $internalName = $this->profileField->internal_name;
$value = $user->profile->$internalName; $value = $user->profile->$internalName;
if (! $raw) { if (!$raw) {
return \yii\helpers\Html::encode(iso3166Codes::country($value)); return \yii\helpers\Html::encode(iso3166Codes::country($value));
} }
return $value; return $value;
} }
/**
* @inheritdoc
*/
public function getFieldFormDefinition()
{
$definition = parent::getFieldFormDefinition();
$definition[$this->profileField->internal_name]['htmlOptions'] = ['data-ui-select2' => true];
return $definition;
}
} }