Skip to content

Commit f645237

Browse files
committed
Merge pull request #35 from thomasblass/ObjectIdentifierTransformer
[Task] Add ObjectIdentifierTransformer
2 parents 97698dd + 757ab45 commit f645237

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
namespace Flowpack\ElasticSearch\Indexer\Object\Transform;
3+
4+
/* *
5+
* This script belongs to the TYPO3 Flow package "Flowpack.ElasticSearch".*
6+
* *
7+
* It is free software; you can redistribute it and/or modify it under *
8+
* the terms of the GNU Lesser General Public License, either version 3 *
9+
* of the License, or (at your option) any later version. *
10+
* *
11+
* The TYPO3 project - inspiring people to share! *
12+
* */
13+
14+
use TYPO3\Flow\Annotations as Flow;
15+
use TYPO3\Flow\Persistence\PersistenceManagerInterface;
16+
17+
/**
18+
* @Flow\Scope("singleton")
19+
*/
20+
class ObjectIdentifierTransformer implements TransformerInterface {
21+
22+
/**
23+
* @Flow\Inject
24+
* @var PersistenceManagerInterface
25+
*/
26+
protected $persistenceManager;
27+
28+
/**
29+
* Returns the Elasticsearch type this transform() method returns
30+
*
31+
* @return string
32+
*/
33+
public function getTargetMappingType() {
34+
return 'string';
35+
}
36+
37+
/**
38+
* @param mixed $source
39+
* @param \Flowpack\ElasticSearch\Annotations\Transform $annotation
40+
* @return string
41+
*/
42+
public function transformByAnnotation($source, \Flowpack\ElasticSearch\Annotations\Transform $annotation) {
43+
if($source != null) {
44+
return $this->persistenceManager->getIdentifierByObject($source);
45+
}
46+
return '';
47+
}
48+
}
49+

0 commit comments

Comments
 (0)