Skip to content

Commit

Permalink
Merge pull request #45 from RhymeDigital/php8.1-compat
Browse files Browse the repository at this point in the history
Fix for missing tables in loadLanguageFile hook
  • Loading branch information
rhymeadam committed Feb 9, 2024
2 parents 4580299 + 165a94e commit 7f676fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/Hooks/LoadLanguageFile/LoadElementSets.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use Contao\ContentModel;
use Contao\Controller;
use Contao\Input;
use Contao\Database;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Finder\Finder;
use Veello\ThemeBundle\Cache;
Expand Down Expand Up @@ -114,22 +114,27 @@ protected function loadSetsFromFiles(array &$elements)
*/
protected function loadSetsFromTables(array &$elements)
{
$groupTable = ElementSetGroup::getTable();
$setTable = ElementSet::getTable();

// Load from DCA too - Todo: move to new function
if (($groups = ElementSetGroup::findAll()) !== null)
{
if (Database::getInstance()->tableExists($groupTable) &&
Database::getInstance()->tableExists($setTable) &&
($groups = ElementSetGroup::findAll()) !== null
){
while ($groups->next())
{
$currentGroup = $groups->current();
if (!$currentGroup->alias) continue;

if (($sets = ElementSet::findByPid($currentGroup->id, ['order'=>ElementSet::getTable().".sorting"])) !== null)
if (($sets = ElementSet::findByPid($currentGroup->id, ['order'=>$setTable.".sorting"])) !== null)
{
while ($sets->next())
{
$currentSet = $sets->current();
if (!$currentSet->alias) continue;

if (($contents = ContentModel::findPublishedByPidAndTable($currentSet->id, ElementSet::getTable())) !== null)
if (($contents = ContentModel::findPublishedByPidAndTable($currentSet->id, $setTable)) !== null)
{
$elements[$currentGroup->alias] = $elements[$currentGroup->alias] ?? [];
$elements[$currentGroup->alias][$currentSet->alias] = $elements[$currentGroup->alias][$currentSet->alias] ?? [];
Expand Down
6 changes: 4 additions & 2 deletions src/Hooks/ParseBackendTemplate/AdjustElementSetSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Rhyme\ContaoBackendThemeBundle\Hooks\ParseBackendTemplate;

use Contao\Controller;
use Contao\RequestToken;
use Contao\Database;
use Contao\System;
use Rhyme\ContaoBackendThemeBundle\Constants\Config;
use Rhyme\ContaoBackendThemeBundle\Model\Veello\ElementSet;
Expand All @@ -27,8 +27,10 @@ class AdjustElementSetSelector extends Controller
* @param string $strTemplate
*/
public function run($strBuffer, $strTemplate) {
$setTable = ElementSet::getTable();

if ($strTemplate === 'be_vee_element_set' &&
Database::getInstance()->tableExists($setTable) &&
($elementSets = ElementSet::findAll()) !== null
) {
$data = [];
Expand All @@ -37,7 +39,7 @@ public function run($strBuffer, $strTemplate) {
$params = \http_build_query([
'do' => Config::BE_MOD_VLO_ELEMENT_SETS,
'id' => $current->id,
'table' => ElementSet::getTable(),
'table' => $setTable,
'act' => 'edit',
'popup' => 1,
'rt' => System::getContainer()->get('contao.csrf.token_manager')->getDefaultTokenValue(),
Expand Down

0 comments on commit 7f676fc

Please sign in to comment.