Skip to content

Commit

Permalink
Fix PHPCQ & file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
zonky2 committed Jul 29, 2024
1 parent 32a6fa3 commit 5fc2a61
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 101 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
},
"extra": {
"branch-alias": {
"dev-feature/2.3.0": "2.3.x-dev"
"dev-feature/2.3.0": "2.3.x-dev",
"dev-hotfix/update_phpcq": "2.3.x-dev"
},
"contao-manager-plugin": "ContaoCommunityAlliance\\DcGeneral\\ContaoFrontend\\ContaoManager\\Plugin"
}
Expand Down
5 changes: 3 additions & 2 deletions src/Resources/config/listeners.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
services:
cca.dc-general.contao_frontend.view.build_widget_listener:
class: ContaoCommunityAlliance\DcGeneral\ContaoFrontend\View\DefaultWidgetBuilder
tags:
- { name: kernel.event_listener, event: 'dc-general.contao-frontend.build-widget', method: handleEvent }
arguments:
- '@cca.dc-general.scope-matcher'
- '@translator'
tags:
- { name: kernel.event_listener, event: 'dc-general.contao-frontend.build-widget', method: handleEvent }

cca.dc-general.contao_frontend.handle_submit_listener:
class: ContaoCommunityAlliance\DcGeneral\ContaoFrontend\Listener\HandleSubmitListener
Expand Down
37 changes: 21 additions & 16 deletions src/Resources/contao/templates/dcfe_general_edit.html5
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* This file is part of contao-community-alliance/dc-general-contao-frontend.
*
* (c) 2015-2021 Contao Community Alliance.
* (c) 2015-2024 Contao Community Alliance.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -13,40 +13,45 @@
* @package contao-community-alliance/dc-general-contao-frontend
* @author Christian Schiffler <[email protected]>
* @author Ingolf Steinhardt <[email protected]>
* @copyright 2015-2021 Contao Community Alliance.
* @copyright 2015-2024 Contao Community Alliance.
* @license https://github.com/contao-community-alliance/dc-general-contao-frontend/blob/master/LICENSE LGPL-3.0
* @filesource
*/

use Contao\StringUtil;
use Contao\System;

$requestToken = System::getContainer()->get('contao.csrf.token_manager')->getDefaultTokenValue();
?>
<h2 class="sub_headline"><?= $this->subHeadline; ?></h2>
<?= $this->getMessages(); ?>
<?= $this->getMessages() ?>

<form method="post"
action="<?= ampersand(\Environment::get('request'), true); ?>"
id="<?= $this->table; ?>"
enctype="<?= $this->enctype; ?>"
action="<?= StringUtil::ampersand(\Environment::get('request')) ?>"
id="<?= $this->table ?>"
enctype="<?= $this->enctype ?>"
>
<div class="formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="<?= \Contao\StringUtil::specialchars($this->table); ?>"/>
<input type="hidden" name="REQUEST_TOKEN" value="<?= REQUEST_TOKEN; ?>"/>
<?php if ($this->error): ?><p class="tl_error"><?= implode('<br />', $this->error); ?></p><?php endif; ?>
<input type="hidden" name="FORM_SUBMIT" value="<?= StringUtil::specialchars($this->table) ?>"/>
<input type="hidden" name="REQUEST_TOKEN" value="<?= $requestToken ?>"/>
<?php if ($this->error): ?><p class="tl_error"><?= implode('<br />', $this->error) ?></p><?php endif; ?>
<?php foreach ($this->fieldsets as $arrFieldset): ?>
<?php if ($arrFieldset['legend']): ?>
<fieldset id="pal_<?= \Contao\StringUtil::specialchars($arrFieldset['legend']); ?>"
class="<?= $arrFieldset['class']; ?> block">
<legend><?= $arrFieldset['label']; ?></legend>
<?= $arrFieldset['palette']; ?>
<fieldset id="pal_<?= StringUtil::specialchars($arrFieldset['legend']) ?>"
class="<?= $arrFieldset['class'] ?> block">
<legend><?= $arrFieldset['label'] ?></legend>
<?= $arrFieldset['palette'] ?>
</fieldset>
<?php else: ?>
<fieldset class="<?= $arrFieldset['class']; ?> block nolegend">
<?= $arrFieldset['palette']; ?>
<fieldset class="<?= $arrFieldset['class'] ?> block nolegend">
<?= $arrFieldset['palette'] ?>
</fieldset>
<?php endif; ?>
<?php endforeach; ?>
</div>
<div class="formbody_submit">
<div class="submit_container">
<?= implode(' ', $this->editButtons); ?>
<?= implode(' ', $this->editButtons) ?>
</div>
</div>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,15 @@
<?php if ($this->deselect): ?>
<div class="file-reset">
<label for="ctrl_reset_<?= $this->id ?>_<?= $key ?>"><?= $this->trans('MSC.reset') ?></label>
<input type="checkbox" name="<?= $this->name ?>[reset][]"
<input type="checkbox" name="<?= $this->name ?>__reset[]"
id="ctrl_reset_<?= $this->id ?>_<?= $key ?>"
value="<?= \Contao\StringUtil::binToUuid($file['uuid']) ?>">
</div>
<?php endif; ?>
<?php if ($this->delete): ?>
<div class="file-delete">
<label for="ctrl_delete_<?= $this->id ?>_<?= $key ?>"><?= $this->trans(
'MSC.delete'
) ?></label>
<input type="checkbox" name="<?= $this->name ?>[delete][]"
<label for="ctrl_delete_<?= $this->id ?>_<?= $key ?>"><?= $this->trans('MSC.delete') ?></label>
<input type="checkbox" name="<?= $this->name ?>__delete[]"
id="ctrl_delete_<?= $this->id ?>_<?= $key ?>"
value="<?= \Contao\StringUtil::binToUuid($file['uuid']) ?>">
</div>
Expand Down
27 changes: 22 additions & 5 deletions src/View/DefaultWidgetBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace ContaoCommunityAlliance\DcGeneral\ContaoFrontend\View;

use Contao\System;
use Contao\Widget;
use ContaoCommunityAlliance\Contao\Bindings\ContaoEvents;
use ContaoCommunityAlliance\Contao\Bindings\Events\Widget\GetAttributesFromDcaEvent;
Expand All @@ -35,6 +36,7 @@
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\Properties\PropertyInterface;
use ContaoCommunityAlliance\DcGeneral\EnvironmentInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* Widget Builder to build Contao frontend widgets.
Expand All @@ -51,14 +53,23 @@ class DefaultWidgetBuilder
*/
private RequestScopeDeterminator $scopeDeterminator;

/**
* The translator.
*
* @var TranslatorInterface
*/
private TranslatorInterface $translator;

/**
* DefaultWidgetBuilder constructor.
*
* @param RequestScopeDeterminator $scopeDeterminator The request scope determinator.
* @param TranslatorInterface $translator The translator.
*/
public function __construct(RequestScopeDeterminator $scopeDeterminator)
public function __construct(RequestScopeDeterminator $scopeDeterminator, TranslatorInterface $translator)
{
$this->scopeDeterminator = $scopeDeterminator;
$this->translator = $translator;
}

/**
Expand Down Expand Up @@ -159,12 +170,18 @@ public function buildWidget(
$propExtra['class'] = $this->addCssClass($propExtra['class'], $propExtra['tl_class']);
}

// If no description present, pass as string instead of array.
$label = $this->translator->trans($property->getLabel(), [], $defName);
if ('' !== $description = $property->getDescription()) {
$label = [
$label,
$this->translator->trans($description, [], $defName),
];
}

$arrConfig = [
'inputType' => $property->getWidgetType(),
'label' => [
$property->getLabel(),
$property->getDescription()
],
'label' => $label,
'options' => $this->getOptionsForWidget($environment, $property, $model),
'eval' => $propExtra,
];
Expand Down
Loading

0 comments on commit 5fc2a61

Please sign in to comment.