Completed
Push — master ( e35e6f...5d201a )
by Fabien
53:19
created
Classes/Domain/Validator/MatchesValidator.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -23,20 +23,20 @@
 block discarded – undo
23 23
 class MatchesValidator extends AbstractValidator
24 24
 {
25 25
 
26
-    /**
27
-     * Check if $matches is valid. If it is not valid, throw an exception.
28
-     *
29
-     * @param mixed $matches
30
-     * @return void
31
-     */
32
-    public function isValid($matches)
33
-    {
26
+	/**
27
+	 * Check if $matches is valid. If it is not valid, throw an exception.
28
+	 *
29
+	 * @param mixed $matches
30
+	 * @return void
31
+	 */
32
+	public function isValid($matches)
33
+	{
34 34
 
35
-        foreach ($matches as $fieldName => $value) {
36
-            if (!Tca::table()->hasField($fieldName)) {
37
-                $message = sprintf('Field "%s" is not allowed. Actually, it is not configured in the TCA.', $fieldName);
38
-                $this->addError($message, 1380019718);
39
-            }
40
-        }
41
-    }
35
+		foreach ($matches as $fieldName => $value) {
36
+			if (!Tca::table()->hasField($fieldName)) {
37
+				$message = sprintf('Field "%s" is not allowed. Actually, it is not configured in the TCA.', $fieldName);
38
+				$this->addError($message, 1380019718);
39
+			}
40
+		}
41
+	}
42 42
 }
Please login to merge, or discard this patch.
Tests/Feature/bootstrap/FeatureContext.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -14,16 +14,16 @@
 block discarded – undo
14 14
  */
15 15
 class FeatureContext extends MinkContext
16 16
 {
17
-    /**
18
-     * Initializes context.
19
-     * Every scenario gets it's own context object.
20
-     *
21
-     * @param array $parameters context parameters (set them up through behat.yml)
22
-     */
23
-    public function __construct(array $parameters)
24
-    {
25
-        // Initialize your context here
26
-    }
17
+	/**
18
+	 * Initializes context.
19
+	 * Every scenario gets it's own context object.
20
+	 *
21
+	 * @param array $parameters context parameters (set them up through behat.yml)
22
+	 */
23
+	public function __construct(array $parameters)
24
+	{
25
+		// Initialize your context here
26
+	}
27 27
 
28 28
 	/**
29 29
 	 * @Given /^I wait "([^"]*)" seconds$/
Please login to merge, or discard this patch.
Classes/Resolver/FieldPathResolver.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -25,111 +25,111 @@
 block discarded – undo
25 25
 class FieldPathResolver implements SingletonInterface
26 26
 {
27 27
 
28
-    /**
29
-     * Remove the prefixing path from the file name.
30
-     *
31
-     * @param string $fieldNameAndPath
32
-     * @param string $dataType
33
-     * @return string
34
-     */
35
-    public function stripFieldPath($fieldNameAndPath, $dataType = '')
36
-    {
37
-
38
-        $dataType = $this->getContextualDataType($dataType);
39
-
40
-        if ($this->containsPath($fieldNameAndPath, $dataType)) {
41
-
42
-            // Corresponds to the field name of the foreign table.
43
-            $fieldParts = GeneralUtility::trimExplode('.', $fieldNameAndPath);
44
-            $fieldName = $fieldParts[1];
45
-        } else {
46
-            $fieldName = $fieldNameAndPath;
47
-        }
48
-        return $fieldName;
49
-    }
50
-
51
-    /**
52
-     * Remove the suffixing field name
53
-     *
54
-     * @param string $fieldNameAndPath
55
-     * @param string $dataType
56
-     * @return string
57
-     */
58
-    public function stripFieldName($fieldNameAndPath, $dataType = '')
59
-    {
60
-
61
-        $dataType = $this->getContextualDataType($dataType);
62
-
63
-        if ($this->containsPath($fieldNameAndPath, $dataType)) {
64
-
65
-            // Corresponds to the field name of the foreign table.
66
-            $fieldParts = GeneralUtility::trimExplode('.', $fieldNameAndPath);
67
-            $fieldName = $fieldParts[0];
68
-        } else {
69
-            $fieldName = $fieldNameAndPath;
70
-        }
71
-        return $fieldName;
72
-    }
73
-
74
-    /**
75
-     * Returns the class names to be applied to a cell ("td").
76
-     *
77
-     * @param string $fieldNameAndPath
78
-     * @param string $dataType
79
-     * @return string
80
-     */
81
-    public function getDataType($fieldNameAndPath, $dataType = '')
82
-    {
83
-
84
-        $dataType = $this->getContextualDataType($dataType);
85
-
86
-        if ($this->containsPath($fieldNameAndPath, $dataType)) {
87
-
88
-            // Compute the foreign data type.
89
-            $fieldParts = GeneralUtility::trimExplode('.', $fieldNameAndPath);
90
-            $fieldNameAndPath = $fieldParts[0];
91
-            $dataType = Tca::table($dataType)->field($fieldNameAndPath)->getForeignTable();
92
-        }
93
-        return $dataType;
94
-    }
95
-
96
-    /**
97
-     * Return the data type according to the context.
98
-     *
99
-     * @param $dataType
100
-     * @return string
101
-     */
102
-    public function getContextualDataType($dataType)
103
-    {
104
-
105
-        if (!$dataType) {
106
-            $dataType = $this->getModuleLoader()->getDataType();
107
-        }
108
-        return $dataType;
109
-    }
110
-
111
-    /**
112
-     * Tell whether the field name contains a path, e.g. metadata.title
113
-     * But resolves the case when the field is composite e.g "items.sys_file_metadata" and looks as field path but is not!
114
-     * A composite field = a field for a MM relation  of type "group" where the table name is appended.
115
-     *
116
-     * @param string $fieldNameAndPath
117
-     * @param string $dataType
118
-     * @return boolean
119
-     */
120
-    public function containsPath($fieldNameAndPath, $dataType)
121
-    {
122
-        $doesContainPath = strpos($fieldNameAndPath, '.') > 0 && !Tca::table($dataType)->hasField($fieldNameAndPath); // -> will make sure it is not a composite field name.
123
-        return $doesContainPath;
124
-    }
125
-
126
-    /**
127
-     * Get the Vidi Module Loader.
128
-     *
129
-     * @return ModuleLoader
130
-     */
131
-    protected function getModuleLoader()
132
-    {
133
-        return GeneralUtility::makeInstance(ModuleLoader::class);
134
-    }
28
+	/**
29
+	 * Remove the prefixing path from the file name.
30
+	 *
31
+	 * @param string $fieldNameAndPath
32
+	 * @param string $dataType
33
+	 * @return string
34
+	 */
35
+	public function stripFieldPath($fieldNameAndPath, $dataType = '')
36
+	{
37
+
38
+		$dataType = $this->getContextualDataType($dataType);
39
+
40
+		if ($this->containsPath($fieldNameAndPath, $dataType)) {
41
+
42
+			// Corresponds to the field name of the foreign table.
43
+			$fieldParts = GeneralUtility::trimExplode('.', $fieldNameAndPath);
44
+			$fieldName = $fieldParts[1];
45
+		} else {
46
+			$fieldName = $fieldNameAndPath;
47
+		}
48
+		return $fieldName;
49
+	}
50
+
51
+	/**
52
+	 * Remove the suffixing field name
53
+	 *
54
+	 * @param string $fieldNameAndPath
55
+	 * @param string $dataType
56
+	 * @return string
57
+	 */
58
+	public function stripFieldName($fieldNameAndPath, $dataType = '')
59
+	{
60
+
61
+		$dataType = $this->getContextualDataType($dataType);
62
+
63
+		if ($this->containsPath($fieldNameAndPath, $dataType)) {
64
+
65
+			// Corresponds to the field name of the foreign table.
66
+			$fieldParts = GeneralUtility::trimExplode('.', $fieldNameAndPath);
67
+			$fieldName = $fieldParts[0];
68
+		} else {
69
+			$fieldName = $fieldNameAndPath;
70
+		}
71
+		return $fieldName;
72
+	}
73
+
74
+	/**
75
+	 * Returns the class names to be applied to a cell ("td").
76
+	 *
77
+	 * @param string $fieldNameAndPath
78
+	 * @param string $dataType
79
+	 * @return string
80
+	 */
81
+	public function getDataType($fieldNameAndPath, $dataType = '')
82
+	{
83
+
84
+		$dataType = $this->getContextualDataType($dataType);
85
+
86
+		if ($this->containsPath($fieldNameAndPath, $dataType)) {
87
+
88
+			// Compute the foreign data type.
89
+			$fieldParts = GeneralUtility::trimExplode('.', $fieldNameAndPath);
90
+			$fieldNameAndPath = $fieldParts[0];
91
+			$dataType = Tca::table($dataType)->field($fieldNameAndPath)->getForeignTable();
92
+		}
93
+		return $dataType;
94
+	}
95
+
96
+	/**
97
+	 * Return the data type according to the context.
98
+	 *
99
+	 * @param $dataType
100
+	 * @return string
101
+	 */
102
+	public function getContextualDataType($dataType)
103
+	{
104
+
105
+		if (!$dataType) {
106
+			$dataType = $this->getModuleLoader()->getDataType();
107
+		}
108
+		return $dataType;
109
+	}
110
+
111
+	/**
112
+	 * Tell whether the field name contains a path, e.g. metadata.title
113
+	 * But resolves the case when the field is composite e.g "items.sys_file_metadata" and looks as field path but is not!
114
+	 * A composite field = a field for a MM relation  of type "group" where the table name is appended.
115
+	 *
116
+	 * @param string $fieldNameAndPath
117
+	 * @param string $dataType
118
+	 * @return boolean
119
+	 */
120
+	public function containsPath($fieldNameAndPath, $dataType)
121
+	{
122
+		$doesContainPath = strpos($fieldNameAndPath, '.') > 0 && !Tca::table($dataType)->hasField($fieldNameAndPath); // -> will make sure it is not a composite field name.
123
+		return $doesContainPath;
124
+	}
125
+
126
+	/**
127
+	 * Get the Vidi Module Loader.
128
+	 *
129
+	 * @return ModuleLoader
130
+	 */
131
+	protected function getModuleLoader()
132
+	{
133
+		return GeneralUtility::makeInstance(ModuleLoader::class);
134
+	}
135 135
 }
Please login to merge, or discard this patch.
Classes/Grid/ColumnRendererInterface.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -14,46 +14,46 @@
 block discarded – undo
14 14
 interface ColumnRendererInterface
15 15
 {
16 16
 
17
-    /**
18
-     * Render a column in the Grid.
19
-     *
20
-     * @return string
21
-     */
22
-    public function render();
23
-
24
-    /**
25
-     * @param \Fab\Vidi\Domain\Model\Content $object
26
-     * @return $this
27
-     */
28
-    public function setObject($object);
29
-
30
-    /**
31
-     * @param string $fieldName
32
-     * @return $this
33
-     */
34
-    public function setFieldName($fieldName);
35
-
36
-    /**
37
-     * @param int $index
38
-     * @return $this
39
-     */
40
-    public function setRowIndex($index);
41
-
42
-    /**
43
-     * @param array $configuration
44
-     * @return $this
45
-     */
46
-    public function setFieldConfiguration($configuration);
47
-
48
-    /**
49
-     * @param array $configuration
50
-     * @return $this
51
-     */
52
-    public function setGridRendererConfiguration($configuration);
53
-
54
-    /**
55
-     * @return array
56
-     */
57
-    public function getConfiguration();
17
+	/**
18
+	 * Render a column in the Grid.
19
+	 *
20
+	 * @return string
21
+	 */
22
+	public function render();
23
+
24
+	/**
25
+	 * @param \Fab\Vidi\Domain\Model\Content $object
26
+	 * @return $this
27
+	 */
28
+	public function setObject($object);
29
+
30
+	/**
31
+	 * @param string $fieldName
32
+	 * @return $this
33
+	 */
34
+	public function setFieldName($fieldName);
35
+
36
+	/**
37
+	 * @param int $index
38
+	 * @return $this
39
+	 */
40
+	public function setRowIndex($index);
41
+
42
+	/**
43
+	 * @param array $configuration
44
+	 * @return $this
45
+	 */
46
+	public function setFieldConfiguration($configuration);
47
+
48
+	/**
49
+	 * @param array $configuration
50
+	 * @return $this
51
+	 */
52
+	public function setGridRendererConfiguration($configuration);
53
+
54
+	/**
55
+	 * @return array
56
+	 */
57
+	public function getConfiguration();
58 58
 
59 59
 }
Please login to merge, or discard this patch.
Classes/Tool/AbstractTool.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -18,51 +18,51 @@
 block discarded – undo
18 18
 abstract class AbstractTool implements ToolInterface
19 19
 {
20 20
 
21
-    /**
22
-     * @param string $templateNameAndPath
23
-     * @return StandaloneView
24
-     * @throws \InvalidArgumentException
25
-     */
26
-    protected function initializeStandaloneView($templateNameAndPath)
27
-    {
21
+	/**
22
+	 * @param string $templateNameAndPath
23
+	 * @return StandaloneView
24
+	 * @throws \InvalidArgumentException
25
+	 */
26
+	protected function initializeStandaloneView($templateNameAndPath)
27
+	{
28 28
 
29
-        $templateNameAndPath = GeneralUtility::getFileAbsFileName($templateNameAndPath);
29
+		$templateNameAndPath = GeneralUtility::getFileAbsFileName($templateNameAndPath);
30 30
 
31
-        /** @var StandaloneView $view */
32
-        $view = $this->getObjectManager()->get(StandaloneView::class);
31
+		/** @var StandaloneView $view */
32
+		$view = $this->getObjectManager()->get(StandaloneView::class);
33 33
 
34
-        $view->setTemplatePathAndFilename($templateNameAndPath);
35
-        return $view;
36
-    }
34
+		$view->setTemplatePathAndFilename($templateNameAndPath);
35
+		return $view;
36
+	}
37 37
 
38
-    /**
39
-     * Returns an instance of the current Backend User.
40
-     *
41
-     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
42
-     */
43
-    protected function getBackendUser()
44
-    {
45
-        return $GLOBALS['BE_USER'];
46
-    }
38
+	/**
39
+	 * Returns an instance of the current Backend User.
40
+	 *
41
+	 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
42
+	 */
43
+	protected function getBackendUser()
44
+	{
45
+		return $GLOBALS['BE_USER'];
46
+	}
47 47
 
48
-    /**
49
-     * @return ObjectManager
50
-     * @throws \InvalidArgumentException
51
-     */
52
-    protected function getObjectManager()
53
-    {
54
-        return GeneralUtility::makeInstance(ObjectManager::class);
55
-    }
48
+	/**
49
+	 * @return ObjectManager
50
+	 * @throws \InvalidArgumentException
51
+	 */
52
+	protected function getObjectManager()
53
+	{
54
+		return GeneralUtility::makeInstance(ObjectManager::class);
55
+	}
56 56
 
57
-    /**
58
-     * Get the Vidi Module Loader.
59
-     *
60
-     * @return ModuleLoader
61
-     * @throws \InvalidArgumentException
62
-     */
63
-    protected function getModuleLoader()
64
-    {
65
-        return GeneralUtility::makeInstance(ModuleLoader::class);
66
-    }
57
+	/**
58
+	 * Get the Vidi Module Loader.
59
+	 *
60
+	 * @return ModuleLoader
61
+	 * @throws \InvalidArgumentException
62
+	 */
63
+	protected function getModuleLoader()
64
+	{
65
+		return GeneralUtility::makeInstance(ModuleLoader::class);
66
+	}
67 67
 
68 68
 }
Please login to merge, or discard this patch.
Classes/ViewHelpers/Content/FindOneViewHelper.php 1 patch
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -24,174 +24,174 @@
 block discarded – undo
24 24
 class FindOneViewHelper extends AbstractViewHelper implements CompilableInterface
25 25
 {
26 26
 
27
-    /**
28
-     * @return void
29
-     * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
30
-     */
31
-    public function initializeArguments()
32
-    {
33
-        parent::initializeArguments();
34
-
35
-        $this->registerArgument('type', 'string', 'The content type', true, '');
36
-        $this->registerArgument('matches', 'array', 'Key / value array to be used as filter. The key corresponds to a field name.', false, []);
37
-        $this->registerArgument('identifier', 'int', 'The identifier of the object to be fetched.', false, 0);
38
-        $this->registerArgument('argumentName', 'string', 'The parameter name where to retrieve the identifier', false, 'tx_vidifrontend_pi1|uid');
39
-        $this->registerArgument('as', 'string', 'The alias object', false, 'object');
40
-    }
41
-
42
-    /**
43
-     * @return string Rendered string
44
-     * @throws \Fab\Vidi\Exception\NotExistingClassException
45
-     * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException
46
-     * @throws \InvalidArgumentException
47
-     * @api
48
-     */
49
-    public function render()
50
-    {
51
-        return static::renderStatic(
52
-            $this->arguments,
53
-            $this->buildRenderChildrenClosure(),
54
-            $this->renderingContext
55
-        );
56
-    }
57
-
58
-    /**
59
-     * @param array $arguments
60
-     * @param \Closure $renderChildrenClosure
61
-     * @param RenderingContextInterface $renderingContext
62
-     *
63
-     * @return string
64
-     * @throws \Fab\Vidi\Exception\NotExistingClassException
65
-     * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException
66
-     * @throws \InvalidArgumentException
67
-     */
68
-    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
69
-    {
70
-
71
-        // Fetch the object
72
-        $matches = self::computeMatches($arguments);
73
-        $matcher = self::getMatcher($arguments['type'], $matches);
74
-
75
-        $contentRepository = ContentRepositoryFactory::getInstance($arguments['type']);
76
-        $object = $contentRepository->findOneBy($matcher);
77
-
78
-        $output = '';
79
-        if ($object) {
80
-            // Render children with "as" variable.
81
-            $templateVariableContainer = $renderingContext->getTemplateVariableContainer();
82
-            $templateVariableContainer->add($arguments['as'], $object);
83
-            $output = $renderChildrenClosure();
84
-            $templateVariableContainer->remove($arguments['as']);
85
-        }
86
-
87
-        return $output;
88
-    }
89
-
90
-    /**
91
-     * @param array $arguments
92
-     * @return array
93
-     */
94
-    protected static function computeMatches(array $arguments)
95
-    {
96
-
97
-        $matches = [];
98
-
99
-        $argumentValue = self::getArgumentValue($arguments['argumentName']);
100
-        if ($argumentValue > 0) {
101
-            $matches['uid'] = $argumentValue;
102
-        }
103
-
104
-        if ($arguments['matches']) {
105
-            $matches = $arguments['matches'];
106
-        }
107
-
108
-        if ($arguments['identifier'] > 0) {
109
-            $matches['uid'] = $arguments['identifier'];
110
-        }
111
-
112
-        // We want a default value in any case.
113
-        if (!$matches) {
114
-            $matches['uid'] = 0;
115
-        }
116
-        return $matches;
117
-    }
118
-
119
-    /**
120
-     * Returns a matcher object.
121
-     *
122
-     * @param string $dataType
123
-     * @param array $matches
124
-     * @return Matcher
125
-     * @throws \Fab\Vidi\Exception\NotExistingClassException
126
-     * @throws \InvalidArgumentException
127
-     */
128
-    protected static function getMatcher($dataType, array $matches = [])
129
-    {
130
-
131
-        /** @var $matcher Matcher */
132
-        $matcher = GeneralUtility::makeInstance(Matcher::class, [], $dataType);
133
-
134
-        foreach ($matches as $fieldNameAndPath => $value) {
135
-
136
-            // CSV values should be considered as "in" operator in Query, otherwise "equals".
137
-            $explodedValues = GeneralUtility::trimExplode(',', $value, true);
138
-
139
-            // The matching value contains a "1,2" as example
140
-            if (count($explodedValues) > 1) {
141
-
142
-                $resolvedDataType = self::getFieldPathResolver()->getDataType($fieldNameAndPath, $dataType);
143
-                $resolvedFieldName = self::getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $dataType);
144
-
145
-                // "equals" if in presence of a relation.
146
-                // "in" if not a relation.
147
-                if (Tca::table($resolvedDataType)->field($resolvedFieldName)->hasRelation()) {
148
-                    foreach ($explodedValues as $explodedValue) {
149
-                        $matcher->equals($fieldNameAndPath, $explodedValue);
150
-                    }
151
-                } else {
152
-                    $matcher->in($fieldNameAndPath, $explodedValues);
153
-                }
154
-            } else {
155
-                $matcher->equals($fieldNameAndPath, $explodedValues[0]);
156
-            }
157
-        }
158
-
159
-        return $matcher;
160
-    }
161
-
162
-    /**
163
-     * @return FieldPathResolver
164
-     * @throws \InvalidArgumentException
165
-     */
166
-    protected static function getFieldPathResolver()
167
-    {
168
-        return GeneralUtility::makeInstance(FieldPathResolver::class);
169
-    }
170
-
171
-    /**
172
-     * @param string $argumentName
173
-     * @return int
174
-     */
175
-    protected static function getArgumentValue($argumentName)
176
-    {
177
-
178
-        $value = ''; // default value
179
-
180
-        // Merge parameters
181
-        $parameters = GeneralUtility::_GET();
182
-        $post = GeneralUtility::_POST();
183
-        ArrayUtility::mergeRecursiveWithOverrule($parameters, $post);
184
-
185
-        // Traverse argument parts and retrieve value.
186
-        $argumentParts = GeneralUtility::trimExplode('|', $argumentName);
187
-        foreach ($argumentParts as $argumentPart) {
188
-            if (isset($parameters[$argumentPart])) {
189
-                $value = $parameters[$argumentPart];
190
-                $parameters = $value;
191
-            }
192
-        }
193
-
194
-        return (int)$value;
195
-    }
27
+	/**
28
+	 * @return void
29
+	 * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
30
+	 */
31
+	public function initializeArguments()
32
+	{
33
+		parent::initializeArguments();
34
+
35
+		$this->registerArgument('type', 'string', 'The content type', true, '');
36
+		$this->registerArgument('matches', 'array', 'Key / value array to be used as filter. The key corresponds to a field name.', false, []);
37
+		$this->registerArgument('identifier', 'int', 'The identifier of the object to be fetched.', false, 0);
38
+		$this->registerArgument('argumentName', 'string', 'The parameter name where to retrieve the identifier', false, 'tx_vidifrontend_pi1|uid');
39
+		$this->registerArgument('as', 'string', 'The alias object', false, 'object');
40
+	}
41
+
42
+	/**
43
+	 * @return string Rendered string
44
+	 * @throws \Fab\Vidi\Exception\NotExistingClassException
45
+	 * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException
46
+	 * @throws \InvalidArgumentException
47
+	 * @api
48
+	 */
49
+	public function render()
50
+	{
51
+		return static::renderStatic(
52
+			$this->arguments,
53
+			$this->buildRenderChildrenClosure(),
54
+			$this->renderingContext
55
+		);
56
+	}
57
+
58
+	/**
59
+	 * @param array $arguments
60
+	 * @param \Closure $renderChildrenClosure
61
+	 * @param RenderingContextInterface $renderingContext
62
+	 *
63
+	 * @return string
64
+	 * @throws \Fab\Vidi\Exception\NotExistingClassException
65
+	 * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException
66
+	 * @throws \InvalidArgumentException
67
+	 */
68
+	public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
69
+	{
70
+
71
+		// Fetch the object
72
+		$matches = self::computeMatches($arguments);
73
+		$matcher = self::getMatcher($arguments['type'], $matches);
74
+
75
+		$contentRepository = ContentRepositoryFactory::getInstance($arguments['type']);
76
+		$object = $contentRepository->findOneBy($matcher);
77
+
78
+		$output = '';
79
+		if ($object) {
80
+			// Render children with "as" variable.
81
+			$templateVariableContainer = $renderingContext->getTemplateVariableContainer();
82
+			$templateVariableContainer->add($arguments['as'], $object);
83
+			$output = $renderChildrenClosure();
84
+			$templateVariableContainer->remove($arguments['as']);
85
+		}
86
+
87
+		return $output;
88
+	}
89
+
90
+	/**
91
+	 * @param array $arguments
92
+	 * @return array
93
+	 */
94
+	protected static function computeMatches(array $arguments)
95
+	{
96
+
97
+		$matches = [];
98
+
99
+		$argumentValue = self::getArgumentValue($arguments['argumentName']);
100
+		if ($argumentValue > 0) {
101
+			$matches['uid'] = $argumentValue;
102
+		}
103
+
104
+		if ($arguments['matches']) {
105
+			$matches = $arguments['matches'];
106
+		}
107
+
108
+		if ($arguments['identifier'] > 0) {
109
+			$matches['uid'] = $arguments['identifier'];
110
+		}
111
+
112
+		// We want a default value in any case.
113
+		if (!$matches) {
114
+			$matches['uid'] = 0;
115
+		}
116
+		return $matches;
117
+	}
118
+
119
+	/**
120
+	 * Returns a matcher object.
121
+	 *
122
+	 * @param string $dataType
123
+	 * @param array $matches
124
+	 * @return Matcher
125
+	 * @throws \Fab\Vidi\Exception\NotExistingClassException
126
+	 * @throws \InvalidArgumentException
127
+	 */
128
+	protected static function getMatcher($dataType, array $matches = [])
129
+	{
130
+
131
+		/** @var $matcher Matcher */
132
+		$matcher = GeneralUtility::makeInstance(Matcher::class, [], $dataType);
133
+
134
+		foreach ($matches as $fieldNameAndPath => $value) {
135
+
136
+			// CSV values should be considered as "in" operator in Query, otherwise "equals".
137
+			$explodedValues = GeneralUtility::trimExplode(',', $value, true);
138
+
139
+			// The matching value contains a "1,2" as example
140
+			if (count($explodedValues) > 1) {
141
+
142
+				$resolvedDataType = self::getFieldPathResolver()->getDataType($fieldNameAndPath, $dataType);
143
+				$resolvedFieldName = self::getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $dataType);
144
+
145
+				// "equals" if in presence of a relation.
146
+				// "in" if not a relation.
147
+				if (Tca::table($resolvedDataType)->field($resolvedFieldName)->hasRelation()) {
148
+					foreach ($explodedValues as $explodedValue) {
149
+						$matcher->equals($fieldNameAndPath, $explodedValue);
150
+					}
151
+				} else {
152
+					$matcher->in($fieldNameAndPath, $explodedValues);
153
+				}
154
+			} else {
155
+				$matcher->equals($fieldNameAndPath, $explodedValues[0]);
156
+			}
157
+		}
158
+
159
+		return $matcher;
160
+	}
161
+
162
+	/**
163
+	 * @return FieldPathResolver
164
+	 * @throws \InvalidArgumentException
165
+	 */
166
+	protected static function getFieldPathResolver()
167
+	{
168
+		return GeneralUtility::makeInstance(FieldPathResolver::class);
169
+	}
170
+
171
+	/**
172
+	 * @param string $argumentName
173
+	 * @return int
174
+	 */
175
+	protected static function getArgumentValue($argumentName)
176
+	{
177
+
178
+		$value = ''; // default value
179
+
180
+		// Merge parameters
181
+		$parameters = GeneralUtility::_GET();
182
+		$post = GeneralUtility::_POST();
183
+		ArrayUtility::mergeRecursiveWithOverrule($parameters, $post);
184
+
185
+		// Traverse argument parts and retrieve value.
186
+		$argumentParts = GeneralUtility::trimExplode('|', $argumentName);
187
+		foreach ($argumentParts as $argumentPart) {
188
+			if (isset($parameters[$argumentPart])) {
189
+				$value = $parameters[$argumentPart];
190
+				$parameters = $value;
191
+			}
192
+		}
193
+
194
+		return (int)$value;
195
+	}
196 196
 
197 197
 }
Please login to merge, or discard this patch.
Classes/View/Button/EditButton.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -20,35 +20,35 @@
 block discarded – undo
20 20
 class EditButton extends AbstractComponentView
21 21
 {
22 22
 
23
-    /**
24
-     * Renders a "edit" button to be placed in the grid.
25
-     *
26
-     * @param Content $object
27
-     * @return string
28
-     */
29
-    public function render(Content $object = null)
30
-    {
31
-        $editUri = $this->getUriRenderer()->render($object);
23
+	/**
24
+	 * Renders a "edit" button to be placed in the grid.
25
+	 *
26
+	 * @param Content $object
27
+	 * @return string
28
+	 */
29
+	public function render(Content $object = null)
30
+	{
31
+		$editUri = $this->getUriRenderer()->render($object);
32 32
 
33
-        return $this->makeLinkButton()
34
-            ->setHref($editUri)
35
-            ->setDataAttributes([
36
-                'uid' => $object->getUid(),
37
-                'toggle' => 'tooltip',
38
-            ])
39
-            ->setClasses('btn-edit')
40
-            ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:edit'))
41
-            ->setIcon($this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL))
42
-            ->render();
43
-    }
33
+		return $this->makeLinkButton()
34
+			->setHref($editUri)
35
+			->setDataAttributes([
36
+				'uid' => $object->getUid(),
37
+				'toggle' => 'tooltip',
38
+			])
39
+			->setClasses('btn-edit')
40
+			->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:edit'))
41
+			->setIcon($this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL))
42
+			->render();
43
+	}
44 44
 
45
-    /**
46
-     * @return \Fab\Vidi\View\Uri\EditUri
47
-     * @throws \InvalidArgumentException
48
-     */
49
-    protected function getUriRenderer()
50
-    {
51
-        return GeneralUtility::makeInstance(EditUri::class);
52
-    }
45
+	/**
46
+	 * @return \Fab\Vidi\View\Uri\EditUri
47
+	 * @throws \InvalidArgumentException
48
+	 */
49
+	protected function getUriRenderer()
50
+	{
51
+		return GeneralUtility::makeInstance(EditUri::class);
52
+	}
53 53
 
54 54
 }
Please login to merge, or discard this patch.
Classes/View/Button/DeleteButton.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -19,47 +19,47 @@
 block discarded – undo
19 19
 class DeleteButton extends AbstractComponentView
20 20
 {
21 21
 
22
-    /**
23
-     * Renders a "delete" button to be placed in the grid.
24
-     *
25
-     * @param Content $object
26
-     * @return string
27
-     */
28
-    public function render(Content $object = null)
29
-    {
30
-        $labelField = Tca::table($object->getDataType())->getLabelField();
31
-        $label = $object[$labelField] ? $object[$labelField] : $object->getUid();
22
+	/**
23
+	 * Renders a "delete" button to be placed in the grid.
24
+	 *
25
+	 * @param Content $object
26
+	 * @return string
27
+	 */
28
+	public function render(Content $object = null)
29
+	{
30
+		$labelField = Tca::table($object->getDataType())->getLabelField();
31
+		$label = $object[$labelField] ? $object[$labelField] : $object->getUid();
32 32
 
33
-        return $this->makeLinkButton()
34
-            ->setHref($this->getDeleteUri($object))
35
-            ->setDataAttributes([
36
-                'uid' => $object->getUid(),
37
-                'toggle' => 'tooltip',
38
-                'label' => $label,
39
-            ])
40
-            ->setClasses('btn-delete')
41
-            ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:delete'))
42
-            ->setIcon($this->getIconFactory()->getIcon('actions-edit-delete', Icon::SIZE_SMALL))
43
-            ->render();
44
-    }
33
+		return $this->makeLinkButton()
34
+			->setHref($this->getDeleteUri($object))
35
+			->setDataAttributes([
36
+				'uid' => $object->getUid(),
37
+				'toggle' => 'tooltip',
38
+				'label' => $label,
39
+			])
40
+			->setClasses('btn-delete')
41
+			->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:delete'))
42
+			->setIcon($this->getIconFactory()->getIcon('actions-edit-delete', Icon::SIZE_SMALL))
43
+			->render();
44
+	}
45 45
 
46
-    /**
47
-     * @param Content $object
48
-     * @return string
49
-     */
50
-    protected function getDeleteUri(Content $object)
51
-    {
52
-        $additionalParameters = array(
53
-            $this->getModuleLoader()->getParameterPrefix() => array(
54
-                'controller' => 'Content',
55
-                'action' => 'delete',
56
-                'format' => 'json',
57
-                'matches' => array(
58
-                    'uid' => $object->getUid(),
59
-                ),
60
-            ),
61
-        );
62
-        return $this->getModuleLoader()->getModuleUrl($additionalParameters);
63
-    }
46
+	/**
47
+	 * @param Content $object
48
+	 * @return string
49
+	 */
50
+	protected function getDeleteUri(Content $object)
51
+	{
52
+		$additionalParameters = array(
53
+			$this->getModuleLoader()->getParameterPrefix() => array(
54
+				'controller' => 'Content',
55
+				'action' => 'delete',
56
+				'format' => 'json',
57
+				'matches' => array(
58
+					'uid' => $object->getUid(),
59
+				),
60
+			),
61
+		);
62
+		return $this->getModuleLoader()->getModuleUrl($additionalParameters);
63
+	}
64 64
 
65 65
 }
Please login to merge, or discard this patch.
Classes/View/System/ButtonsSystem.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -19,15 +19,15 @@
 block discarded – undo
19 19
 class ButtonsSystem extends AbstractComponentView
20 20
 {
21 21
 
22
-    /**
23
-     * Rendering buttons in the grids given a Content object.
24
-     *
25
-     * @param Content $object
26
-     * @return string
27
-     */
28
-    public function render(Content $object = null)
29
-    {
30
-        return '';
31
-    }
22
+	/**
23
+	 * Rendering buttons in the grids given a Content object.
24
+	 *
25
+	 * @param Content $object
26
+	 * @return string
27
+	 */
28
+	public function render(Content $object = null)
29
+	{
30
+		return '';
31
+	}
32 32
 
33 33
 }
Please login to merge, or discard this patch.