Added Feature #16641: Here comes FAL - beta2 version
[Packages/TYPO3.CMS.git] / typo3 / sysext / fal / classes / hooks / class.tx_fal_hooks_tceforms_dbfileicons.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 FAL development team <fal@wmdb.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Hook into t3lib_TCEforms::dbFileIcons
30 *
31 * @author FAL development team <fal@wmdb.de>
32 * @package TYPO3
33 * @subpackage tx_fal
34 */
35 class tx_fal_hooks_TCEforms_dbFileIcons implements t3lib_TCEforms_dbFileIconsHook {
36
37 /**
38 * Modifies the parameters for selector box form-field for the db/file/select elements (multiple)
39 *
40 * @param array $params An array of additional parameters, eg: "size", "info", "headers" (array with "selector" and "items"), "noBrowser", "thumbnails"
41 * @param string $selector Alternative selector box.
42 * @param string $thumbnails Thumbnail view of images. Only filled if there are images only. This images will be shown under the selectorbox.
43 * @param array $icons Defined icons next to the selector box.
44 * @param string $rightbox Thumbnail view of images. Only filled if there are other types as images. This images will be shown right next to the selectorbox.
45 * @param string $fName Form element name
46 * @param array $uidList The array of item-uids. Have a look at t3lib_TCEforms::dbFileIcons parameter "$itemArray"
47 * @param array $additionalParams Array with additional parameters which are be available at method call. Includes $mode, $allowed, $itemArray, $onFocus, $table, $field, $uid. For more information have a look at PHPDoc-Comment of t3lib_TCEforms::dbFileIcons
48 * @param t3lib_TCEforms $parentObject parent t3lib_TCEforms object
49 * @return void
50 */
51 public function dbFileIcons_postProcess(array &$params, &$selector, &$thumbnails, array &$icons, &$rightbox, &$fName, array &$uidList, array $additionalParams, t3lib_TCEforms $parentObject) {
52
53 if (tx_fal_tcafunc::isFieldAFalField($additionalParams['field'], $additionalParams['table']) === TRUE) {
54 $icons['R'] = array();
55 if (!$params['readOnly'] && !$params['noList']) {
56 if (!$params['noBrowser']) {
57
58 //load needed js-libs:
59 $pageRenderer = &$GLOBALS['SOBE']->doc->getPageRenderer();
60 //disableCompressJavascript is required to make $pageRenderer respect
61 //ajax.php?ajaxID=ExtDirect::getAPI&namespace=
62 $pageRenderer->disableCompressJavascript();
63 $pageRenderer->addExtOnReadyCode("
64 Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
65 ");
66
67 $pageRenderer->addJsInlineCode('loadFalElementBrowser',"
68 loadFalElementBrowser = function(fName){
69 var l = document.getElementsByName(fName+'_list')[0],
70 h = document.getElementsByName(fName)[0];
71 top.TYPO3.Components.filelist.loadElementBrowser(l,h);
72 }
73 ");
74
75 //render EB-Icon:
76 $table = $additionalParams['table'];
77 $field = $additionalParams['field'];
78
79 // check against inline uniqueness
80 $inlineParent = $parentObject->inline->getStructureLevel(-1);
81 if(is_array($inlineParent) && $inlineParent['uid']) {
82 if ($inlineParent['config']['foreign_table'] == $table && $inlineParent['config']['foreign_unique'] == $field) {
83 $objectPrefix = $parentObject->inline->inlineNames['object'].'['.$table.']';
84 $aOnClickInline = $objectPrefix.'|inline.checkUniqueElement|inline.setUniqueElement';
85 $rOnClickInline = 'inline.revertUnique(\''.$objectPrefix.'\',null,\''.$uid.'\');';
86 }
87 }
88 $aOnClick='loadFalElementBrowser(\''.$fName.'\',\''.$allowed.'\',\''.$aOnClickInline.'\'); return false;';
89 $icons['R'][]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
90 t3lib_iconWorks::getSpriteIcon('actions-insert-record', array('title' => htmlspecialchars($parentObject->getLL('l_browse_' . ($mode == 'db' ? 'db' : 'file'))))) .
91 '</a>';
92 }
93 }
94 }
95 }
96 }
97
98 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/fal/classes/hooks/class.tx_fal_hooks_tceforms_dbfileicons.php'])) {
99 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/fal/classes/hooks/class.tx_fal_hooks_tceforms_dbfileicons.php']);
100 }
101 ?>