From 3503e2e5160099900cfe3027fc388daa1f37431c Mon Sep 17 00:00:00 2001 From: Leo Feyer Date: Thu, 26 Sep 2013 16:05:24 +0200 Subject: [PATCH] Added new DCA table config flags (see #5254) --- system/docs/CHANGELOG.md | 12 ++++ system/modules/core/drivers/DC_Folder.php | 45 +++++++++++++-- system/modules/core/drivers/DC_Table.php | 69 +++++++++++++++++++---- 3 files changed, 111 insertions(+), 15 deletions(-) diff --git a/system/docs/CHANGELOG.md b/system/docs/CHANGELOG.md index 2b33e03d6e..8c10d32298 100644 --- a/system/docs/CHANGELOG.md +++ b/system/docs/CHANGELOG.md @@ -4,6 +4,18 @@ Contao Open Source CMS Changelog Version 3.2.beta1 (2013-XX-XX) ------------------------------ +### New +Added new DCA table config flags (see #5254): + + * `closed`: no new rows can be added at all + * `notEditable`: the rows cannot be edited + * `notDeletable`: the rows cannot be deleted + * `notSortable`: the order of the rows cannot be altered (new) + * `notCopyable`: existing rows cannot be duplicated (new) + * `notCreatable`: prevents to create rows but allows to duplicate rows (new) + +The `closed` flag hence is a combination of `notCreatable` and `notCopyable`. + ### Improved Always show the save buttons in the modal windows (see #5985). diff --git a/system/modules/core/drivers/DC_Folder.php b/system/modules/core/drivers/DC_Folder.php index a602f703c4..89e9ed7955 100644 --- a/system/modules/core/drivers/DC_Folder.php +++ b/system/modules/core/drivers/DC_Folder.php @@ -322,7 +322,7 @@ public function showAll() $return = '
'.((\Input::get('act') == 'select') ? ' '.$GLOBALS['TL_LANG']['MSC']['backBT'].' ' : '') . ((\Input::get('act') != 'select' && !$blnClipboard) ? ' -'.$lblNew.' ' . (!$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] ? ''.$GLOBALS['TL_LANG'][$this->strTable]['move'][0].' ' : '') . $this->generateGlobalButtons(true) : '') . ($blnClipboard ? ''.$GLOBALS['TL_LANG']['MSC']['clearClipboard'].' ' : '') . ' +'.$lblNew.' ' . ((!$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable']) ? ''.$GLOBALS['TL_LANG'][$this->strTable]['move'][0].' ' : '') . $this->generateGlobalButtons(true) : '') . ($blnClipboard ? ''.$GLOBALS['TL_LANG']['MSC']['clearClipboard'].' ' : '') . '
' . \Message::generate(true) . ((\Input::get('act') == 'select') ? '
@@ -357,8 +357,15 @@ public function showAll() $arrButtons['delete'] = ''; } - $arrButtons['cut'] = ''; - $arrButtons['copy'] = ''; + if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notSortable']) + { + $arrButtons['cut'] = ''; + } + + if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notCopyable']) + { + $arrButtons['copy'] = ''; + } if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notEditable']) { @@ -414,6 +421,12 @@ public function show() */ public function create() { + if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable']) + { + $this->log('Table "'.$this->strTable.'" is not creatable', 'DC_Folder create()', TL_ERROR); + $this->redirect('contao/main.php?act=error'); + } + $this->import('Files'); $strFolder = \Input::get('pid', true); @@ -439,6 +452,12 @@ public function create() */ public function cut($source=null) { + if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notSortable']) + { + $this->log('Table "'.$this->strTable.'" is not sortable', 'DC_Folder cut()', TL_ERROR); + $this->redirect('contao/main.php?act=error'); + } + $strFolder = \Input::get('pid', true); $blnDoNotRedirect = ($source !== null); @@ -510,6 +529,12 @@ public function cut($source=null) */ public function cutAll() { + if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notSortable']) + { + $this->log('Table "'.$this->strTable.'" is not sortable', 'DC_Folder cutAll()', TL_ERROR); + $this->redirect('contao/main.php?act=error'); + } + // PID is mandatory if (!strlen(\Input::get('pid', true))) { @@ -537,6 +562,12 @@ public function cutAll() */ public function copy($source=null, $destination=null) { + if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notCopyable']) + { + $this->log('Table "'.$this->strTable.'" is not copyable', 'DC_Folder copy()', TL_ERROR); + $this->redirect('contao/main.php?act=error'); + } + $strFolder = \Input::get('pid', true); $blnDoNotRedirect = ($source !== null); @@ -634,6 +665,12 @@ public function copy($source=null, $destination=null) */ public function copyAll() { + if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notCopyable']) + { + $this->log('Table "'.$this->strTable.'" is not copyable', 'DC_Folder copyAll()', TL_ERROR); + $this->redirect('contao/main.php?act=error'); + } + // PID is mandatory if (!strlen(\Input::get('pid', true))) { @@ -2206,7 +2243,7 @@ protected function generateTree($path, $intMargin, $mount=false, $blnProtected=f } // Upload button - if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && \Input::get('act') != 'select') + if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable'] && \Input::get('act') != 'select') { $return .= ' '.\Image::getHtml('new.gif', $GLOBALS['TL_LANG'][$this->strTable]['move'][0]).''; } diff --git a/system/modules/core/drivers/DC_Table.php b/system/modules/core/drivers/DC_Table.php index c9f43c0720..82ace5eab4 100644 --- a/system/modules/core/drivers/DC_Table.php +++ b/system/modules/core/drivers/DC_Table.php @@ -598,6 +598,12 @@ public function show() */ public function create($set=array()) { + if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable']) + { + $this->log('Table "'.$this->strTable.'" is not creatable', 'DC_Table create()', TL_ERROR); + $this->redirect('contao/main.php?act=error'); + } + // Get all default values for the new entry foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'] as $k=>$v) { @@ -686,6 +692,12 @@ public function create($set=array()) */ public function cut($blnDoNotRedirect=false) { + if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notSortable']) + { + $this->log('Table "'.$this->strTable.'" is not sortable', 'DC_Table cut()', TL_ERROR); + $this->redirect('contao/main.php?act=error'); + } + $cr = array(); // ID and PID are mandatory @@ -769,6 +781,12 @@ public function cut($blnDoNotRedirect=false) */ public function cutAll() { + if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notSortable']) + { + $this->log('Table "'.$this->strTable.'" is not sortable', 'DC_Table cutAll()', TL_ERROR); + $this->redirect('contao/main.php?act=error'); + } + // PID is mandatory if (!strlen(\Input::get('pid'))) { @@ -799,6 +817,12 @@ public function cutAll() */ public function copy($blnDoNotRedirect=false) { + if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notCopyable']) + { + $this->log('Table "'.$this->strTable.'" is not copyable', 'DC_Table copy()', TL_ERROR); + $this->redirect('contao/main.php?act=error'); + } + if (!$this->intId) { $this->redirect($this->getReferer()); @@ -1080,6 +1104,12 @@ protected function copyChilds($table, $insertID, $id, $parentId) */ public function copyAll() { + if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notCopyable']) + { + $this->log('Table "'.$this->strTable.'" is not copyable', 'DC_Table copyAll()', TL_ERROR); + $this->redirect('contao/main.php?act=error'); + } + // PID is mandatory if (!strlen(\Input::get('pid'))) { @@ -1848,7 +1878,7 @@ public function edit($intID=null, $ajaxId=null) $arrButtons['saveNclose'] = ''; } - if (!\Input::get('popup') && !$GLOBALS['TL_DCA'][$this->strTable]['config']['closed']) + if (!\Input::get('popup') && !$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable']) { $arrButtons['saveNcreate'] = ''; } @@ -3181,7 +3211,7 @@ protected function treeView() $return = '
'.((\Input::get('act') == 'select') ? ' '.$GLOBALS['TL_LANG']['MSC']['backBT'].' ' : (isset($GLOBALS['TL_DCA'][$this->strTable]['config']['backlink']) ? ' -'.$GLOBALS['TL_LANG']['MSC']['backBT'].' ' : '')) . ((\Input::get('act') != 'select' && !$blnClipboard && !$GLOBALS['TL_DCA'][$this->strTable]['config']['closed']) ? ' +'.$GLOBALS['TL_LANG']['MSC']['backBT'].' ' : '')) . ((\Input::get('act') != 'select' && !$blnClipboard && !$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable']) ? ' '.$GLOBALS['TL_LANG'][$this->strTable]['new'][0].' ' : '') . ((\Input::get('act') != 'select' && !$blnClipboard) ? $this->generateGlobalButtons() : '') . ($blnClipboard ? ''.$GLOBALS['TL_LANG']['MSC']['clearClipboard'].' ' : '') . '
' . \Message::generate(true); @@ -3309,8 +3339,15 @@ protected function treeView() $arrButtons['delete'] = ''; } - $arrButtons['cut'] = ''; - $arrButtons['copy'] = ''; + if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notSortable']) + { + $arrButtons['cut'] = ''; + } + + if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notCopyable']) + { + $arrButtons['copy'] = ''; + } if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notEditable']) { @@ -3706,7 +3743,7 @@ protected function parentView() $return = '
' . (\Input::get('nb') ? ' ' : ' -'.$GLOBALS['TL_LANG']['MSC']['backBT'].'') . ' ' . (!$blnClipboard ? ((\Input::get('act') != 'select') ? (!$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] ? ' +'.$GLOBALS['TL_LANG']['MSC']['backBT'].'') . ' ' . (!$blnClipboard ? ((\Input::get('act') != 'select') ? ((!$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable']) ? ' '.$GLOBALS['TL_LANG'][$this->strTable]['new'][0].' ' : '') . $this->generateGlobalButtons() : '') : ''.$GLOBALS['TL_LANG']['MSC']['clearClipboard'].' ') . '
' . \Message::generate(true); @@ -3747,7 +3784,7 @@ protected function parentView() $return .= '
'.((\Input::get('act') == 'select') ? ' ' : (!$GLOBALS['TL_DCA'][$this->ptable]['config']['notEditable'] ? ' -'.$imageEditHeader.'' : '') . (($blnHasSorting && !$GLOBALS['TL_DCA'][$this->strTable]['config']['closed']) ? ' '.$imagePasteNew.'' : '') . ($blnClipboard ? ' '.$imagePasteAfter.'' : '')) . ' +'.$imageEditHeader.'' : '') . (($blnHasSorting && !$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable']) ? ' '.$imagePasteNew.'' : '') . ($blnClipboard ? ' '.$imagePasteAfter.'' : '')) . '
'; // Format header fields @@ -4015,7 +4052,7 @@ protected function parentView() if ($blnHasSorting) { // Create new button - if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['closed']) + if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable']) { $return .= ' '.$imagePasteNew.''; } @@ -4039,7 +4076,10 @@ protected function parentView() } // Drag handle - $return .= ' ' . \Image::getHtml('drag.gif', '', 'class="drag-handle" title="' . sprintf($GLOBALS['TL_LANG'][$this->strTable]['cut'][1], $row[$i]['id']) . '"'); + if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notSortable']) + { + $return .= ' ' . \Image::getHtml('drag.gif', '', 'class="drag-handle" title="' . sprintf($GLOBALS['TL_LANG'][$this->strTable]['cut'][1], $row[$i]['id']) . '"'); + } } } @@ -4093,8 +4133,15 @@ protected function parentView() $arrButtons['delete'] = ''; } - $arrButtons['cut'] = ''; - $arrButtons['copy'] = ''; + if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notSortable']) + { + $arrButtons['cut'] = ''; + } + + if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notCopyable']) + { + $arrButtons['copy'] = ''; + } if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['notEditable']) { @@ -4250,7 +4297,7 @@ protected function listView()
'.((\Input::get('act') == 'select' || $this->ptable) ? ' '.$GLOBALS['TL_LANG']['MSC']['backBT'].' ' : (isset($GLOBALS['TL_DCA'][$this->strTable]['config']['backlink']) ? ' '.$GLOBALS['TL_LANG']['MSC']['backBT'].' ' : '')) . ((\Input::get('act') != 'select') ? ' -'.(!$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] ? ''.$GLOBALS['TL_LANG'][$this->strTable]['new'][0].' ' : '') . $this->generateGlobalButtons() : '') . ' +'.((!$GLOBALS['TL_DCA'][$this->strTable]['config']['closed'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['notCreatable']) ? ''.$GLOBALS['TL_LANG'][$this->strTable]['new'][0].' ' : '') . $this->generateGlobalButtons() : '') . '
' . \Message::generate(true); }