-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
243 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/EventListener/DataContainer/NewsArchiveLangPidOptionsCallbackListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Guave\DeeplBundle\EventListener\DataContainer; | ||
|
||
use Contao\Controller; | ||
use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback; | ||
use Contao\DataContainer; | ||
use Contao\NewsArchiveModel; | ||
|
||
#[AsCallback(table: 'tl_news_archive', target: 'fields.langPid.options')] | ||
class NewsArchiveLangPidOptionsCallbackListener | ||
{ | ||
public function __invoke(DataContainer $dataContainer): array | ||
{ | ||
Controller::loadDataContainer(NewsArchiveModel::class); | ||
|
||
$array = []; | ||
|
||
$archives = NewsArchiveModel::findAll(); | ||
if ($archives) { | ||
foreach ($archives as $a) { | ||
$array[$a->id] = $a->title . ' (' . $a->language . ')'; | ||
} | ||
} | ||
|
||
return $array; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/EventListener/DataContainer/NewsArchiveLanguageOptionsCallbackListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Guave\DeeplBundle\EventListener\DataContainer; | ||
|
||
use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback; | ||
use Contao\DataContainer; | ||
use Guave\DeeplBundle\Model\MultilingualModel; | ||
|
||
#[AsCallback(table: 'tl_news_archive', target: 'fields.language.options')] | ||
class NewsArchiveLanguageOptionsCallbackListener | ||
{ | ||
public function __invoke(DataContainer $dataContainer): array | ||
{ | ||
return MultilingualModel::getRootPageLanguages(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/Resolver/ActiveLanguageByNewsArchiveLanguageResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Guave\DeeplBundle\Resolver; | ||
|
||
use Contao\DataContainer; | ||
use Contao\Input; | ||
use Contao\NewsArchiveModel; | ||
|
||
class ActiveLanguageByNewsArchiveLanguageResolver implements ActiveLanguageResolverInterface | ||
{ | ||
public function supports(DataContainer $dataContainer): bool | ||
{ | ||
if ($dataContainer->table === NewsArchiveModel::getTable() && Input::get('do') === 'news' && Input::get('act') === 'edit') { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function resolve(DataContainer $dataContainer): ?string | ||
{ | ||
$newsArchive = NewsArchiveModel::findOneBy('id', (int) Input::get('id')); | ||
|
||
return $newsArchive->language ?? null; | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/Resolver/ActiveLanguageByNewsContentLanguageResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Guave\DeeplBundle\Resolver; | ||
|
||
use Contao\ContentModel; | ||
use Contao\DataContainer; | ||
use Contao\NewsArchiveModel; | ||
use Contao\NewsModel; | ||
|
||
class ActiveLanguageByNewsContentLanguageResolver implements ActiveLanguageResolverInterface | ||
{ | ||
public function supports(DataContainer $dataContainer): bool | ||
{ | ||
if ($dataContainer->table === ContentModel::getTable() && \Input::get('do') === 'news') { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function resolve(DataContainer $dataContainer): ?string | ||
{ | ||
$content = ContentModel::findOneBy('id', (int) \Input::get('id')); | ||
|
||
$news = NewsModel::findOneBy('id', (int) $content->pid); | ||
|
||
$newsArchive = NewsArchiveModel::findOneBy('id', (int) $news->pid); | ||
|
||
return $newsArchive->language ?? null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Guave\DeeplBundle\Resolver; | ||
|
||
use Contao\DataContainer; | ||
use Contao\NewsArchiveModel; | ||
use Contao\NewsModel; | ||
|
||
class ActiveLanguageByNewsLanguageResolver implements ActiveLanguageResolverInterface | ||
{ | ||
public function supports(DataContainer $dataContainer): bool | ||
{ | ||
if ($dataContainer->table === NewsModel::getTable() && \Input::get('do') === 'news') { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function resolve(DataContainer $dataContainer): ?string | ||
{ | ||
$news = NewsModel::findOneBy('id', (int) \Input::get('id')); | ||
|
||
if ($news) { | ||
$newsArchive = NewsArchiveModel::findOneBy('id', (int) $news->pid); | ||
|
||
return $newsArchive->language ?? null; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Contao\Controller; | ||
use Contao\CoreBundle\DataContainer\PaletteManipulator; | ||
use Contao\NewsArchiveModel; | ||
|
||
$table = NewsArchiveModel::getTable(); | ||
Controller::loadLanguageFile($table); | ||
|
||
PaletteManipulator::create() | ||
->addField('language', 'title_legend', PaletteManipulator::POSITION_APPEND) | ||
->addField('langPid', 'title_legend', PaletteManipulator::POSITION_APPEND) | ||
->applyToPalette('default', 'tl_news_archive') | ||
; | ||
|
||
/** | ||
* LIST | ||
*/ | ||
$GLOBALS['TL_DCA'][$table]['list']['label']['fields'] = ['title', 'language']; | ||
$GLOBALS['TL_DCA'][$table]['list']['label']['format'] = '%s <span style="color:#999;">(%s)</span>'; | ||
|
||
/** | ||
* FIELDS | ||
*/ | ||
$GLOBALS['TL_DCA'][$table]['fields']['language'] = [ | ||
'label' => &$GLOBALS['TL_LANG'][$table]['language'], | ||
'exclude' => true, | ||
'inputType' => 'select', | ||
'filter' => true, | ||
'eval' => [ | ||
'mandatory' => true, | ||
'tl_class' => 'w50 clr', | ||
'chosen' => true, | ||
'includeBlankOption' => true, | ||
], | ||
'sql' => ['type' => 'string', 'length' => 2, 'default' => ''], | ||
]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Contao\NewsArchiveModel; | ||
|
||
$table = NewsArchiveModel::getTable(); | ||
|
||
$GLOBALS['TL_DCA'][$table]['language'] = ['Sprache']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Contao\NewsArchiveModel; | ||
|
||
$table = NewsArchiveModel::getTable(); | ||
|
||
$GLOBALS['TL_DCA'][$table]['language'] = ['language']; |