Skip to content

Commit

Permalink
exploreimpact#76 Bugfix: Refactoring handling of page type. Creating …
Browse files Browse the repository at this point in the history
…callbacks to show page type in dca select and to update dca palettes.
  • Loading branch information
patric-eberle committed Jul 26, 2015
1 parent 607e2b7 commit 3288693
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 41 deletions.
19 changes: 1 addition & 18 deletions src/system/modules/i18nl10n/config/runonce.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @copyright Copyright (c) 2014-2015 Verstärker, Patric Eberle
* @author Patric Eberle <[email protected]>
* @package i18nl10n config
* @version 1.5.1
* @version 1.5.2
* @license LGPLv3 http://www.gnu.org/licenses/lgpl-3.0.html
*/

Expand Down Expand Up @@ -67,8 +67,6 @@ public function run()
$this->removeDeprecatedSettings();

$this->updateChildPageLanguage();

$this->recoverPageType();
}

/**
Expand Down Expand Up @@ -217,21 +215,6 @@ private function updateChildPageLanguage()
}
}
}

/**
* Recover type field information
*
* The type field of tl_page_i18nl10n was removed a few version back. But
* it's needed as a DCA field selector.
*/
private function recoverPageType()
{
// Create field if not existing
$this->Database->query('ALTER TABLE tl_page_i18nl10n ADD type varchar(32) NOT NULL default ""');

// Set field value if not existing
$this->Database->query('UPDATE tl_page_i18nl10n as pi SET type = (SELECT p.type FROM tl_page as p WHERE p.id = pi.pid) WHERE pi.type = "";');
}
}

$objI18nl10nRunOnceJob = new I18nl10nRunOnceJob();
Expand Down
26 changes: 13 additions & 13 deletions src/system/modules/i18nl10n/dca/tl_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @copyright Copyright (c) 2014-2015 Verstärker, Patric Eberle
* @author Patric Eberle <[email protected]>
* @package i18nl10n dca
* @version 1.2.1
* @version 1.5.2
* @license LGPLv3 http://www.gnu.org/licenses/lgpl-3.0.html
*/

Expand Down Expand Up @@ -246,19 +246,19 @@ function($value) {
}

$fields = array(
'pid' => $dc->id,
'sorting' => 0,
'tstamp' => time(),
'title' => $dc->activeRecord->title,
'pageTitle' => $dc->activeRecord->pageTitle,
'description' => $dc->activeRecord->description,
'cssClass' => $dc->activeRecord->cssClass,
'pid' => $dc->id,
'sorting' => 0,
'tstamp' => time(),
'title' => $dc->activeRecord->title,
'pageTitle' => $dc->activeRecord->pageTitle,
'description' => $dc->activeRecord->description,
'cssClass' => $dc->activeRecord->cssClass,
'i18nl10n_published' => $dc->activeRecord->published,
'start' => $dc->activeRecord->start,
'stop' => $dc->activeRecord->stop,
'dateFormat' => $dc->activeRecord->dateFormat,
'timeFormat' => $dc->activeRecord->timeFormat,
'datimFormat' => $dc->activeRecord->datimFormat
'start' => $dc->activeRecord->start,
'stop' => $dc->activeRecord->stop,
'dateFormat' => $dc->activeRecord->dateFormat,
'timeFormat' => $dc->activeRecord->timeFormat,
'datimFormat' => $dc->activeRecord->datimFormat
);

// Now make copies in each language
Expand Down
61 changes: 51 additions & 10 deletions src/system/modules/i18nl10n/dca/tl_page_i18nl10n.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @copyright Copyright (c) 2014-2015 Verstärker, Patric Eberle
* @author Patric Eberle <[email protected]>
* @package i18nl10n dca
* @version 1.5.1
* @version 1.5.2
* @license LGPLv3 http://www.gnu.org/licenses/lgpl-3.0.html
*/

Expand Down Expand Up @@ -56,7 +56,8 @@
array('tl_page', 'addBreadcrumb'),
array('tl_page_i18nl10n', 'displayLanguageMessage'),
array('tl_page_i18nl10n', 'localizeAllHandler'),
array('tl_page_i18nl10n', 'checkPermission')
array('tl_page_i18nl10n', 'checkPermission'),
array('tl_page_i18nl10n', 'modifyPalettes'),
),
'sql' => array
(
Expand Down Expand Up @@ -141,19 +142,13 @@
// Palettes
'palettes' => array
(
'__selector__' => array('type'),
'default' => '{i18nl10n_menuLegend},title,alias;'
'default' => '{i18nl10n_menuLegend},title,type,alias;'
. '{i18nl10n_metaLegend},pageTitle,description;'
. '{i18nl10n_timeLegend:hide},dateFormat,timeFormat,datimFormat;'
. '{i18nl10n_expertLegend:hide},cssClass;'
. '{publish_legend},start,stop;'
. '{i18nl10n_legend},language,i18nl10n_published',
'redirect' => '{i18nl10n_menuLegend},title,alias;'
. '{i18nl10n_metaLegend},pageTitle;'
. '{redirect_legend},url;'
. '{i18nl10n_expertLegend:hide},cssClass;'
. '{publish_legend},start,stop;'
. '{i18nl10n_legend},language,i18nl10n_published'
// Redirect palette is created by onload callback
),
// Fields
'fields' => array
Expand Down Expand Up @@ -219,6 +214,11 @@
$GLOBALS['TL_DCA']['tl_page_i18nl10n']['fields']['url']['eval']['tl_class'] = 'long';
$GLOBALS['TL_DCA']['tl_page_i18nl10n']['fields']['i18nl10n_published']['eval']['tl_class'] = 'w50 m12';

// Update type field definition
$GLOBALS['TL_DCA']['tl_page_i18nl10n']['fields']['type']['eval']['disabled'] = true;
$GLOBALS['TL_DCA']['tl_page_i18nl10n']['fields']['type']['load_callback'][] = array('tl_page_i18nl10n', 'getPageType');
unset($GLOBALS['TL_DCA']['tl_page_i18nl10n']['fields']['type']['sql']);

// Splice in localize all in case languages are available
if ($enableCreate) {
$additionalFunctions = array(
Expand Down Expand Up @@ -248,6 +248,11 @@
class tl_page_i18nl10n extends tl_page
{

/**
* @var string
*/
protected $pageType;

/**
* Generate a localization icon for treeview
*
Expand Down Expand Up @@ -943,4 +948,40 @@ private function userHasPermissionToEditPage($arrRow, $strTable = 'tl_page_i18nl
return $this->User->isAdmin
|| ($this->userHasPermissionToEditLanguage($arrRow) && $this->userHasPermissionToEditPageType($arrRow, $strTable));
}

/**
* Modify dca palette according to parent page type
*
* @param $dc
*/
public function modifyPalettes($dc)
{
$arrPage = \Database::getInstance()
->prepare('SELECT type FROM tl_page WHERE id = (SELECT pid FROM tl_page_i18nl10n WHERE id = ?)')
->limit(1)
->execute($dc->id)
->fetchAssoc();

// Save type for later use
$this->pageType = $arrPage['type'];

if ($this->pageType === 'redirect') {
$GLOBALS['TL_DCA']['tl_page_i18nl10n']['palettes']['default'] = '{i18nl10n_menuLegend},title,type,alias;'
. '{i18nl10n_metaLegend},pageTitle;'
. '{redirect_legend},url;'
. '{i18nl10n_expertLegend:hide},cssClass;'
. '{publish_legend},start,stop;'
. '{i18nl10n_legend},language,i18nl10n_published';
}
}

/**
* Get page type for onload_callback of type field
*
* @return string
*/
public function getPageType()
{
return $this->pageType;
}
}

0 comments on commit 3288693

Please sign in to comment.