[BUGFIX] Fix oddities of the CategoryRegistry
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Configuration / TcaBuildingAspect.php
1 <?php
2 namespace TYPO3\CMS\Core\Configuration;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2014 Helmut Hummel <helmut.hummel@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Assembles TCA overrides from packages to build the final TCA
32 */
33 class TcaBuildingAspect {
34
35 const TCA_OVERRIDES_PATH = 'Configuration/TCA/Overrides';
36
37 /**
38 * @var \TYPO3\CMS\Core\Package\PackageManager
39 * @inject
40 */
41 protected $packageManager;
42
43 /**
44 * @var \TYPO3\CMS\Core\Category\CategoryRegistry
45 * @inject
46 */
47 protected $categoryRegistry;
48
49 /**
50 * Scans active packages for TCA override code and executes it.
51 * Also applies category registry changes after that, so that
52 * registering calls to the registry can be (and should be) in TCA override files.
53 *
54 * @return array
55 */
56 public function applyTcaOverrides() {
57 $this->categoryRegistry->applyTcaForPreRegisteredTables();
58 foreach ($this->packageManager->getActivePackages() as $package) {
59 $tcaOverridesPathForPackage = $package->getPackagePath() . self::TCA_OVERRIDES_PATH;
60 if (is_dir($tcaOverridesPathForPackage)) {
61 $files = scandir($tcaOverridesPathForPackage);
62 foreach ($files as $file) {
63 if (
64 is_file($tcaOverridesPathForPackage . '/' . $file)
65 && ($file !== '.')
66 && ($file !== '..')
67 && (substr($file, -4, 4) === '.php')
68 ) {
69 require($tcaOverridesPathForPackage . '/' . $file);
70 }
71 }
72 }
73
74 }
75 return array($GLOBALS['TCA']);
76 }
77 }