Skip to content

Commit

Permalink
Merge branch 'hotfix/3.1.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Aug 1, 2017
2 parents bdc3246 + a43ee59 commit 63cba4b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 41 deletions.
3 changes: 2 additions & 1 deletion dca/tl_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
'inputType' => 'pageTree',
'eval' => array('fieldType'=>'radio', 'multiple'=>false, 'rootNodes'=>[0], 'tl_class'=>'w50 clr'),
'sql' => "int(10) unsigned NOT NULL default '0'",
'save_callback' => [['Terminal42\ChangeLanguage\EventListener\DataContainer\PageFieldsListener', 'onSaveLanguageMain']]
'load_callback' => [['Terminal42\ChangeLanguage\EventListener\DataContainer\PageFieldsListener', 'onLoadLanguageMain']],
'save_callback' => [['Terminal42\ChangeLanguage\EventListener\DataContainer\PageFieldsListener', 'onSaveLanguageMain']],
);

$GLOBALS['TL_DCA']['tl_page']['fields']['languageRoot'] = array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,51 @@

namespace Terminal42\ChangeLanguage\EventListener\DataContainer;

use Contao\Database;
use Contao\DataContainer;
use Contao\Input;
use Contao\PageModel;
use Terminal42\ChangeLanguage\PageFinder;

class PageFieldsListener
{
/**
* Sets rootNodes when initializing the languageMain field.
*
* @param mixed $value
* @param DataContainer $dc
*
* @return mixed
*/
public function onLoadLanguageMain($value, DataContainer $dc)
{
if (!$dc->id || 'page' !== Input::get('do')) {
return $value;
}

$page = PageModel::findWithDetails($dc->id);
$root = PageModel::findByPk($page->rootId);

if ($root->fallback
&& (!$root->languageRoot || ($languageRoot = PageModel::findByPk($root->languageRoot)) === null)
) {
return $value;
}

$pageFinder = new PageFinder();
$masterRoot = $pageFinder->findMasterRootForPage($page);

if (null !== $masterRoot) {
$GLOBALS['TL_DCA']['tl_page']['fields']['languageMain']['eval']['rootNodes'] = Database::getInstance()
->prepare('SELECT id FROM tl_page WHERE pid=? ORDER BY sorting')
->execute($masterRoot->id)
->fetchEach('id')
;
}

return $value;
}

/**
* Validate input value when saving tl_page.languageMain field.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@

namespace Terminal42\ChangeLanguage\EventListener\DataContainer;

use Contao\Database;
use Contao\DataContainer;
use Contao\PageModel;
use Haste\Dca\PaletteManipulator;
use Terminal42\ChangeLanguage\PageFinder;

class PageInitializationListener
{
Expand Down Expand Up @@ -47,12 +45,6 @@ public function onLoad(DataContainer $dc)
case 'editAll':
$this->handleEditAllMode();
break;
// Page picker popup
case 'show':
if ('languageMain' === \Input::get('field')) {
$this->setRootNodesForPage($dc->id);
}
break;
}
}

Expand Down Expand Up @@ -88,39 +80,11 @@ private function handleEditAllMode()
$this->addRegularLanguageFields(
array_diff(
array_keys($GLOBALS['TL_DCA']['tl_page']['palettes']),
['__selector__', 'root']
['__selector__', 'root', 'folder']
)
);
}

/**
* Limits the available pages in page picker to the fallback page tree.
*
* @param int $pageId
*/
private function setRootNodesForPage($pageId)
{
$page = PageModel::findWithDetails($pageId);
$root = PageModel::findByPk($page->rootId);

if ($root->fallback
&& (!$root->languageRoot || ($languageRoot = PageModel::findByPk($root->languageRoot)) === null)
) {
return;
}

$pageFinder = new PageFinder();
$masterRoot = $pageFinder->findMasterRootForPage($page);

if (null !== $masterRoot) {
$GLOBALS['TL_DCA']['tl_page']['fields']['languageMain']['eval']['rootNodes'] = Database::getInstance()
->prepare('SELECT id FROM tl_page WHERE pid=? ORDER BY sorting')
->execute($masterRoot->id)
->fetchEach('id')
;
}
}

private function addRootLanguageFields()
{
PaletteManipulator::create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(PageModel $rootPage, $label = null)
);
}

$this->rootPage = $rootPage;
$this->rootPage = $rootPage->loadDetails();
$this->linkLabel = $label;

if (null === $label) {
Expand Down Expand Up @@ -136,7 +136,7 @@ public function getTargetPage()
*/
public function setTargetPage(PageModel $targetPage, $isDirectFallback, $isCurrentPage = false)
{
$this->targetPage = $targetPage;
$this->targetPage = $targetPage->loadDetails();
$this->isDirectFallback = (bool) $isDirectFallback;
$this->isCurrentPage = (bool) $isCurrentPage;
}
Expand Down Expand Up @@ -221,7 +221,7 @@ public function getHref(UrlParameterBag $urlParameterBag)
$href = \Controller::generateFrontendUrl(
$targetPage->row(),
$urlParameterBag->generateParameters(),
$targetPage->language,
$targetPage->rootLanguage,
true
);

Expand Down

0 comments on commit 63cba4b

Please sign in to comment.