TYPO3 CMS  TYPO3_6-2
ExtensionUtility.php
Go to the documentation of this file.
1 <?php
3 
21 
22  const PLUGIN_TYPE_PLUGIN = 'list_type';
23  const PLUGIN_TYPE_CONTENT_ELEMENT = 'CType';
24 
44  static public function configurePlugin($extensionName, $pluginName, array $controllerActions, array $nonCacheableControllerActions = array(), $pluginType = self::PLUGIN_TYPE_PLUGIN) {
45  if (empty($pluginName)) {
46  throw new \InvalidArgumentException('The plugin name must not be empty', 1239891987);
47  }
48  if (empty($extensionName)) {
49  throw new \InvalidArgumentException('The extension name was invalid (must not be empty and must match /[A-Za-z][_A-Za-z0-9]/)', 1239891989);
50  }
51  // Check if vendor name is prepended to extensionName in the format {vendorName}.{extensionName}
52  $vendorName = NULL;
53  $delimiterPosition = strrpos($extensionName, '.');
54  if ($delimiterPosition !== FALSE) {
55  $vendorName = str_replace('.', '\\', substr($extensionName, 0, $delimiterPosition));
56  $extensionName = substr($extensionName, $delimiterPosition + 1);
57  }
58  $extensionName = str_replace(' ', '', ucwords(str_replace('_', ' ', $extensionName)));
59 
60  $pluginSignature = strtolower($extensionName . '_' . $pluginName);
61  if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName])) {
62  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName] = array();
63  }
64  foreach ($controllerActions as $controllerName => $actionsList) {
65  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'][$controllerName] = array('actions' => \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $actionsList));
66  if (!empty($nonCacheableControllerActions[$controllerName])) {
67  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'][$controllerName]['nonCacheableActions'] = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $nonCacheableControllerActions[$controllerName]);
68  }
69  }
70 
71  switch ($pluginType) {
72  case self::PLUGIN_TYPE_PLUGIN:
73  $pluginContent = trim('
74 tt_content.list.20.' . $pluginSignature . ' = USER
75 tt_content.list.20.' . $pluginSignature . ' {
76  userFunc = TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run
77  extensionName = ' . $extensionName . '
78  pluginName = ' . $pluginName . (NULL !== $vendorName ? ("\n\t" . 'vendorName = ' . $vendorName) : '') . '
79 }');
80  break;
81  case self::PLUGIN_TYPE_CONTENT_ELEMENT:
82  $pluginContent = trim('
83 tt_content.' . $pluginSignature . ' = COA
84 tt_content.' . $pluginSignature . ' {
85  10 = < lib.stdheader
86  20 = USER
87  20 {
88  userFunc = TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run
89  extensionName = ' . $extensionName . '
90  pluginName = ' . $pluginName . (NULL !== $vendorName ? ("\n\t\t" . 'vendorName = ' . $vendorName) : '') . '
91  }
92 }');
93  break;
94  default:
95  throw new \InvalidArgumentException('The pluginType "' . $pluginType . '" is not suported', 1289858856);
96  }
97  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['pluginType'] = $pluginType;
99 # Setting ' . $extensionName . ' plugin TypoScript
100 ' . $pluginContent, 'defaultContentRendering');
101  }
102 
114  static public function registerPlugin($extensionName, $pluginName, $pluginTitle, $pluginIconPathAndFilename = NULL) {
115  if (empty($pluginName)) {
116  throw new \InvalidArgumentException('The plugin name must not be empty', 1239891988);
117  }
118  if (empty($extensionName)) {
119  throw new \InvalidArgumentException('The extension name was invalid (must not be empty and must match /[A-Za-z][_A-Za-z0-9]/)', 1239891991);
120  }
121  $delimiterPosition = strrpos($extensionName, '.');
122  if ($delimiterPosition !== FALSE) {
123  $extensionName = substr($extensionName, $delimiterPosition + 1);
124  }
125  $extensionName = str_replace(' ', '', ucwords(str_replace('_', ' ', $extensionName)));
126  $pluginSignature = strtolower($extensionName) . '_' . strtolower($pluginName);
127 
128  // At this point $extensionName is normalized, no matter which format the method was feeded with.
129  // Calculate the original extensionKey from this again.
131 
132  // pluginType is usually defined by configurePlugin() in the global array. Use this or fall back to default "list_type".
133  $pluginType = isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['pluginType'])
134  ? $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['pluginType']
135  : 'list_type';
136 
138  array($pluginTitle, $pluginSignature, $pluginIconPathAndFilename),
139  $pluginType,
140  $extensionKey
141  );
142  }
143 
152  static public function configureModule($moduleSignature, $modulePath) {
153  $moduleConfiguration = $GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature];
154  $iconPathAndFilename = $moduleConfiguration['icon'];
155  if (substr($iconPathAndFilename, 0, 4) === 'EXT:') {
156  list($extensionKey, $relativePath) = explode('/', substr($iconPathAndFilename, 4), 2);
157  $iconPathAndFilename = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($extensionKey) . $relativePath;
158  }
159  // TODO: skin support
160  $moduleLabels = array(
161  'tabs_images' => array(
162  'tab' => $iconPathAndFilename
163  ),
164  'labels' => array(
165  'tablabel' => $GLOBALS['LANG']->sL($moduleConfiguration['labels'] . ':mlang_labels_tablabel'),
166  'tabdescr' => $GLOBALS['LANG']->sL($moduleConfiguration['labels'] . ':mlang_labels_tabdescr')
167  ),
168  'tabs' => array(
169  'tab' => $GLOBALS['LANG']->sL($moduleConfiguration['labels'] . ':mlang_tabs_tab')
170  )
171  );
172  $GLOBALS['LANG']->addModuleLabels($moduleLabels, $moduleSignature . '_');
173  return $moduleConfiguration;
174  }
175 
189  static public function registerModule($extensionName, $mainModuleName = '', $subModuleName = '', $position = '', array $controllerActions = array(), array $moduleConfiguration = array()) {
190  if (empty($extensionName)) {
191  throw new \InvalidArgumentException('The extension name must not be empty', 1239891990);
192  }
193  // Check if vendor name is prepended to extensionName in the format {vendorName}.{extensionName}
194  $vendorName = NULL;
195  if (FALSE !== $delimiterPosition = strrpos($extensionName, '.')) {
196  $vendorName = str_replace('.', '\\', substr($extensionName, 0, $delimiterPosition));
197  $extensionName = substr($extensionName, $delimiterPosition + 1);
198  }
200  $extensionName = str_replace(' ', '', ucwords(str_replace('_', ' ', $extensionName)));
201  $defaultModuleConfiguration = array(
202  'access' => 'admin',
203  'icon' => 'EXT:extbase/ext_icon.gif',
204  'labels' => '',
205  'extRelPath' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($extensionKey) . 'Classes/'
206  );
207  if (strlen($mainModuleName) > 0 && !array_key_exists($mainModuleName, $GLOBALS['TBE_MODULES'])) {
208  $mainModuleName = $extensionName . \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($mainModuleName);
209  } else {
210  $mainModuleName = strlen($mainModuleName) > 0 ? $mainModuleName : 'web';
211  }
212  // add mandatory parameter to use new pagetree
213  if ($mainModuleName === 'web') {
214  $defaultModuleConfiguration['navigationComponentId'] = 'typo3-pagetree';
215  }
216  \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($defaultModuleConfiguration, $moduleConfiguration);
217  $moduleConfiguration = $defaultModuleConfiguration;
218  $moduleSignature = $mainModuleName;
219  if (strlen($subModuleName) > 0) {
220  $subModuleName = $extensionName . \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($subModuleName);
221  $moduleSignature .= '_' . $subModuleName;
222  }
223  $moduleConfiguration['name'] = $moduleSignature;
224  if (NULL !== $vendorName) {
225  $moduleConfiguration['vendorName'] = $vendorName;
226  }
227  $moduleConfiguration['extensionName'] = $extensionName;
228  $moduleConfiguration['configureModuleFunction'] = array('TYPO3\\CMS\\Extbase\\Utility\\ExtensionUtility', 'configureModule');
229  $GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature] = $moduleConfiguration;
230  if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['modules'][$moduleSignature])) {
231  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['modules'][$moduleSignature] = array();
232  }
233  foreach ($controllerActions as $controllerName => $actions) {
234  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['modules'][$moduleSignature]['controllers'][$controllerName] = array(
235  'actions' => \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $actions)
236  );
237  }
238  \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModule($mainModuleName, $subModuleName, $position);
239  }
240 
248  static public function registerTypeConverter($typeConverterClassName) {
249  if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['typeConverters'])) {
250  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['typeConverters'] = array();
251  }
252  $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['typeConverters'][] = $typeConverterClassName;
253  }
254 }
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=TRUE, $includeEmptyValues=TRUE, $enableUnsetFeature=TRUE)
if(!defined('TYPO3_MODE')) $pluginContent
static addTypoScript($key, $type, $content, $afterStaticUid=0)
static registerPlugin($extensionName, $pluginName, $pluginTitle, $pluginIconPathAndFilename=NULL)
static registerTypeConverter($typeConverterClassName)
static addPlugin($itemArray, $type='list_type', $extensionKey=NULL)
static configureModule($moduleSignature, $modulePath)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
static registerModule($extensionName, $mainModuleName='', $subModuleName='', $position='', array $controllerActions=array(), array $moduleConfiguration=array())
static addModule($main, $sub='', $position='', $path='', $moduleConfiguration=array())
static configurePlugin($extensionName, $pluginName, array $controllerActions, array $nonCacheableControllerActions=array(), $pluginType=self::PLUGIN_TYPE_PLUGIN)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]