-
-
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
4 changed files
with
66 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace ContaoNewsRelatedBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\Extension; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
|
||
class ContaoNewsRelatedExtension extends Extension | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | ||
$loader->load('listener.yml'); | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
namespace ContaoNewsRelatedBundle\EventListener; | ||
|
||
use Contao\DataContainer; | ||
use Contao\NewsModel; | ||
|
||
class NewsListener | ||
{ | ||
/** | ||
* Options callback for the related news selection. | ||
* | ||
* @param DataContainer $dc | ||
* | ||
* @return array | ||
*/ | ||
public function relatedNewsOptionsCallback(DataContainer $dc) | ||
{ | ||
$t = NewsModel::getTable(); | ||
$objNews = NewsModel::findAll(['order' => "$t.headline ASC"]); | ||
|
||
$arrOptions = []; | ||
foreach ($objNews as $news) | ||
{ | ||
// skip self | ||
if ('tl_news' == $dc->table && $dc->activeRecord && isset($dc->activeRecord->id) && $dc->activeRecord->id == $news->id) | ||
{ | ||
continue; | ||
} | ||
if ('tl_news' == $dc->parentTable && $dc->activeRecord->pid == $news->id) | ||
{ | ||
continue; | ||
} | ||
|
||
$arrOptions[$news->getRelated('pid')->title][$news->id] = $news->headline; | ||
} | ||
|
||
ksort($arrOptions); | ||
|
||
return $arrOptions; | ||
} | ||
} |
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,3 @@ | ||
services: | ||
contao_newsrelated.listener.news: | ||
class: ContaoNewsRelatedBundle\EventListener\NewsListener |
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