Merge branch 'master' of https://github.com/nadilnadeem/humhub into nadilnadeem-master

# Conflicts:
#	protected/humhub/compat/HForm.php
This commit is contained in:
Lucas Bartholemy 2016-08-04 10:57:33 +02:00
commit 2f99c02125
4 changed files with 142 additions and 23 deletions

View File

@ -246,6 +246,11 @@ class HForm extends \yii\base\Component
'dateFormat' => $format,
'clientOptions' => ['changeYear' => true, 'yearRange' => $yearRange, 'changeMonth' => true, 'disabled' => (isset($options['readOnly']) && $options['readOnly'])],
'options' => ['class' => 'form-control']]);
case 'markdown':
$options['id'] = $name;
$returnField = $this->form->field($model, $name)->textarea($options);
$returnField . = \humhub\widgets\MarkdownEditor::widget(array('fieldId' => $name));
return $returnField;
default:
return "Field Type " . $definition['type'] . " not supported by Compat HForm";
}

View File

@ -10,6 +10,7 @@ namespace humhub\modules\user\models\fieldtype;
use Yii;
use humhub\modules\user\models\Profile;
use humhub\modules\user\models\fieldtype;
/**
* ProfileFieldType is the base class for all Profile Field Types.
@ -82,6 +83,7 @@ class BaseType extends \yii\base\Model
DateTime::className() => Yii::t('UserModule.models_ProfileFieldType', 'Datetime'),
Birthday::className() => Yii::t('UserModule.models_ProfileFieldType', 'Birthday'),
CountrySelect::className() => Yii::t('UserModule.models_ProfileFieldType', 'Country'),
MarkdownEditor::className() => Yii::t('UserModule.models_ProfileFieldType', 'Markdown'),
), $this->fieldTypes);
return $fieldTypes;
}

View File

@ -0,0 +1,90 @@
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2015 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\user\models\fieldtype;
use Yii;
/**
* ProfileFieldTypeTextArea handles text area profile fields.
*
* @package humhub.modules_core.user.models
* @since 0.5
*/
class MarkdownEditor extends BaseType
{
/**
* Rules for validating the Field Type Settings Form
*
* @return type
*/
public function rules()
{
return array(
#array('maxLength, alphaNumOnly', 'safe'),
);
}
/**
* Returns Form Definition for edit/create this field.
*
* @return Array Form Definition
*/
public function getFormDefinition($definition = array())
{
return parent::getFormDefinition(array(
get_class($this) => array(
'type' => 'form',
'title' => Yii::t('UserModule.models_ProfileFieldTypeTextArea', 'Text area field options'),
'elements' => array(
)
)));
}
/**
* Saves this Profile Field Type
*/
public function save()
{
$columnName = $this->profileField->internal_name;
if (!\humhub\modules\user\models\Profile::columnExists($columnName)) {
$query = Yii::$app->db->getQueryBuilder()->addColumn(\humhub\modules\user\models\Profile::tableName(), $columnName, 'TEXT');
Yii::$app->db->createCommand($query)->execute();
}
return parent::save();
}
/**
* Returns the Field Rules, to validate users input
*
* @param type $rules
* @return type
*/
public function getFieldRules($rules = array())
{
$rules[] = array($this->profileField->internal_name, 'safe');
return parent::getFieldRules($rules);
}
/**
* Return the Form Element to edit the value of the Field
*/
public function getFieldFormDefinition()
{
return array($this->profileField->internal_name => array(
'type' => 'markdown',
'class' => 'form-control',
'rows' => '3'
));
}
}
?>

View File

@ -1,59 +1,81 @@
<?php
use yii\helpers\Html;
use yii\helpers\Html;
?>
<div class="panel panel-default">
<div
class="panel-heading"><?php echo Yii::t('UserModule.views_profile_about', '<strong>About</strong> this user'); ?></div>
<div class="panel-body">
<?php $firstClass = "active"; ?>
<ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
<?php foreach ($user->profile->getProfileFieldCategories() as $category): ?>
<li class="<?php echo $firstClass;
$firstClass = ""; ?>"><a href="#profile-category-<?php echo $category->id; ?>"
data-toggle="tab"><?php echo Html::encode(Yii::t($category->getTranslationCategory(), $category->title)); ?></a>
<li class="<?php echo $firstClass; ?>">
<a href="#profile-category-<?php echo $category->id; ?>" data-toggle="tab"><?php echo Html::encode(Yii::t($category->getTranslationCategory(), $category->title)); ?></a>
</li>
<?php endforeach; ?>
<?php
$firstClass = "";
endforeach; ?>
</ul>
<?php $firstClass = "active"; ?>
<div class="tab-content">
<?php foreach ($user->profile->getProfileFieldCategories() as $category): ?>
<div class="tab-pane <?php echo $firstClass;
$firstClass = ""; ?>" id="profile-category-<?php echo $category->id; ?>">
<form class="form-horizontal" role="form">
<?php foreach ($user->profile->getProfileFields($category) as $field) : ?>
<div class="form-group">
<label
class="col-sm-3 control-label"><?php echo Html::encode(Yii::t($field->getTranslationCategory(), $field->title)); ?></label>
<?php if (strtolower($field->title) == 'about') { ?>
<?php
$fieldType = $field->field_type_class;
//print_r($field);
if (strtolower($field->title) == 'about') {
?>
<div class="col-sm-9">
<p class="form-control-static"><?php echo humhub\widgets\RichText::widget(['text' => $field->getUserValue($user, true)]); ?></p>
<?php
if (strpos($fieldType, 'Markdown') !== false) {
$briefText = \yii\helpers\Markdown::process($field->getUserValue($user, false));
?>
<p class="form-control-static"
style="min-height: 0 !important;padding-top:0;"><?php echo $briefText; ?></p>
<?php } else {
?>
<p class="form-control-static"><?php echo humhub\widgets\RichText::widget(['text' => $field->getUserValue($user, true)]); ?></p>
<?php
}
?>
</div>
<?php } else { ?>
<?php
} else {
?>
<div class="col-sm-9">
<p class="form-control-static"><?php echo $field->getUserValue($user, false); ?></p>
<?php
if (strpos($fieldType, 'Markdown') !== false) {
$briefText = \yii\helpers\Markdown::process($field->getUserValue($user, false));
?>
<p class="form-control-static"
style="min-height: 0 !important;padding-top:0;"><?php echo $briefText; ?></p>
<?php } else {
?>
<p class="form-control-static"><?php echo $field->getUserValue($user, false); ?></p> <?php
}
?>
</div>
<?php } ?>
</div>
<?php endforeach; ?>
</form>
</div>
<?php endforeach; ?>
</div>
</div>
</div>