Closed g0dkar closed 9 years ago
What's the current status of this bug being fixed?
The pull request should be reverted by HumHub developers since it appears the pull author has abandoned it.
@luke- @andystrobel
Hotfix (but i'm not a HumHub developer). Change actionEditField and getTypeInstances functions to:
UserProfileController.php
public function actionEditField() {
// XSS Protection
$_POST = Yii::app()->input->stripClean($_POST);
$id = (int) Yii::app()->request->getQuery('id');
// Get Base Field
$field = ProfileField::model()->findByPk($id);
if ($field == null)
$field = new ProfileField;
// Get all Available Field Class Instances, also bind current profilefield to the type
$profileFieldTypes = new ProfileFieldType();
$fieldTypes = $profileFieldTypes->getTypeInstances();
// Build Form Definition
$definition = array();
#$definition['activeForm'] = array(
# 'class' => 'CActiveForm',
# 'enableAjaxValidation' => true,
# 'id' => 'login-form',
#);
$definition['elements'] = array();
// Add all sub forms
$definition['elements'] = array_merge($definition['elements'], $field->getFormDefinition());
foreach ($fieldTypes as $fieldType) {
$definition['elements'] = array_merge($definition['elements'], $fieldType->getFormDefinition());
}
// Add Form Buttons
$definition['buttons'] = array(
'save' => array(
'type' => 'submit',
'label' => Yii::t('AdminModule.controllers_UserprofileController', 'Save'),
'class' => 'btn btn-primary'
),
);
if (!$field->isNewRecord && !$field->is_system) {
$definition['buttons']['delete'] = array(
'type' => 'submit',
'label' => Yii::t('AdminModule.controllers_UserprofileController', 'Delete'),
'class' => 'btn btn-danger pull-right'
);
}
// Create Form Instance
$form = new HForm($definition);
// Add used models to the CForm, so we can validate it
$form['ProfileField']->model = $field;
foreach ($fieldTypes as $fieldType) {
$form[get_class($fieldType)]->model = $fieldType;
}
// Form Submitted?
if ($form->submitted('save') && $form->validate()) {
$this->forcePostRequest();
// Use ProfileField Instance from Form with new Values
$field = $form['ProfileField']->model;
$fieldType = $form[$field->field_type_class]->model;
$fieldType->setProfileField($field);
$field->save();
$fieldType->save();
$this->redirect(Yii::app()->createUrl('//admin/userprofile'));
}
if ($form->submitted('delete')) {
$this->forcePostRequest();
$field->delete();
$this->redirect(Yii::app()->createUrl('//admin/userprofile'));
}
$this->render('editField', array('form' => $form, 'field' => $field));
}
ProfileFieldType.php
/**
* Returns an array of instances of all available field types.
*
* @return Array
*/
public function getTypeInstances($profileField = null) {
$types = array();
foreach ($this->getFieldTypes() as $className => $title) {
if (Helpers::CheckClassType($className, 'ProfileFieldType')) {
$instance = new $className;
if ($profileField != null) {
$instance->profileField = $profileField;
// Seems current type, so try load data
if ($profileField->field_type_class == $className) {
$instance->load();
}
}
$types[] = $instance;
}
}
return $types;
}
Thank you esemve for the Fix!
Worked, great work!
Hi!
I just learned about HumHub, installed it and it is AMAZING! Truly wonderful! The only problem I've had so far is that I can't change any of the default User Profile fields. I get this error whenever I try to change some info on the default User Profile fields.
I'm trying to hide some of them, and change the name of a few.
I wish I could help more, but since I just started using it (and I'm really rusty on PHP) I'm afraid I can't =/