1
|
|
|
<?php |
2
|
|
|
namespace MOC\SynchronizeUrl; |
3
|
|
|
|
4
|
|
|
use TYPO3\Flow\Package\Package as BasePackage; |
5
|
|
|
use TYPO3\TYPO3CR\Domain\Model\Node; |
6
|
|
|
|
7
|
|
|
class Package extends BasePackage { |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Invokes custom PHP code directly after the package manager has been initialized. |
11
|
|
|
* |
12
|
|
|
* @param \TYPO3\Flow\Core\Bootstrap $bootstrap The current bootstrap |
13
|
|
|
* @return void |
14
|
|
|
*/ |
15
|
|
|
public function boot(\TYPO3\Flow\Core\Bootstrap $bootstrap) { |
16
|
|
|
$dispatcher = $bootstrap->getSignalSlotDispatcher(); |
17
|
|
|
$newUriPathSegment = NULL; |
18
|
|
|
$dispatcher->connect('TYPO3\TYPO3CR\Domain\Model\Node', 'nodePropertyChanged', function(Node $node, $propertyName, $oldValue, $newValue) use($bootstrap, &$newUriPathSegment) { |
19
|
|
|
if (method_exists('TYPO3\Neos\Utility\NodeUriPathSegmentGenerator', 'generateUriPathSegment') || method_exists('TYPO3\Neos\Utility\NodeUriPathSegmentGenerator', 'setUniqueUriPathSegment')) { |
20
|
|
|
$nodeUriPathSegmentGenerator = $bootstrap->getObjectManager()->get('TYPO3\Neos\Utility\NodeUriPathSegmentGenerator'); |
21
|
|
|
} |
22
|
|
|
if ($propertyName === 'title' && $node->getNodeType()->isOfType('TYPO3.Neos:Document')) { |
23
|
|
|
if (method_exists('TYPO3\Neos\Utility\NodeUriPathSegmentGenerator', 'generateUriPathSegment')) { |
24
|
|
|
$newUriPathSegment = strtolower($nodeUriPathSegmentGenerator->generateUriPathSegment($node)); |
|
|
|
|
25
|
|
|
} else { |
26
|
|
|
$newUriPathSegment = strtolower(\TYPO3\TYPO3CR\Utility::renderValidNodeName($node->getProperty('title') ?: $node->getName())); |
27
|
|
|
} |
28
|
|
|
if (method_exists('TYPO3\Neos\Utility\NodeUriPathSegmentGenerator', 'setUniqueUriPathSegment')) { |
29
|
|
|
$nodeUriPathSegmentGenerator->setUniqueUriPathSegment($node); |
30
|
|
|
} else { |
31
|
|
|
$node->setProperty('uriPathSegment', $newUriPathSegment); |
32
|
|
|
} |
33
|
|
|
$bootstrap->getObjectManager()->get('TYPO3\Neos\Routing\Cache\RouteCacheFlusher')->registerNodeChange($node); |
34
|
|
|
} elseif ($propertyName === 'uriPathSegment' && $newUriPathSegment !== NULL && $newValue !== $newUriPathSegment) { |
35
|
|
|
if (method_exists('TYPO3\Neos\Utility\NodeUriPathSegmentGenerator', 'setUniqueUriPathSegment')) { |
36
|
|
|
$nodeUriPathSegmentGenerator->setUniqueUriPathSegment($node); |
37
|
|
|
} else { |
38
|
|
|
$node->setProperty('uriPathSegment', $newUriPathSegment); |
39
|
|
|
} |
40
|
|
|
$newUriPathSegment = NULL; |
41
|
|
|
} |
42
|
|
|
}); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: