Skip to content

Commit

Permalink
Fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Tastaturberuf committed Aug 2, 2021
1 parent 1d8b38d commit 04c7b3b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
composer.lock
vendor/
42 changes: 29 additions & 13 deletions EventListener/DcaFilesListener.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
<?php // with ♥ and Contao

/**
* ImageCopyright for Contao Open Source CMS
*
* @copyright 2016 – 2020 Tastaturberuf <tastaturberuf.de>
* @copyright 2016 – 2021 Tastaturberuf <tastaturberuf.de>
* @author Daniel Jahnsmüller <tastaturberuf.de>
* @license LGPL-3.0-or-later
*/
Expand All @@ -18,10 +18,10 @@
use Contao\CoreBundle\ServiceAnnotation\Callback;
use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\DataContainer;
use Terminal42\ServiceAnnotationBundle\ServiceAnnotationInterface;
use Contao\Input;


class DcaFilesListener implements ServiceAnnotationInterface
class DcaFilesListener
{

/**
Expand Down Expand Up @@ -91,22 +91,38 @@ public function addFields(string $table): void
*/
public function onLoadCallback(DataContainer $dc = null): void
{
// make sure to have data container and file id
if ( null === $dc || null === $dc->id )
// make sure to have data container
if ( null === $dc )
{
return;
}

$fileExtension = pathinfo($dc->id)['extension'];
// render fields on edit all
if ( 'editAll' === Input::get('act') )
{
$this->addFieldsToPalette($dc->table);
}

if ( in_array($fileExtension, $this->validImageExtensions) )
// render when valid image type
if ( null !== $dc->id )
{
PaletteManipulator::create()
->addLegend('tastaturberuf_image_copyright_legend', 'meta')
->addField(['ic_copyright', 'ic_href', 'ic_hide'], 'tastaturberuf_image_copyright_legend')
->applyToPalette('default', $dc->table)
;
$fileExtension = pathinfo((string) $dc->id)['extension'];

if ( in_array($fileExtension, $this->validImageExtensions) )
{
$this->addFieldsToPalette($dc->table);
}
}
}


private function addFieldsToPalette(string $table): void
{
PaletteManipulator::create()
->addLegend('tastaturberuf_image_copyright_legend', 'meta')
->addField(['ic_copyright', 'ic_href', 'ic_hide'], 'tastaturberuf_image_copyright_legend')
->applyToPalette('default', $table)
;
}

}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ search for `tastaturberuf/contao-image-copyright-bundle`
[Link to the Contao Extension Repository](https://extensions.contao.org/?p=tastaturberuf%2Fcontao-image-copyright-bundle)


## Known issues

- ### Edit multiple files
The backend show fields to all files and directories. This is a technical issue in the
Contao core. **Copyright hints on invalid image types or directories have no impact to the frondend module.**

## Translations

- [ ] Chinese - 中文(简体)
Expand Down

0 comments on commit 04c7b3b

Please sign in to comment.