ThemeSectionArticleModel not working?
Opened this issue · 0 comments
Hey Sven,
this my first attempt to use your extension. I really like the idea of splitting layout articles to a seperate section.
ATM I'm trying add my own logic to the output article, so I use your $GLOBALS['TL_HOOKS']['compileThemeArticle'] Hook.
My files are
src/Ressources/contao/dca/tl_theme_section_article.php
use Contao\CoreBundle\ContaoCoreBundle;
use Contao\CoreBundle\DataContainer\PaletteManipulator;
PaletteManipulator::create()
->addField('container','alias',PaletteManipulator::POSITION_AFTER)
->applyToPalette('default', 'tl_theme_section_article');
// CONTAINER MODE
$GLOBALS['TL_DCA']['tl_theme_section_article']['fields']['container'] = array(
'label' => $GLOBALS['TL_LANG']['tl_theme_section_article']['container'],
'inputType' => 'select',
'options' => ['container','container-fluid'],
'reference' => $GLOBALS['TL_LANG']['tl_theme_section_article']['containerOptions'],
'eval' => ['tl_class'=>'w50', 'includeBlankOption' => true],
'sql' => ['type' => 'string', 'length' => 50, 'default' => ''],
);
src/Ressources/contao/config/config.php
$GLOBALS['TL_HOOKS']['compileThemeArticle'][] = [ArticleListener::class, 'npGetThemeArticle'];
src/EventListener/ArticleListener.php
namespace Neckarpixel\NparticleBundle\EventListener;
use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\ArticleModel;
use Contao\FilesModel;
use Contao\Module;
use Contao\FrontendTemplate;
use Srhinow\ThemeSectionArticleModel;
class ArticleListener
{
public function npGetThemeArticle(FrontendTemplate $template, array $data, Module $module)
{
$objThemeArticle = \ThemeSectionArticleModel::findThemeArticleByIdOrAlias($data->themeArticle);
$arrCssID = $data->cssID;
$strClasses = $arrCssID[1];
// ADD CONTAINER CLASS TO ARTICLE CSS
$strClasses = $strClasses . ' ' . $objThemeArticle->container;
$arrCssID[1] = trim($strClasses);
$data->cssID = $arrCssID;
}
}
What did I wrong?
This is the log file entry
[2021-05-10 14:29:12] request.CRITICAL: Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\ClassNotFoundError: "Attempted to load class "ThemeSectionArticleModel" from the global namespace. Did you forget a "use" statement for "Srhinow\ThemecontentBundle\Model\ThemeSectionArticleModel"?" at /vendor/neckarpixel/contao-nparticle-bundle/src/EventListener/ArticleListener.php line 60 {"exception":"[object] (Symfony\Component\ErrorHandler\Error\ClassNotFoundError(code: 0): Attempted to load class "ThemeSectionArticleModel" from the global namespace.\nDid you forget a "use" statement for "Srhinow\ThemecontentBundle\Model\ThemeSectionArticleModel"? at ...