Skip to content

Commit

Permalink
Fixed issue #18110: Unable to get empty help in question attributes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Shnoulle committed May 31, 2022
1 parent ac0d01b commit c28e7d0
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 88 deletions.
Expand Up @@ -8,6 +8,13 @@ class AdvancedSettingWidget extends CWidget
/** @var Survey */
public $survey;

const SINGLEINPUTTYPE = array(
'columns',
'integer',
'singleselect',
'text',
'textarea'
);
/**
* @todo Classes instead of array.
* @return void
Expand All @@ -27,8 +34,23 @@ public function run()
if (isset($this->setting['expression']) && $this->setting['expression'] == 2) {
$this->setting['aFormElementOptions']['inputGroup'] = ['prefix' => '{', 'suffix' => '}'];
}

$content = $this->render($this->setting['inputtype'], null, true);
$this->render('layout', ['content' => $content]);
$this->setting['hidden'] = !empty($this->setting['hidden']);
$this->setting['i18n'] = !empty($this->setting['i18n']);
$this->setting['help'] = trim($this->setting['help']);
if ($this->setting['help']) {
/* @fixme : Must be done in Model : QuestionTheme must be allowed to have own translation, plugin can have own translation */
$this->setting['help'] = gT($this->setting['help'], 'unescaped');
}
$inputBaseName = "advancedSettings[" . strtolower($this->setting['category']) . "][" . $this->setting['name'] ."]";
$content = $this->render($this->setting['inputtype'],
['inputBaseName' => $inputBaseName]
, true
);
$this->render('layout',
[
'content' => $content,
'inputBaseName' => $inputBaseName
]
);
}
}
@@ -1,10 +1,13 @@
<div class="btn-group col-12" role="group" data-toggle="buttons">
<div class="btn-group col-12" role="group" data-toggle="buttons"
aria-labelledby="label-<?= CHtml::getIdByName($inputBaseName); ?>"
<?= ($this->setting['help']) ? 'aria-describedby="help-' . CHtml::getIdByName($inputBaseName) . '"' : "" ?>
>
<?php foreach ($this->setting['options'] as $value => $text): ?>
<?php if ($this->setting['value'] == $value): ?>
<label class="btn btn-default active">
<input
type="radio"
name="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>]"
name="<?= $inputBaseName ?>"
value="<?= CHtml::encode($value); ?>"
checked
/>
Expand All @@ -14,7 +17,7 @@
<label class="btn btn-default">
<input
type="radio"
name="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>]"
name="<?= $inputBaseName ?>"
value="<?= CHtml::encode($value); ?>"
/>
<?= $text; ?>
Expand Down
Expand Up @@ -7,7 +7,9 @@
<input
type="number"
class="form-control"
name="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>]"
name="<?= $inputBaseName ?>"
id="<?= CHtml::getIdByName($inputBaseName); ?>"
<?= ($this->setting['help']) ? 'aria-describedby="help-' . CHtml::getIdByName($inputBaseName) . '"' : "" ?>
value="<?= CHtml::encode($this->setting['value']); ?>"
max="12"
min="1"
Expand Down
Expand Up @@ -11,8 +11,9 @@
<input
type="number"
class="form-control"
name="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>]"
id="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>]"
name="<?= $inputBaseName ?>"
id="<?= CHtml::getIdByName($inputBaseName); ?>"
<?= ($this->setting['help']) ? 'aria-describedby="help-' . CHtml::getIdByName($inputBaseName) . '"' : "" ?>
value="<?= CHtml::encode($this->setting['value']); ?>"
/>
<?php if (isset($this->setting['aFormElementOptions']['inputGroup']['suffix'])) : ?>
Expand Down
46 changes: 28 additions & 18 deletions application/extensions/AdvancedSettingWidget/views/layout.php
@@ -1,29 +1,39 @@
<div class="form-group <?= isset($this->setting['hidden']) && $this->setting['hidden'] === '1' ? 'hidden' : '' ?>">
<div class="form-group <?= $this->setting['hidden'] ? 'hidden' : '' ?>">
<div class="question-option-general-setting-block">
<label class="form-label" :for="elId">
<?= gT($this->setting['caption']) ?>
</label>
<?php if (in_array($this->setting['inputtype'], AdvancedSettingWidget::SINGLEINPUTTYPE) && !$this->setting['i18n']): ?>
<label class="form-label" for="<?= CHtml::getIdByName($inputBaseName); ?>">
<?= gT($this->setting['caption']) ?>
</label>
<?php else: ?>
<strong class="form-label" id="label-<?= CHtml::getIdByName($inputBaseName); ?>">
<?= gT($this->setting['caption']) ?>
</strong>
<?php endif; ?>
<!-- TODO: Object method $setting->isLocalized(). -->
<?php if (isset($this->setting['i18n']) && $this->setting['i18n'] == 1): ?>
<?php if ($this->setting['i18n']): ?>
<i
class="fa fa-globe"
data-toggle="tooltip"
title="<?= gT("This setting is localized") ?>"
></i>
<?php endif; ?>
<i
role="button"
class="fa fa-question-circle text-success"
onclick="jQuery('#general-setting-help-<?= $this->setting['name'] ?>').slideToggle()"
data-toggle="tooltip"
title="<?= gT("See help") ?>"
></i>
<?php if ($this->setting['help']): ?>
<a
role="button"
data-toggle="collapse"
href="#help-<?= CHtml::getIdByName($inputBaseName); ?>"
><i
class="fa fa-question-circle text-info"
data-toggle="tooltip"
title="<?= CHtml::encode(strip_tags($this->setting['help'])) ?>"
> </i><span class="sr-only"><?= gT("Show help"); ?></span> </a>
<div class="help-block collapse" id="help-<?= CHtml::getIdByName($inputBaseName); ?>" aria-expanded="false"><?= $this->setting['help']; ?></div>
<?php endif; ?>
<?= $content ?>
<div
id="general-setting-help-<?= $this->setting['name'] ?>"
class="question-option-help well"
>
<?= gT($this->setting['help']) ?>
</div>
</div>
</div>
<script>
function getNames(){
return 'testing';
}
</script>
@@ -1,7 +1,8 @@
<select
class="form-control"
name="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>]"
id="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>]"
name="<?= $inputBaseName ?>"
id="<?= CHtml::getIdByName($inputBaseName); ?>"
<?= ($this->setting['help']) ? 'aria-describedby="help-' . CHtml::getIdByName($inputBaseName) . '"' : "" ?>
>
<?php foreach ($this->setting['options'] as $value => $text) : ?>
<?php if ($this->setting['value'] == $value): ?>
Expand Down
13 changes: 8 additions & 5 deletions application/extensions/AdvancedSettingWidget/views/switch.php
@@ -1,10 +1,13 @@
<div class="inputtype--toggle-container">
<div class="btn-group" role="group" data-toggle="buttons">
<div class="btn-group" role="group" data-toggle="buttons"
aria-labelledby="label-<?= CHtml::getIdByName($inputBaseName); ?>"
<?= ($this->setting['help']) ? 'aria-describedby="help-' . CHtml::getIdByName($inputBaseName) . '"' : "" ?>
>
<?php if ($this->setting['value'] == "1") : ?>
<label class="btn btn-default active">
<input
type="radio"
name="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>]"
name="<?= $inputBaseName ?>"
value="1"
checked
/>
Expand All @@ -13,7 +16,7 @@
<label class="btn btn-default">
<input
type="radio"
name="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>]"
name="<?= $inputBaseName ?>"
value="0"
/>
<?= gT('Off'); ?>
Expand All @@ -22,15 +25,15 @@
<label class="btn btn-default">
<input
type="radio"
name="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>]"
name="<?= $inputBaseName ?>"
value="1"
/>
<?= gT('On'); ?>
</label>
<label class="btn btn-default active">
<input
type="radio"
name="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>]"
name="<?= $inputBaseName ?>"
value="0"
checked
/>
Expand Down
16 changes: 9 additions & 7 deletions application/extensions/AdvancedSettingWidget/views/text.php
@@ -1,30 +1,32 @@
<div class="input-group col-12">
<?php /*

<?php if (isset($this->setting['aFormElementOptions']['inputGroup']['prefix'])) : ?>
<div class="input-group-addon">
<?= $this->setting['aFormElementOptions']['inputGroup']['prefix']; ?>
</div>
<?php endif; ?>
*/ ?>

<?php if (isset($this->setting['i18n']) && $this->setting['i18n'] == 1): ?>
<?php if ($this->setting['i18n']): ?>
<?php foreach ($this->survey->allLanguages as $lang): ?>
<div class="lang-hide lang-<?= $lang; ?>">
<input
type="text"
class="form-control"
name="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>][<?= $lang; ?>]"
id="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>][<?= $lang; ?>]"
name="<?= $inputBaseName; ?>[<?= $lang ?>]"
id="<?= CHtml::getIdByName($inputBaseName . "[" . $lang ."]"); ?>"
value="<?= CHtml::encode($this->setting[$lang]['value']); ?>"
aria-labelledby="label-<?= CHtml::getIdByName($inputBaseName); ?>"
<?= ($this->setting['help']) ? 'aria-describedby="help-' . CHtml::getIdByName($inputBaseName) . '"' : "" ?>
/>
</div>
<?php endforeach; ?>
<?php else: ?>
<input
type="text"
class="form-control"
name="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>]"
id="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>]"
name="<?= $inputBaseName ?>"
id="<?= CHtml::getIdByName($inputBaseName); ?>"
<?= ($this->setting['help']) ? 'aria-describedby="help-' . CHtml::getIdByName($inputBaseName) . '"' : "" ?>
value="<?= CHtml::encode($this->setting['value']); ?>"
/>
<?php endif; ?>
Expand Down
13 changes: 8 additions & 5 deletions application/extensions/AdvancedSettingWidget/views/textarea.php
Expand Up @@ -5,21 +5,24 @@
<?= $this->setting['aFormElementOptions']['inputGroup']['prefix']; ?>
</div>
<?php endif; ?>
<?php if (isset($this->setting['i18n']) && $this->setting['i18n'] == 1): ?>
<?php if ($this->setting['i18n']): ?>
<?php foreach ($this->survey->allLanguages as $lang): ?>
<div class="lang-hide lang-<?= $lang; ?>">
<textarea
class="form-control"
name="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>][<?= $lang; ?>]"
id="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>][<?= $lang; ?>]"
name="<?= $inputBaseName; ?>[<?= $lang; ?>]"
id="<?= CHtml::getIdByName($inputBaseName . "[" . $lang ."]"); ?>"
aria-labelledby="label-<?= CHtml::getIdByName($inputBaseName); ?>"
<?= ($this->setting['help']) ? 'aria-describedby="help-' . CHtml::getIdByName($inputBaseName) . '"' : "" ?>
><?= $this->setting[$lang]['value']; ?></textarea>
</div>
<?php endforeach; ?>
<?php else: ?>
<textarea
class="form-control"
name="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>]"
id="advancedSettings[<?= strtolower($this->setting['category']); ?>][<?= $this->setting['name']; ?>]"
name="<?= $inputBaseName ?>"
id="<?= CHtml::getIdByName($inputBaseName); ?>"
<?= ($this->setting['help']) ? 'aria-describedby="help-' . CHtml::getIdByName($inputBaseName) . '"' : "" ?>
><?= $this->setting['value']; ?></textarea>
<?php endif; ?>
<?php if (isset($this->setting['aFormElementOptions']['inputGroup']['suffix'])) : ?>
Expand Down
17 changes: 7 additions & 10 deletions application/extensions/GeneralOptionWidget/GeneralOptionWidget.php
Expand Up @@ -5,21 +5,18 @@ class GeneralOptionWidget extends CWidget
/** @var GeneralOption */
public $generalOption;

const SINGLEINPUTTYPE = array(
'questiongroup',
'questiontheme',
'text',
'textarea'
);

/**
* @todo Classes instead of switch.
*/
public function run()
{
if ($this->generalOption->inputType === 'buttongroup') {
//echo '<pre>';print_r($this->generalOption->formElement->options);die;
}

//workaround if inputType is text, then take out "" in the middle of the string and replace every " inside the string
//with '
if($this->generalOption->inputType === 'text'){
$this->generalOption->formElement->value = str_replace('"', "'",$this->generalOption->formElement->value);
}

// If the formElement has extra attributes defined, make sure they don't override the basic attributes
if (!empty($this->generalOption->formElement->options['attributes'])) {
unset($this->generalOption->formElement->options['attributes']['id']);
Expand Down
@@ -1,11 +1,14 @@
<div class="btn-group col-12" role="group" data-toggle="buttons">
<div class="btn-group col-12" role="group" data-toggle="buttons"
aria-labelledby="label-<?= CHtml::getIdByName($this->generalOption->name); ?>"
<?= ($this->generalOption->formElement->help) ? 'aria-describedby="help-' . CHtml::getIdByName($this->generalOption->name) . '"' : "" ?>
>
<?php foreach ($this->generalOption->formElement->options['options'] as $i => $option): ?>
<?php if ($this->generalOption->formElement->value == $option->value) : ?>
<label class="btn btn-default active">
<input
type="radio"
name="question[<?= $this->generalOption->name; ?>]"
value="<?= $option->value; ?>"
value="<?= Chtml::encode($option->value); ?>"
checked="checked"
/>
<?= $option->text; ?>
Expand All @@ -15,7 +18,7 @@
<input
type="radio"
name="question[<?= $this->generalOption->name; ?>]"
value="<?= $option->value; ?>"
value="<?= Chtml::encode($option->value); ?>"
/>
<?= $option->text; ?>
</label>
Expand Down
37 changes: 21 additions & 16 deletions application/extensions/GeneralOptionWidget/views/layout.php
@@ -1,21 +1,26 @@
<div class="form-group">
<div class="question-option-general-setting-block">
<label class="form-label">
<?= $this->generalOption->title; ?>
</label>
<i
role="button"
class="fa fa-question-circle text-success"
onclick="jQuery('#general-setting-help-<?= $this->generalOption->name; ?>').slideToggle()"
data-toggle="tooltip"
title="<?= gT("See help"); ?>"
></i>
<?php if (in_array($this->generalOption->inputType, GeneralOptionWidget::SINGLEINPUTTYPE)): ?>
<label class="form-label" for="<?= CHtml::getIdByName($this->generalOption->name); ?>">
<?= $this->generalOption->title; ?>
</label>
<?php else: ?>
<strong class="form-label" id="label-<?= CHtml::getIdByName($this->generalOption->name); ?>">
<?= $this->generalOption->title; ?>
</strong>
<?php endif; ?>
<?php if ($this->generalOption->formElement->help): ?>
<a
role="button"
data-toggle="collapse"
href="#help-<?= CHtml::getIdByName($this->generalOption->name); ?>"
><i
class="fa fa-question-circle text-info"
data-toggle="tooltip"
title="<?= CHtml::encode(strip_tags($this->generalOption->formElement->help)) ?>"
> </i><span class="sr-only"><?= gT("Show help"); ?></span> </a>
<div class="help-block collapse" id="help-<?= CHtml::getIdByName($this->generalOption->name); ?>" aria-expanded="false"><?= $this->generalOption->formElement->help; ?></div>
<?php endif; ?>
<?= $content; ?>
<div
id="general-setting-help-<?= $this->generalOption->name; ?>"
class="question-option-help well"
>
<?= $this->generalOption->formElement->help; ?>
</div>
</div>
</div>
@@ -1,15 +1,16 @@
<select
class="form-control"
name="question[<?= $this->generalOption->name ?>]"
id="<?= $this->generalOption->name ?>"
id="<?= CHtml::getIdByName($this->generalOption->name) ?>"
<?= ($this->generalOption->formElement->help) ? 'aria-describedby="help-' . CHtml::getIdByName($this->generalOption->name) . '"' : "" ?>
<?= $this->generalOption->disabled ? 'disabled' : '' ?>
>
<!-- TODO: Fix weird object reference. -->
<?php foreach ($this->generalOption->formElement->options['options'] as $option) : ?>
<?php if ($this->generalOption->formElement->value == $option->value) : ?>
<option value="<?= $option->value ?>" selected="selected"><?= $option->text ?></option>
<option value="<?= Chtml::encode($option->value) ?>" selected="selected"><?= $option->text ?></option>
<?php else : ?>
<option value="<?= $option->value ?>"><?= $option->text ?></option>
<option value="<?= Chtml::encode($option->value) ?>"><?= $option->text ?></option>
<?php endif; ?>
<?php endforeach; ?>
</select>

0 comments on commit c28e7d0

Please sign in to comment.