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' => [ 'operations' => [
'edit' => [ 'edit' => [
'label' => ['Fragen bearbeiten', 'Fragen der Umfrage bearbeiten'],
'href' => 'table=tl_survey_content', 'href' => 'table=tl_survey_content',
'icon' => 'children.svg', 'icon' => 'children.svg',
], ],
'editheader' => [ 'editheader' => [
'label' => ['Umfrage bearbeiten', 'Umfrage bearbeiten'],
'href' => 'act=edit', 'href' => 'act=edit',
'icon' => 'header.svg', 'icon' => 'header.svg',
], ],
'publishedWarning' => [
'label' => &$GLOBALS['TL_LANG']['tl_survey']['publishedWarning'],
'icon' => 'important.svg',
'button_callback' => [SurveyDcaListener::class, 'generatePublishedWarningButton'],
],
'toggle' => [ 'toggle' => [
'label' => &$GLOBALS['TL_LANG']['tl_survey']['toggleActive'], 'label' => &$GLOBALS['TL_LANG']['tl_survey']['toggleActive'],
'href' => 'act=toggle&field=isActive', 'href' => 'act=toggle&field=isActive',
@@ -66,12 +63,20 @@ $GLOBALS['TL_DCA']['tl_survey'] = [
'primary' => true, 'primary' => true,
'showInHeader' => true, 'showInHeader' => true,
], ],
'publishedWarning' => [
'label' => &$GLOBALS['TL_LANG']['tl_survey']['publishedWarning'],
'icon' => 'important.svg',
'primary' => true,
'button_callback' => [SurveyDcaListener::class, 'generatePublishedWarningButton'],
],
'delete' => [ 'delete' => [
'label' => ['Löschen', 'Eintrag wirklich löschen?'],
'href' => 'act=delete', 'href' => 'act=delete',
'icon' => 'delete.svg', 'icon' => 'delete.svg',
'attributes' => 'onclick="if(!confirm(\'Eintrag wirklich löschen?\'))return false;Backend.getScrollOffset()"', 'attributes' => 'onclick="if(!confirm(\'Eintrag wirklich löschen?\'))return false;Backend.getScrollOffset()"',
], ],
'show' => [ 'show' => [
'label' => ['Details', 'Details des Elements ID %s anzeigen'],
'href' => 'act=show', 'href' => 'act=show',
'icon' => 'show.svg', 'icon' => 'show.svg',
], ],
@@ -33,7 +33,6 @@
{% elseif createMode %} {% elseif createMode %}
<div class="survey-card"> <div class="survey-card">
<h3>{{ 'survey.edit.create_title'|trans }}</h3> <h3>{{ 'survey.edit.create_title'|trans }}</h3>
<p>{{ 'survey.edit.create_text'|trans }}</p>
{{ form_start(surveyForm, {attr: {class: 'survey-form-grid'}}) }} {{ form_start(surveyForm, {attr: {class: 'survey-form-grid'}}) }}
<input type="hidden" name="REQUEST_TOKEN" value="{{ contao.request_token }}"> <input type="hidden" name="REQUEST_TOKEN" value="{{ contao.request_token }}">
{{ form_widget(surveyForm._token) }} {{ form_widget(surveyForm._token) }}
@@ -94,11 +93,6 @@
<strong>{{ question.question|striptags|trim ?: ('survey.edit.question_fallback'|trans({'%id%': question.id})) }}</strong> <strong>{{ question.question|striptags|trim ?: ('survey.edit.question_fallback'|trans({'%id%': question.id})) }}</strong>
</span> </span>
</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> </button>
</h4> </h4>
<div class="survey-accordion-panel handorgel__content"> <div class="survey-accordion-panel handorgel__content">
@@ -240,9 +234,9 @@
<article class="survey-card survey-condition-card"> <article class="survey-card survey-condition-card">
{% set sourceLabel = (condition.sourceQuestionLabel|default('')|striptags|trim) ?: ('survey.edit.question_fallback'|trans({'%id%': condition.sourceQuestion})) %} {% 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})) %} {% 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>{{ '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> </article>
{% else %} {% else %}
<div>{{ 'survey.edit.no_conditions'|trans }}</div> <div>{{ 'survey.edit.no_conditions'|trans }}</div>
@@ -337,7 +337,9 @@ final class MemberSurveyEditController extends AbstractFrontendModuleController
{ {
$questionLabels = []; $questionLabels = [];
$questionSortings = []; $questionSortings = [];
$questionPositions = [];
$rules = []; $rules = [];
$position = 1;
foreach ($questions as $question) { foreach ($questions as $question) {
$questionId = (int) ($question->id ?? 0); $questionId = (int) ($question->id ?? 0);
@@ -348,6 +350,7 @@ final class MemberSurveyEditController extends AbstractFrontendModuleController
$questionLabels[$questionId] = (string) ($question->question ?? ''); $questionLabels[$questionId] = (string) ($question->question ?? '');
$questionSortings[$questionId] = (int) ($question->sorting ?? 0); $questionSortings[$questionId] = (int) ($question->sorting ?? 0);
$questionPositions[$questionId] = $position++;
} }
foreach ($questions as $question) { foreach ($questions as $question) {
@@ -371,6 +374,8 @@ final class MemberSurveyEditController extends AbstractFrontendModuleController
'answerValue' => $answerValue, 'answerValue' => $answerValue,
'sourceQuestion' => $questionId, 'sourceQuestion' => $questionId,
'targetQuestion' => $targetQuestionId, 'targetQuestion' => $targetQuestionId,
'sourcePosition' => $questionPositions[$questionId] ?? 0,
'targetPosition' => $questionPositions[$targetQuestionId] ?? 0,
'sourceQuestionLabel' => (string) ($question->question ?? ''), 'sourceQuestionLabel' => (string) ($question->question ?? ''),
'targetQuestionLabel' => $questionLabels[$targetQuestionId] ?? '', 'targetQuestionLabel' => $questionLabels[$targetQuestionId] ?? '',
'sourceSorting' => $questionSortings[$questionId] ?? 0, 'sourceSorting' => $questionSortings[$questionId] ?? 0,
@@ -386,6 +391,8 @@ final class MemberSurveyEditController extends AbstractFrontendModuleController
'answerValue' => (string) ($condition['answerValue'] ?? ''), 'answerValue' => (string) ($condition['answerValue'] ?? ''),
'sourceQuestion' => $sourceQuestionId, 'sourceQuestion' => $sourceQuestionId,
'targetQuestion' => (int) ($condition['targetQuestion'] ?? 0), 'targetQuestion' => (int) ($condition['targetQuestion'] ?? 0),
'sourcePosition' => $questionPositions[$sourceQuestionId] ?? 0,
'targetPosition' => $questionPositions[(int) ($condition['targetQuestion'] ?? 0)] ?? 0,
'sourceQuestionLabel' => (string) ($condition['sourceQuestionLabel'] ?? ''), 'sourceQuestionLabel' => (string) ($condition['sourceQuestionLabel'] ?? ''),
'targetQuestionLabel' => (string) ($condition['targetQuestionLabel'] ?? ''), 'targetQuestionLabel' => (string) ($condition['targetQuestionLabel'] ?? ''),
'sourceSorting' => $questionSortings[$sourceQuestionId] ?? 0, 'sourceSorting' => $questionSortings[$sourceQuestionId] ?? 0,
+42 -32
View File
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Mummert\SurveyBundle\EventListener; namespace Mummert\SurveyBundle\EventListener;
use Contao\Config; use Contao\Config;
use Contao\CoreBundle\DataContainer\DataContainerOperation;
use Contao\CoreBundle\Routing\ContentUrlGenerator; use Contao\CoreBundle\Routing\ContentUrlGenerator;
use Contao\CoreBundle\Framework\ContaoFramework; use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\DataContainer; use Contao\DataContainer;
@@ -37,18 +38,19 @@ final class SurveyDcaListener
return $this->surveyRepository->ensurePublicAlias((string) $value, (int) ($dataContainer->id ?? 0)); 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'); $publicUrl = $this->buildSurveyPageUrl((string) ($row['alias'] ?? ''), 'surveyReaderPage');
$label = 'Link kopieren';
$title = 'Den öffentlichen Link in die Zwischenablage kopieren';
if (null === $publicUrl) { if (null === $publicUrl) {
return sprintf( $operation->setHtml(sprintf(
'<span title="%s">%s</span>', '<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), 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( $copyScript = sprintf(
@@ -58,50 +60,58 @@ final class SurveyDcaListener
json_encode('Bestätigung', JSON_THROW_ON_ERROR), json_encode('Bestätigung', JSON_THROW_ON_ERROR),
); );
return sprintf( $operation->setUrl('#');
'<a href="#" title="%s" onclick="%s"%s>%s</a>', $operation['label'] = 'Link kopieren';
htmlspecialchars($title, ENT_QUOTES), $operation['title'] = 'Den öffentlichen Link in die Zwischenablage kopieren';
htmlspecialchars($copyScript, ENT_QUOTES), $operation['icon'] = 'copy.svg';
$attributes, $operation['attributes']
Image::getHtml($icon ?? 'copy.svg', $label).' '.$label ->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'); $resultsUrl = $this->buildSurveyPageUrl((string) ($row['alias'] ?? ''), 'surveyResultsPage');
$label = 'Ergebnisse anzeigen';
$title = 'Die Ergebnisse dieser Umfrage im Frontend anzeigen';
if (null === $resultsUrl) { if (null === $resultsUrl) {
return sprintf( $operation->setHtml(sprintf(
'<span title="%s">%s</span>', '<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), 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( $operation->setUrl($resultsUrl);
'<a href="%s" title="%s" target="_blank" rel="noreferrer"%s>%s</a>', $operation['label'] = 'Ergebnisse anzeigen';
htmlspecialchars($resultsUrl, ENT_QUOTES), $operation['title'] = 'Die Ergebnisse dieser Umfrage im Frontend anzeigen';
htmlspecialchars($title, ENT_QUOTES), $operation['icon'] = 'show.svg';
$attributes, $operation['attributes']
Image::getHtml($icon ?? 'show.svg', $label).' '.$label ->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'] ?? '')) { if ('1' !== (string) ($row['published'] ?? '')) {
return ''; $operation->setHtml('');
return;
} }
return sprintf( $operation->setHtml(sprintf(
'<span title="%s"%s>%s</span>', '<span title="%s"%s>%s</span>',
htmlspecialchars('Umfrage bereits veröffentlicht, keine Änderungen an den Fragen vornehmen!', ENT_QUOTES), htmlspecialchars('Umfrage bereits veröffentlicht, keine Änderungen an den Fragen vornehmen!', ENT_QUOTES),
$attributes, $operation['attributes'],
Image::getHtml($icon ?? 'important.svg', $label) 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_content q ON q.pid = s.id
LEFT JOIN tl_survey_submission sub ON sub.survey = s.id LEFT JOIN tl_survey_submission sub ON sub.survey = s.id
GROUP BY s.id GROUP BY s.id
ORDER BY s.updatedAt DESC, s.title ASC ORDER BY s.title ASC, s.id ASC
SQL, SQL,
['member' => $memberId], ['member' => $memberId],
); );