Fix backend survey action labels

This commit is contained in:
Jürgen Mummert
2026-06-07 21:45:42 +02:00
parent 4b82d70117
commit 497b4f962d
5 changed files with 62 additions and 46 deletions
+10 -5
View File
@@ -47,18 +47,15 @@ $GLOBALS['TL_DCA']['tl_survey'] = [
],
'operations' => [
'edit' => [
'label' => ['Fragen bearbeiten', 'Fragen der Umfrage bearbeiten'],
'href' => 'table=tl_survey_content',
'icon' => 'children.svg',
],
'editheader' => [
'label' => ['Umfrage bearbeiten', 'Umfrage bearbeiten'],
'href' => 'act=edit',
'icon' => 'header.svg',
],
'publishedWarning' => [
'label' => &$GLOBALS['TL_LANG']['tl_survey']['publishedWarning'],
'icon' => 'important.svg',
'button_callback' => [SurveyDcaListener::class, 'generatePublishedWarningButton'],
],
'toggle' => [
'label' => &$GLOBALS['TL_LANG']['tl_survey']['toggleActive'],
'href' => 'act=toggle&field=isActive',
@@ -66,12 +63,20 @@ $GLOBALS['TL_DCA']['tl_survey'] = [
'primary' => true,
'showInHeader' => true,
],
'publishedWarning' => [
'label' => &$GLOBALS['TL_LANG']['tl_survey']['publishedWarning'],
'icon' => 'important.svg',
'primary' => true,
'button_callback' => [SurveyDcaListener::class, 'generatePublishedWarningButton'],
],
'delete' => [
'label' => ['Löschen', 'Eintrag wirklich löschen?'],
'href' => 'act=delete',
'icon' => 'delete.svg',
'attributes' => 'onclick="if(!confirm(\'Eintrag wirklich löschen?\'))return false;Backend.getScrollOffset()"',
],
'show' => [
'label' => ['Details', 'Details des Elements ID %s anzeigen'],
'href' => 'act=show',
'icon' => 'show.svg',
],
@@ -33,7 +33,6 @@
{% elseif createMode %}
<div class="survey-card">
<h3>{{ 'survey.edit.create_title'|trans }}</h3>
<p>{{ 'survey.edit.create_text'|trans }}</p>
{{ form_start(surveyForm, {attr: {class: 'survey-form-grid'}}) }}
<input type="hidden" name="REQUEST_TOKEN" value="{{ contao.request_token }}">
{{ form_widget(surveyForm._token) }}
@@ -94,11 +93,6 @@
<strong>{{ question.question|striptags|trim ?: ('survey.edit.question_fallback'|trans({'%id%': question.id})) }}</strong>
</span>
</span>
<span class="survey-meta survey-accordion-actions">
<span class="survey-badge neutral">{{ ('survey.survey.question_type_' ~ question.type)|trans }}</span>
{% if question.mandatory %}<span class="survey-badge warning">{{ 'survey.edit.mandatory_badge'|trans }}</span>{% endif %}
{% if loop.first %}<span class="survey-badge success">{{ 'survey.edit.start_badge'|trans }}</span>{% endif %}
</span>
</button>
</h4>
<div class="survey-accordion-panel handorgel__content">
@@ -240,9 +234,9 @@
<article class="survey-card survey-condition-card">
{% set sourceLabel = (condition.sourceQuestionLabel|default('')|striptags|trim) ?: ('survey.edit.question_fallback'|trans({'%id%': condition.sourceQuestion})) %}
{% set targetLabel = (condition.targetQuestionLabel|default('')|striptags|trim) ?: ('survey.edit.question_fallback'|trans({'%id%': condition.targetQuestion})) %}
<div><strong>Frage {{ condition.sourceQuestion }}: {{ sourceLabel }}</strong></div>
<div><strong>Frage {{ condition.sourcePosition ?: condition.sourceQuestion }}: {{ sourceLabel }}</strong></div>
<div>{{ 'survey.edit.condition_prefix'|trans({'%value%': condition.answerValue|default('')|striptags|trim|capitalize}) }}</div>
<div>weiter zu Frage {{ condition.targetQuestion }}: {{ targetLabel }}</div>
<div>weiter zu Frage {{ condition.targetPosition ?: condition.targetQuestion }}: {{ targetLabel }}</div>
</article>
{% else %}
<div>{{ 'survey.edit.no_conditions'|trans }}</div>
@@ -337,7 +337,9 @@ final class MemberSurveyEditController extends AbstractFrontendModuleController
{
$questionLabels = [];
$questionSortings = [];
$questionPositions = [];
$rules = [];
$position = 1;
foreach ($questions as $question) {
$questionId = (int) ($question->id ?? 0);
@@ -348,6 +350,7 @@ final class MemberSurveyEditController extends AbstractFrontendModuleController
$questionLabels[$questionId] = (string) ($question->question ?? '');
$questionSortings[$questionId] = (int) ($question->sorting ?? 0);
$questionPositions[$questionId] = $position++;
}
foreach ($questions as $question) {
@@ -371,6 +374,8 @@ final class MemberSurveyEditController extends AbstractFrontendModuleController
'answerValue' => $answerValue,
'sourceQuestion' => $questionId,
'targetQuestion' => $targetQuestionId,
'sourcePosition' => $questionPositions[$questionId] ?? 0,
'targetPosition' => $questionPositions[$targetQuestionId] ?? 0,
'sourceQuestionLabel' => (string) ($question->question ?? ''),
'targetQuestionLabel' => $questionLabels[$targetQuestionId] ?? '',
'sourceSorting' => $questionSortings[$questionId] ?? 0,
@@ -386,6 +391,8 @@ final class MemberSurveyEditController extends AbstractFrontendModuleController
'answerValue' => (string) ($condition['answerValue'] ?? ''),
'sourceQuestion' => $sourceQuestionId,
'targetQuestion' => (int) ($condition['targetQuestion'] ?? 0),
'sourcePosition' => $questionPositions[$sourceQuestionId] ?? 0,
'targetPosition' => $questionPositions[(int) ($condition['targetQuestion'] ?? 0)] ?? 0,
'sourceQuestionLabel' => (string) ($condition['sourceQuestionLabel'] ?? ''),
'targetQuestionLabel' => (string) ($condition['targetQuestionLabel'] ?? ''),
'sourceSorting' => $questionSortings[$sourceQuestionId] ?? 0,
+42 -32
View File
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Mummert\SurveyBundle\EventListener;
use Contao\Config;
use Contao\CoreBundle\DataContainer\DataContainerOperation;
use Contao\CoreBundle\Routing\ContentUrlGenerator;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\DataContainer;
@@ -37,18 +38,19 @@ final class SurveyDcaListener
return $this->surveyRepository->ensurePublicAlias((string) $value, (int) ($dataContainer->id ?? 0));
}
public function generateCopyPublicLinkButton(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes): string
public function generateCopyPublicLinkButton(DataContainerOperation $operation): void
{
$row = $operation->getRecord() ?? [];
$publicUrl = $this->buildSurveyPageUrl((string) ($row['alias'] ?? ''), 'surveyReaderPage');
$label = 'Link kopieren';
$title = 'Den öffentlichen Link in die Zwischenablage kopieren';
if (null === $publicUrl) {
return sprintf(
$operation->setHtml(sprintf(
'<span title="%s">%s</span>',
htmlspecialchars('In den Contao-Einstellungen ist noch keine Reader-Seite hinterlegt oder der Link-Schlüssel ist ungültig.', ENT_QUOTES),
Image::getHtml($icon ?? 'copy.svg', $label)
);
Image::getHtml('copy.svg', 'Link kopieren')
));
return;
}
$copyScript = sprintf(
@@ -58,50 +60,58 @@ final class SurveyDcaListener
json_encode('Bestätigung', JSON_THROW_ON_ERROR),
);
return sprintf(
'<a href="#" title="%s" onclick="%s"%s>%s</a>',
htmlspecialchars($title, ENT_QUOTES),
htmlspecialchars($copyScript, ENT_QUOTES),
$attributes,
Image::getHtml($icon ?? 'copy.svg', $label).' '.$label
);
$operation->setUrl('#');
$operation['label'] = 'Link kopieren';
$operation['title'] = 'Den öffentlichen Link in die Zwischenablage kopieren';
$operation['icon'] = 'copy.svg';
$operation['attributes']
->set('onclick', $copyScript)
->set('data-contao--tooltips-target', 'tooltip')
;
}
public function generateShowResultsButton(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes): string
public function generateShowResultsButton(DataContainerOperation $operation): void
{
$row = $operation->getRecord() ?? [];
$resultsUrl = $this->buildSurveyPageUrl((string) ($row['alias'] ?? ''), 'surveyResultsPage');
$label = 'Ergebnisse anzeigen';
$title = 'Die Ergebnisse dieser Umfrage im Frontend anzeigen';
if (null === $resultsUrl) {
return sprintf(
$operation->setHtml(sprintf(
'<span title="%s">%s</span>',
htmlspecialchars('In den Contao-Einstellungen ist noch keine Ergebnisseite hinterlegt oder der Link-Schlüssel ist ungültig.', ENT_QUOTES),
Image::getHtml($icon ?? 'show.svg', $label)
);
Image::getHtml('show.svg', 'Ergebnisse anzeigen')
));
return;
}
return sprintf(
'<a href="%s" title="%s" target="_blank" rel="noreferrer"%s>%s</a>',
htmlspecialchars($resultsUrl, ENT_QUOTES),
htmlspecialchars($title, ENT_QUOTES),
$attributes,
Image::getHtml($icon ?? 'show.svg', $label).' '.$label
);
$operation->setUrl($resultsUrl);
$operation['label'] = 'Ergebnisse anzeigen';
$operation['title'] = 'Die Ergebnisse dieser Umfrage im Frontend anzeigen';
$operation['icon'] = 'show.svg';
$operation['attributes']
->set('target', '_blank')
->set('rel', 'noreferrer')
->set('data-contao--tooltips-target', 'tooltip')
;
}
public function generatePublishedWarningButton(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes): string
public function generatePublishedWarningButton(DataContainerOperation $operation): void
{
$row = $operation->getRecord() ?? [];
if ('1' !== (string) ($row['published'] ?? '')) {
return '';
$operation->setHtml('');
return;
}
return sprintf(
$operation->setHtml(sprintf(
'<span title="%s"%s>%s</span>',
htmlspecialchars('Umfrage bereits veröffentlicht, keine Änderungen an den Fragen vornehmen!', ENT_QUOTES),
$attributes,
Image::getHtml($icon ?? 'important.svg', $label)
);
$operation['attributes'],
Image::getHtml('important.svg', 'Veröffentlichungshinweis')
));
}
/**
+1 -1
View File
@@ -76,7 +76,7 @@ final class SurveyRepository
LEFT JOIN tl_survey_content q ON q.pid = s.id
LEFT JOIN tl_survey_submission sub ON sub.survey = s.id
GROUP BY s.id
ORDER BY s.updatedAt DESC, s.title ASC
ORDER BY s.title ASC, s.id ASC
SQL,
['member' => $memberId],
);