Skip to content

Commit

Permalink
Merge pull request #60 from timgatzky/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
timgatzky committed Nov 14, 2022
2 parents 84ce007 + 55a57ff commit d891b2f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 28 deletions.
4 changes: 2 additions & 2 deletions system/modules/pct_tabletree_widget/Contao/BackendPctTableTree.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function run()

$objSession->set('pctTableTreeRef', \Contao\Environment::get('request'));

if(!is_array($GLOBALS['TL_DCA'][$strTable]))
if( !isset($GLOBALS['TL_DCA'][$strTable]) || !is_array($GLOBALS['TL_DCA'][$strTable]))
{
$this->loadDataContainer($strTable);
}
Expand Down Expand Up @@ -151,7 +151,7 @@ public function run()
$this->Template->action = \ampersand(\Contao\Environment::get('request'));
#$this->Template->manager = $GLOBALS['TL_LANG']['MSC']['pct_tableTreeManager'];
#$this->Template->managerHref = 'contao/main.php?do=pct_customelements_tags&popup=1';
$this->Template->breadcrumb = $GLOBALS['TL_DCA'][$strSource]['list']['sorting']['breadcrumb'];
$this->Template->breadcrumb = $GLOBALS['TL_DCA'][$strSource]['list']['sorting']['breadcrumb'] ?? '';
$this->Template->request_token = '<input type="hidden" value="'.REQUEST_TOKEN.'" name="REQUEST_TOKEN">';

$this->Template->value = $this->Session->get('pct_tabletree_selector_search');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ public function __construct($arrAttributes=null)
{
$arrAttributes = array_merge($arrAttributes, $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]);
}

if($arrAttributes['fieldType'] == 'checkbox' || $arrAttributes['multiple'] == true || (boolean)$GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['multiple'])
if( (isset($arrAttributes['fieldType']) && $arrAttributes['fieldType'] == 'checkbox') || (isset($arrAttributes['multiple']) && $arrAttributes['multiple'] == true) || (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['multiple']) && (boolean)$GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['multiple']) )
{
$this->blnIsMultiple = true;
}
Expand All @@ -112,13 +112,13 @@ public function __construct($arrAttributes=null)
$this->strKeyField = strlen($arrAttributes['tabletree']['keyField']) > 0 ? $arrAttributes['tabletree']['keyField'] : 'id';
$this->strOrderField = $arrAttributes['tabletree']['orderField'];
$this->strRootField = $arrAttributes['tabletree']['rootsField'];
$this->strConditionsField = $arrAttributes['tabletree']['conditionsField'] ?: '';
$this->strConditions = $this->replaceInsertTags($arrAttributes['tabletree']['conditions'] ?: '');
$this->strConditionsField = $arrAttributes['tabletree']['conditionsField'] ?? '';
$this->strConditions = $this->replaceInsertTags($arrAttributes['tabletree']['conditions'] ?? '');

// load the data container of the source table e.g. for permission checks
$this->loadDataContainer($this->strSource);

if(strlen($arrAttributes['tabletree']['translationField']) > 0)
if( isset($arrAttributes['tabletree']['translationField']) && strlen($arrAttributes['tabletree']['translationField']) > 0)
{
$this->strTranslationField = $arrAttributes['tabletree']['translationField'];
}
Expand Down Expand Up @@ -258,7 +258,7 @@ public function generate()
}

// Root nodes (breadcrumb menu)
if (!empty($GLOBALS['TL_DCA'][$this->strSource]['list']['sorting']['root']))
if ( isset($GLOBALS['TL_DCA'][$this->strSource]['list']['sorting']['root']) && !empty($GLOBALS['TL_DCA'][$this->strSource]['list']['sorting']['root']))
{
$nodes = $this->eliminateNestedPages($GLOBALS['TL_DCA'][$this->strSource]['list']['sorting']['root'], $this->strSource);
foreach ($nodes as $node)
Expand All @@ -268,7 +268,7 @@ public function generate()
}

// Predefined node set (see #3563)
elseif (is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField][$this->strRootField]))
elseif ( isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField][$this->strRootField]) && is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField][$this->strRootField]))
{
$nodes = $this->eliminateNestedPages($GLOBALS['TL_DCA'][$this->strSource]['fields'][$this->strField][$this->strRootField], $this->strSource);
foreach ($nodes as $node)
Expand All @@ -277,7 +277,7 @@ public function generate()
}
}
// custom root nodes
elseif(count($this->arrRootNodes) > 0)
elseif( isset($this->arrRootNodes) && count($this->arrRootNodes) > 0)
{
$nodes = $this->eliminateNestedPages($this->arrRootNodes, $this->strSource);
foreach ($nodes as $node)
Expand Down Expand Up @@ -331,7 +331,7 @@ public function generate()

// Return the tree
return '<ul data-picker-value="'.$pickerValue.'" class="tl_listing tree_view picker_selector'.(($this->strClass != '') ? ' ' . $this->strClass : '').'" id="'.$this->strId.'">
<li class="tl_folder_top"><div class="tl_left">'.\Contao\Image::getHtml($GLOBALS['TL_DCA'][$this->strSource]['list']['sorting']['icon'] ?: 'pagemounts.gif').' '.($GLOBALS['TL_CONFIG']['websiteTitle'] ?: 'Contao Open Source CMS').'</div> <div class="tl_right">&nbsp;</div><div style="clear:both"></div></li><li class="parent" id="'.$this->strId.'_parent"><ul>'.$tree.$strReset.'
<li class="tl_folder_top"><div class="tl_left">'.\Contao\Image::getHtml($GLOBALS['TL_DCA'][$this->strSource]['list']['sorting']['icon'] ?? 'pagemounts.gif').' '.($GLOBALS['TL_CONFIG']['websiteTitle'] ?? 'Contao Open Source CMS').'</div> <div class="tl_right">&nbsp;</div><div style="clear:both"></div></li><li class="parent" id="'.$this->strId.'_parent"><ul>'.$tree.$strReset.'
</ul></li></ul>';
}

Expand Down Expand Up @@ -460,7 +460,7 @@ protected function renderTree($id, $intMargin, $protectedRow=false, $blnNoRecurs
$return .= "\n " . '<li class="tl_file toggle_select"><div class="tl_left" style="padding-left:'.($intMargin + $intSpacing).'px">';

$folderAttribute = 'style="margin-left:20px"';
$session[$node][$id] = is_numeric($session[$node][$id]) ? $session[$node][$id] : 0;
$session[$node][$id] = $session[$node][$id] ?? 0;
$level = ($intMargin / $intSpacing + 1);
$blnIsOpen = ($session[$node][$id] == 1 || in_array($id, $this->arrNodes));

Expand All @@ -478,7 +478,7 @@ protected function renderTree($id, $intMargin, $protectedRow=false, $blnNoRecurs
$metaWizardKey = (version_compare(VERSION,'3.2','<=') ? 'title': 'label');

// label callback
$label_callback = $GLOBALS['PCT_TABLETREE_WIDGET'][$this->strSource]['label_callback'];
$label_callback = $GLOBALS['PCT_TABLETREE_WIDGET'][$this->strSource]['label_callback'] ?? array();

// Add the current row
if (count($childs) > 0)
Expand Down Expand Up @@ -524,6 +524,10 @@ protected function renderTree($id, $intMargin, $protectedRow=false, $blnNoRecurs
$GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['fieldType'] = 'checkbox';
}

if( !isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['fieldType']) )
{
$GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['fieldType'] = 'radio';
}
// Add checkbox or radio button
switch ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['fieldType'])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function postActions($strAction, $objDC)
$varValue = null;
$multiple = false;

if($GLOBALS['TL_DCA'][$objDC->table]['fields'][$strField]['eval']['fieldType'] == 'checkbox' || $GLOBALS['TL_DCA'][$objDC->table]['fields'][$strField]['eval']['multiple'])
if( (isset($GLOBALS['TL_DCA'][$objDC->table]['fields'][$strField]['eval']['fieldType']) && $GLOBALS['TL_DCA'][$objDC->table]['fields'][$strField]['eval']['fieldType'] == 'checkbox') || (isset($GLOBALS['TL_DCA'][$objDC->table]['fields'][$strField]['eval']['multiple']) && $GLOBALS['TL_DCA'][$objDC->table]['fields'][$strField]['eval']['multiple']) )
{
$multiple = true;
}
Expand All @@ -116,7 +116,7 @@ public function postActions($strAction, $objDC)
}

// Call the load_callback
if (is_array($GLOBALS['TL_DCA'][$objDC->table]['fields'][$strField]['load_callback']))
if ( isset($GLOBALS['TL_DCA'][$objDC->table]['fields'][$strField]['load_callback']) && is_array($GLOBALS['TL_DCA'][$objDC->table]['fields'][$strField]['load_callback']))
{
foreach ($GLOBALS['TL_DCA'][$objDC->table]['fields'][$strField]['load_callback'] as $callback)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,33 +96,33 @@ public function __construct($arrAttributes=null)
// load js
$GLOBALS['TL_JAVASCRIPT'][] = PCT_TABLETREE_PATH.'/assets/js/tabletree.js';

if($arrAttributes['fieldType'] == 'checkbox' || $arrAttributes['multiple'] == true || $arrAttributes['eval']['fieldType'] == 'checkbox' || $arrAttributes['eval']['multiple'] == true)
if( (isset($arrAttributes['fieldType']) && $arrAttributes['fieldType'] == 'checkbox') || (isset($arrAttributes['multiple']) && $arrAttributes['multiple'] == true) || (isset($arrAttributes['eval']['fieldType']) && $arrAttributes['eval']['fieldType'] == 'checkbox') || (isset($arrAttributes['eval']['multiple']) && $arrAttributes['eval']['multiple'] == true))
{
$this->blnIsMultiple = true;
}

// get field defintion from datacontainer since contao does not pass custom evalulation arrays to widgets
if(!is_array($arrAttributes['tabletree']))
if( !isset($arrAttributes['tabletree']) || !is_array($arrAttributes['tabletree']))
{
$this->loadDataContainer($this->strTable);
$arrAttributes = array_merge($arrAttributes, $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]);
}

$this->strSource = $arrAttributes['tabletree']['source'];
$this->strValueField = strlen($arrAttributes['tabletree']['valueField']) > 0 ? $arrAttributes['tabletree']['valueField'] : 'id';
$this->strKeyField = strlen($arrAttributes['tabletree']['keyField']) > 0 ? $arrAttributes['tabletree']['keyField'] : 'id';
$this->strOrderField = $arrAttributes['tabletree']['orderField'];
$this->strRootField = $arrAttributes['tabletree']['rootsField'];
$this->strConditionsField = $arrAttributes['tabletree']['conditionsField'] ?: '';
$this->strConditions = $arrAttributes['tabletree']['conditions'] ?: '';
$this->strValueField = $arrAttributes['tabletree']['valueField'] ?? 'id';
$this->strKeyField = $arrAttributes['tabletree']['keyField'] ?? 'id';
$this->strOrderField = $arrAttributes['tabletree']['orderField'] ?? '';
$this->strRootField = $arrAttributes['tabletree']['rootsField'] ?? '';
$this->strConditionsField = $arrAttributes['tabletree']['conditionsField'] ?? '';
$this->strConditions = $arrAttributes['tabletree']['conditions'] ?? '';

if(strlen($arrAttributes['tabletree']['translationField']) > 0)
if( isset($arrAttributes['tabletree']['translationField']) && strlen($arrAttributes['tabletree']['translationField']) > 0)
{
$this->strTranslationField = $arrAttributes['tabletree']['translationField'];
}

// flag as sortable
if($arrAttributes['sortable'] || $arrAttributes['eval']['isSortable'] || $arrAttributes['eval']['sortable'])
if( (isset($arrAttributes['sortable']) && $arrAttributes['sortable']) || isset($arrAttributes['eval']['isSortable']) || (isset($arrAttributes['eval']['sortable']) && $arrAttributes['eval']['sortable']) )
{
$this->blnIsSortable = true;
$this->strOrderSRC = strlen($arrAttributes['eval']['orderField']) > 0 ? $arrAttributes['eval']['orderField']: 'orderSRC_'.$this->strName;
Expand Down Expand Up @@ -289,8 +289,12 @@ public function generate()
}
}

$intId = $this->activeRecord->id ?: \Contao\Input::get('id');

$intId = \Contao\Input::get('id');
if( isset($this->activeRecord->id) )
{
$this->activeRecord->id = 0;
}

$return = '<input type="hidden" name="'.$this->strName.'" id="ctrl_'.$this->strId.'" value="'.implode(',', $arrRawValues).'">' . ($this->blnIsSortable ? '
<input type="hidden" name="'.$this->strOrderSRC.'" id="ctrl_'.$this->strOrderSRCId.'" value="'.$this->{$this->strOrderSRC}.'">' : '') . '
<div class="selector_container">' . (($this->blnIsSortable && count($arrValues) > 1) ? '
Expand Down
3 changes: 3 additions & 0 deletions system/modules/pct_tabletree_widget/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 1.7.3
Update: General PHP8 updates (#59)

### 1.7.2
Fixed: Determine DataContainer class via DataContainer::getDriverForTable instead of DCA array (#57)

Expand Down
2 changes: 1 addition & 1 deletion system/modules/pct_tabletree_widget/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Constants
*/
define('PCT_TABLETREE_PATH', 'system/modules/pct_tabletree_widget');
define('PCT_TABLETREE_VERSION', '1.7.2');
define('PCT_TABLETREE_VERSION', '1.7.3');

/**
* Back end form fields
Expand Down

0 comments on commit d891b2f

Please sign in to comment.