Skip to content

Commit

Permalink
Show error instead of exception for incomplete configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
dmolineus committed Sep 3, 2024
1 parent c925f8a commit 0e3f221
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
12 changes: 11 additions & 1 deletion src/EventListener/ReferencesDcaListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
use Contao\StringUtil;
use Doctrine\DBAL\Connection;
use Hofff\Contao\Content\Reference\ReferenceRegistry;
use InvalidArgumentException;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Translation\TranslatorInterface;
use Terminal42\DcawizardBundle\Widget\DcaWizard;

use function array_merge;
Expand All @@ -25,6 +27,7 @@ public function __construct(
private Connection $connection,
private RequestStack $requestStack,
private ReferenceRegistry $referenceRegistry,
private TranslatorInterface $translator,
) {
}

Expand Down Expand Up @@ -66,7 +69,14 @@ public function referencesList(array $records, string|int $rowId, DcaWizard $wiz
#[AsCallback('tl_hofff_content', 'list.label.label')]
public function onLabel(array $row): string
{
$reference = $this->referenceRegistry->get($row['type']);
try {
$reference = $this->referenceRegistry->get($row['type']);
} catch (InvalidArgumentException) {
return Image::getHtml('error.svg')
. ' <span class="hofff-content-error">'
. $this->translator->trans('ERR.hoffContentUnknownType', [], 'contao_default')
. '</span>';
}

return Image::getHtml($reference->backendIcon($row)) . ' ' . $reference->backendLabel($row);
}
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<argument type="service" id="database_connection"/>
<argument type="service" id="request_stack"/>
<argument type="service" id="Hofff\Contao\Content\Reference\ReferenceRegistry"/>
<argument type="service" id="translator"/>
</service>

<service id="Hofff\Contao\Content\Migration\DeleteContentTreeViewMigration">
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/contao/languages/de/hofff_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
. ' Zum Beispiel fügt das Template "hofff_content_container" einen gemeinsamen'
. ' "div"-Container um alle Artikel herum. Wird kein Template gewählt werden'
. ' die Artikel hintereinanderweg ausgegeben.';

$GLOBALS['TL_LANG']['ERR']['hoffContentUnknownType'] = 'Unbekannter Referenztyp';
1 change: 1 addition & 0 deletions src/Resources/contao/languages/en/hofff_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
$GLOBALS['TL_LANG']['hofff_content']['template'][1] = 'The selected template defines, how the articles are rendered. Selecting'
. ' no template will render them directly one after another.';

$GLOBALS['TL_LANG']['ERR']['hoffContentUnknownType'] = 'Unknown reference type';
16 changes: 2 additions & 14 deletions src/Resources/public/css/hofff_content.css
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@

.hofff-content .hofff-selectri-content {
display: none;
box-sizing: border-box;
padding: 10px;
clear: both;
width: 100%;
}

.hofff-content .hofff-selectri-selection .hofff-selectri-content {
display: table;
}

.hofff-content-edit {
padding-right: 10px;
}
Expand All @@ -23,6 +11,6 @@
color: #b3b3b3;
}

.hofff-selectri-path .hofff-content-label {
display: none;
.hofff-content-error {
color: #c33;
}

0 comments on commit 0e3f221

Please sign in to comment.