Completed
Push — master ( 5794c5...08c98b )
by Fabien
53:00
created
Classes/Grid/GridAnalyserService.php 1 patch
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -16,108 +16,108 @@
 block discarded – undo
16 16
  */
17 17
 class GridAnalyserService
18 18
 {
19
-    /**
20
-     * Check relation for table.
21
-     *
22
-     * @param $tableName
23
-     * @return array
24
-     */
25
-    public function checkRelationForTable($tableName)
26
-    {
27
-        $relations = [];
28
-        $table = Tca::table($tableName);
29
-
30
-        $missingOppositionRelationMessage = <<<EOF
19
+	/**
20
+	 * Check relation for table.
21
+	 *
22
+	 * @param $tableName
23
+	 * @return array
24
+	 */
25
+	public function checkRelationForTable($tableName)
26
+	{
27
+		$relations = [];
28
+		$table = Tca::table($tableName);
29
+
30
+		$missingOppositionRelationMessage = <<<EOF
31 31
 
32 32
   WARNING! Could not define relation precisely. This is not necessarily a problem
33 33
   if the opposite relation is not required in a Grid. But consider adding the opposite
34 34
   TCA configuration if so.
35 35
 EOF;
36 36
 
37
-        foreach (Tca::grid($tableName)->getFields() as $fieldName => $configuration) {
38
-            if ($table->hasField($fieldName)) {
39
-                if ($table->field($fieldName)->hasMany()) {
40
-                    if ($table->field($fieldName)->hasRelationWithCommaSeparatedValues()) {
41
-                        $_relations = $this->checkRelationOf($tableName, $fieldName, 'comma separated values');
42
-                        $relations = array_merge($relations, $_relations);
43
-                    } elseif ($table->field($fieldName)->hasRelationManyToMany()) {
44
-                        $_relations = $this->checkRelationManyToMany($tableName, $fieldName);
45
-                        $relations = array_merge($relations, $_relations);
46
-                    } elseif ($table->field($fieldName)->hasRelationOneToMany()) {
47
-                        $_relations = $this->checkRelationOf($tableName, $fieldName, 'one-to-many');
48
-                        $relations = array_merge($relations, $_relations);
49
-                    } else {
50
-                        $relations[] = sprintf('* field: "%s", relation: ?-to-many%s', $fieldName, $missingOppositionRelationMessage);
51
-                    }
52
-                    $relations[] = '';
53
-                } elseif ($table->field($fieldName)->hasOne()) {
54
-                    if ($table->field($fieldName)->hasRelationOneToOne()) {
55
-                        $relations[] = sprintf('* one-to-one "%s"', $fieldName);
56
-                    } elseif ($table->field($fieldName)->hasRelationManyToOne()) {
57
-                        $_relations = $this->checkRelationOf($tableName, $fieldName, 'many-to-one');
58
-                        $relations = array_merge($relations, $_relations);
59
-                    } else {
60
-                        $relations[] = sprintf('* field: "%s", relation: ?-to-one%s', $fieldName, $missingOppositionRelationMessage);
61
-                    }
62
-                    $relations[] = '';
63
-                }
64
-            }
65
-        }
66
-        return $relations;
67
-    }
68
-
69
-    /**
70
-     * Convenience method for printing out relation many-to-many.
71
-     *
72
-     * @param string $tableName
73
-     * @param string $fieldName
74
-     * @return array
75
-     */
76
-    protected function checkRelationManyToMany($tableName, $fieldName)
77
-    {
78
-        $output = [];
79
-
80
-        $table = Tca::table($tableName);
81
-        $output[] = sprintf('* field: "%s", relation: many-to-many', $fieldName);
82
-
83
-        $foreignTable = $table->field($fieldName)->getForeignTable();
84
-        $manyToManyTable = $table->field($fieldName)->getManyToManyTable();
85
-        $foreignField = $table->field($fieldName)->getForeignField();
86
-
87
-        if (!$foreignField) {
88
-            $output[] = sprintf('  ERROR! Can not found foreign field for "%s". Perhaps missing opposite configuration?', $fieldName);
89
-        } elseif (!$foreignTable) {
90
-            $output[] = sprintf('  ERROR! Can not found foreign table for "%s". Perhaps missing opposite configuration?', $fieldName);
91
-        } elseif (!$manyToManyTable) {
92
-            $output[] = sprintf('  ERROR! Can not found relation table (MM) for "%s". Perhaps missing opposite configuration?', $fieldName);
93
-        } else {
94
-            $output[] = sprintf('  %s.%s <--> %s <--> %s.%s', $tableName, $fieldName, $manyToManyTable, $foreignTable, $foreignField);
95
-        }
96
-
97
-        $output[] = '';
98
-        return $output;
99
-    }
100
-
101
-    /**
102
-     * Convenience method for printing out relation.
103
-     *
104
-     * @param string $tableName
105
-     * @param string $fieldName
106
-     * @param string $relationType
107
-     * @return array
108
-     */
109
-    protected function checkRelationOf($tableName, $fieldName, $relationType)
110
-    {
111
-        $output = [];
112
-
113
-        $table = Tca::table($tableName);
114
-        $output[] = sprintf('* field: "%s", relation: %s', $fieldName, $relationType);
115
-
116
-        $foreignTable = $table->field($fieldName)->getForeignTable();
117
-        $foreignField = $table->field($fieldName)->getForeignField();
118
-        $output[] = sprintf('  %s.%s <--> %s.%s', $tableName, $fieldName, $foreignTable, $foreignField);
119
-        $output[] = '';
120
-
121
-        return $output;
122
-    }
37
+		foreach (Tca::grid($tableName)->getFields() as $fieldName => $configuration) {
38
+			if ($table->hasField($fieldName)) {
39
+				if ($table->field($fieldName)->hasMany()) {
40
+					if ($table->field($fieldName)->hasRelationWithCommaSeparatedValues()) {
41
+						$_relations = $this->checkRelationOf($tableName, $fieldName, 'comma separated values');
42
+						$relations = array_merge($relations, $_relations);
43
+					} elseif ($table->field($fieldName)->hasRelationManyToMany()) {
44
+						$_relations = $this->checkRelationManyToMany($tableName, $fieldName);
45
+						$relations = array_merge($relations, $_relations);
46
+					} elseif ($table->field($fieldName)->hasRelationOneToMany()) {
47
+						$_relations = $this->checkRelationOf($tableName, $fieldName, 'one-to-many');
48
+						$relations = array_merge($relations, $_relations);
49
+					} else {
50
+						$relations[] = sprintf('* field: "%s", relation: ?-to-many%s', $fieldName, $missingOppositionRelationMessage);
51
+					}
52
+					$relations[] = '';
53
+				} elseif ($table->field($fieldName)->hasOne()) {
54
+					if ($table->field($fieldName)->hasRelationOneToOne()) {
55
+						$relations[] = sprintf('* one-to-one "%s"', $fieldName);
56
+					} elseif ($table->field($fieldName)->hasRelationManyToOne()) {
57
+						$_relations = $this->checkRelationOf($tableName, $fieldName, 'many-to-one');
58
+						$relations = array_merge($relations, $_relations);
59
+					} else {
60
+						$relations[] = sprintf('* field: "%s", relation: ?-to-one%s', $fieldName, $missingOppositionRelationMessage);
61
+					}
62
+					$relations[] = '';
63
+				}
64
+			}
65
+		}
66
+		return $relations;
67
+	}
68
+
69
+	/**
70
+	 * Convenience method for printing out relation many-to-many.
71
+	 *
72
+	 * @param string $tableName
73
+	 * @param string $fieldName
74
+	 * @return array
75
+	 */
76
+	protected function checkRelationManyToMany($tableName, $fieldName)
77
+	{
78
+		$output = [];
79
+
80
+		$table = Tca::table($tableName);
81
+		$output[] = sprintf('* field: "%s", relation: many-to-many', $fieldName);
82
+
83
+		$foreignTable = $table->field($fieldName)->getForeignTable();
84
+		$manyToManyTable = $table->field($fieldName)->getManyToManyTable();
85
+		$foreignField = $table->field($fieldName)->getForeignField();
86
+
87
+		if (!$foreignField) {
88
+			$output[] = sprintf('  ERROR! Can not found foreign field for "%s". Perhaps missing opposite configuration?', $fieldName);
89
+		} elseif (!$foreignTable) {
90
+			$output[] = sprintf('  ERROR! Can not found foreign table for "%s". Perhaps missing opposite configuration?', $fieldName);
91
+		} elseif (!$manyToManyTable) {
92
+			$output[] = sprintf('  ERROR! Can not found relation table (MM) for "%s". Perhaps missing opposite configuration?', $fieldName);
93
+		} else {
94
+			$output[] = sprintf('  %s.%s <--> %s <--> %s.%s', $tableName, $fieldName, $manyToManyTable, $foreignTable, $foreignField);
95
+		}
96
+
97
+		$output[] = '';
98
+		return $output;
99
+	}
100
+
101
+	/**
102
+	 * Convenience method for printing out relation.
103
+	 *
104
+	 * @param string $tableName
105
+	 * @param string $fieldName
106
+	 * @param string $relationType
107
+	 * @return array
108
+	 */
109
+	protected function checkRelationOf($tableName, $fieldName, $relationType)
110
+	{
111
+		$output = [];
112
+
113
+		$table = Tca::table($tableName);
114
+		$output[] = sprintf('* field: "%s", relation: %s', $fieldName, $relationType);
115
+
116
+		$foreignTable = $table->field($fieldName)->getForeignTable();
117
+		$foreignField = $table->field($fieldName)->getForeignField();
118
+		$output[] = sprintf('  %s.%s <--> %s.%s', $tableName, $fieldName, $foreignTable, $foreignField);
119
+		$output[] = '';
120
+
121
+		return $output;
122
+	}
123 123
 }
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
@@ -15,45 +15,45 @@
 block discarded – undo
15 15
  */
16 16
 interface ColumnRendererInterface
17 17
 {
18
-    /**
19
-     * Render a column in the Grid.
20
-     *
21
-     * @return string
22
-     */
23
-    public function render();
24
-
25
-    /**
26
-     * @param Content $object
27
-     * @return $this
28
-     */
29
-    public function setObject($object);
30
-
31
-    /**
32
-     * @param string $fieldName
33
-     * @return $this
34
-     */
35
-    public function setFieldName($fieldName);
36
-
37
-    /**
38
-     * @param int $index
39
-     * @return $this
40
-     */
41
-    public function setRowIndex($index);
42
-
43
-    /**
44
-     * @param array $configuration
45
-     * @return $this
46
-     */
47
-    public function setFieldConfiguration($configuration);
48
-
49
-    /**
50
-     * @param array $configuration
51
-     * @return $this
52
-     */
53
-    public function setGridRendererConfiguration($configuration);
54
-
55
-    /**
56
-     * @return array
57
-     */
58
-    public function getConfiguration();
18
+	/**
19
+	 * Render a column in the Grid.
20
+	 *
21
+	 * @return string
22
+	 */
23
+	public function render();
24
+
25
+	/**
26
+	 * @param Content $object
27
+	 * @return $this
28
+	 */
29
+	public function setObject($object);
30
+
31
+	/**
32
+	 * @param string $fieldName
33
+	 * @return $this
34
+	 */
35
+	public function setFieldName($fieldName);
36
+
37
+	/**
38
+	 * @param int $index
39
+	 * @return $this
40
+	 */
41
+	public function setRowIndex($index);
42
+
43
+	/**
44
+	 * @param array $configuration
45
+	 * @return $this
46
+	 */
47
+	public function setFieldConfiguration($configuration);
48
+
49
+	/**
50
+	 * @param array $configuration
51
+	 * @return $this
52
+	 */
53
+	public function setGridRendererConfiguration($configuration);
54
+
55
+	/**
56
+	 * @return array
57
+	 */
58
+	public function getConfiguration();
59 59
 }
Please login to merge, or discard this patch.
Classes/Grid/ButtonGroupRenderer.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -16,40 +16,40 @@
 block discarded – undo
16 16
  */
17 17
 class ButtonGroupRenderer extends ColumnRendererAbstract
18 18
 {
19
-    /**
20
-     * Configure the "Button Group" Grid Renderer.
21
-     */
22
-    public function __construct()
23
-    {
24
-        $configuration = array(
25
-            'sortable' => false,
26
-            'canBeHidden' => false,
27
-            'width' => '100px',
28
-        );
29
-        parent::__construct($configuration);
30
-    }
31
-
32
-    /**
33
-     * Render the "Button Group" in the Grid, e.g. edit, delete, etc..
34
-     *
35
-     * @return string
36
-     */
37
-    public function render()
38
-    {
39
-        $components = $this->getModuleLoader()->getGridButtonsComponents();
40
-
41
-        $buttons = [];
42
-        foreach ($components as $component) {
43
-            /** @var  $view */
44
-            $view = GeneralUtility::makeInstance($component);
45
-            $buttons[] = $view->render($this->getObject());
46
-        }
47
-
48
-        $output = sprintf(
49
-            '<div class="btn-toolbar pull-right" role="toolbar" aria-label=""><div class="btn-group" role="group" aria-label="">%s</div></div>',
50
-            implode("\n", $buttons)
51
-        );
52
-
53
-        return $output;
54
-    }
19
+	/**
20
+	 * Configure the "Button Group" Grid Renderer.
21
+	 */
22
+	public function __construct()
23
+	{
24
+		$configuration = array(
25
+			'sortable' => false,
26
+			'canBeHidden' => false,
27
+			'width' => '100px',
28
+		);
29
+		parent::__construct($configuration);
30
+	}
31
+
32
+	/**
33
+	 * Render the "Button Group" in the Grid, e.g. edit, delete, etc..
34
+	 *
35
+	 * @return string
36
+	 */
37
+	public function render()
38
+	{
39
+		$components = $this->getModuleLoader()->getGridButtonsComponents();
40
+
41
+		$buttons = [];
42
+		foreach ($components as $component) {
43
+			/** @var  $view */
44
+			$view = GeneralUtility::makeInstance($component);
45
+			$buttons[] = $view->render($this->getObject());
46
+		}
47
+
48
+		$output = sprintf(
49
+			'<div class="btn-toolbar pull-right" role="toolbar" aria-label=""><div class="btn-group" role="group" aria-label="">%s</div></div>',
50
+			implode("\n", $buttons)
51
+		);
52
+
53
+		return $output;
54
+	}
55 55
 }
Please login to merge, or discard this patch.
Classes/TypeConverter/CsvToArrayConverter.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -18,35 +18,35 @@
 block discarded – undo
18 18
  */
19 19
 class CsvToArrayConverter extends AbstractTypeConverter
20 20
 {
21
-    /**
22
-     * @var array<string>
23
-     */
24
-    protected $sourceTypes = array('string');
21
+	/**
22
+	 * @var array<string>
23
+	 */
24
+	protected $sourceTypes = array('string');
25 25
 
26
-    /**
27
-     * @var string
28
-     */
29
-    protected $targetType = 'array';
26
+	/**
27
+	 * @var string
28
+	 */
29
+	protected $targetType = 'array';
30 30
 
31
-    /**
32
-     * @var integer
33
-     */
34
-    protected $priority = 1;
31
+	/**
32
+	 * @var integer
33
+	 */
34
+	protected $priority = 1;
35 35
 
36
-    /**
37
-     * Actually convert from $source to $targetType
38
-     *
39
-     * @param string $source
40
-     * @param string $targetType
41
-     * @param array $convertedChildProperties
42
-     * @param PropertyMappingConfigurationInterface $configuration
43
-     * @return array
44
-     * @throws \Exception
45
-     * @throws FileDoesNotExistException
46
-     * @api
47
-     */
48
-    public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
49
-    {
50
-        return GeneralUtility::trimExplode(',', $source, true);
51
-    }
36
+	/**
37
+	 * Actually convert from $source to $targetType
38
+	 *
39
+	 * @param string $source
40
+	 * @param string $targetType
41
+	 * @param array $convertedChildProperties
42
+	 * @param PropertyMappingConfigurationInterface $configuration
43
+	 * @return array
44
+	 * @throws \Exception
45
+	 * @throws FileDoesNotExistException
46
+	 * @api
47
+	 */
48
+	public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
49
+	{
50
+		return GeneralUtility::trimExplode(',', $source, true);
51
+	}
52 52
 }
Please login to merge, or discard this patch.
Classes/ViewHelpers/GpViewHelper.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -18,42 +18,42 @@
 block discarded – undo
18 18
  */
19 19
 class GpViewHelper extends AbstractViewHelper
20 20
 {
21
-    /**
22
-     * @return void
23
-     */
24
-    public function initializeArguments()
25
-    {
26
-        $this->registerArgument('argument', 'string', 'The argument name', true);
27
-        $this->registerArgument('encode', 'bool', 'Whether to encode the URL.', false, true);
28
-    }
29
-
30
-    /**
31
-     * Tells whether the argument exists or not.
32
-     *
33
-     * @return boolean
34
-     */
35
-    public function render()
36
-    {
37
-        $value = ''; // default value
38
-
39
-        // Merge parameters
40
-        $parameters = GeneralUtility::_GET();
41
-        $post = GeneralUtility::_POST();
42
-        ArrayUtility::mergeRecursiveWithOverrule($parameters, $post);
43
-
44
-        // Traverse argument parts and retrieve value.
45
-        $argumentParts = GeneralUtility::trimExplode('|', $this->arguments['argument']);
46
-        foreach ($argumentParts as $argumentPart) {
47
-            if (isset($parameters[$argumentPart])) {
48
-                $value = $parameters[$argumentPart];
49
-                $parameters = $value;
50
-            }
51
-        }
52
-
53
-        // Possible url encode.
54
-        if ($this->arguments['encode']) {
55
-            $value = urlencode($value);
56
-        }
57
-        return $value;
58
-    }
21
+	/**
22
+	 * @return void
23
+	 */
24
+	public function initializeArguments()
25
+	{
26
+		$this->registerArgument('argument', 'string', 'The argument name', true);
27
+		$this->registerArgument('encode', 'bool', 'Whether to encode the URL.', false, true);
28
+	}
29
+
30
+	/**
31
+	 * Tells whether the argument exists or not.
32
+	 *
33
+	 * @return boolean
34
+	 */
35
+	public function render()
36
+	{
37
+		$value = ''; // default value
38
+
39
+		// Merge parameters
40
+		$parameters = GeneralUtility::_GET();
41
+		$post = GeneralUtility::_POST();
42
+		ArrayUtility::mergeRecursiveWithOverrule($parameters, $post);
43
+
44
+		// Traverse argument parts and retrieve value.
45
+		$argumentParts = GeneralUtility::trimExplode('|', $this->arguments['argument']);
46
+		foreach ($argumentParts as $argumentPart) {
47
+			if (isset($parameters[$argumentPart])) {
48
+				$value = $parameters[$argumentPart];
49
+				$parameters = $value;
50
+			}
51
+		}
52
+
53
+		// Possible url encode.
54
+		if ($this->arguments['encode']) {
55
+			$value = urlencode($value);
56
+		}
57
+		return $value;
58
+	}
59 59
 }
Please login to merge, or discard this patch.
Classes/ViewHelpers/SpriteViewHelper.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -19,29 +19,29 @@
 block discarded – undo
19 19
  */
20 20
 class SpriteViewHelper extends AbstractViewHelper
21 21
 {
22
-    /**
23
-     * @return void
24
-     */
25
-    public function initializeArguments()
26
-    {
27
-        $this->registerArgument('name', 'string', 'the file to include', true);
28
-    }
22
+	/**
23
+	 * @return void
24
+	 */
25
+	public function initializeArguments()
26
+	{
27
+		$this->registerArgument('name', 'string', 'the file to include', true);
28
+	}
29 29
 
30
-    /**
31
-     * Returns an icon using sprites
32
-     *
33
-     * @return string
34
-     */
35
-    public function render()
36
-    {
37
-        return $this->getIconFactory()->getIcon($this->arguments['name'], Icon::SIZE_SMALL);
38
-    }
30
+	/**
31
+	 * Returns an icon using sprites
32
+	 *
33
+	 * @return string
34
+	 */
35
+	public function render()
36
+	{
37
+		return $this->getIconFactory()->getIcon($this->arguments['name'], Icon::SIZE_SMALL);
38
+	}
39 39
 
40
-    /**
41
-     * @return IconFactory|object
42
-     */
43
-    protected function getIconFactory()
44
-    {
45
-        return GeneralUtility::makeInstance(IconFactory::class);
46
-    }
40
+	/**
41
+	 * @return IconFactory|object
42
+	 */
43
+	protected function getIconFactory()
44
+	{
45
+		return GeneralUtility::makeInstance(IconFactory::class);
46
+	}
47 47
 }
Please login to merge, or discard this patch.
Classes/ViewHelpers/LanguagesViewHelper.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -17,27 +17,27 @@
 block discarded – undo
17 17
  */
18 18
 class LanguagesViewHelper extends AbstractViewHelper
19 19
 {
20
-    /**
21
-     * Returns an array of available languages.
22
-     *
23
-     * @return array
24
-     */
25
-    public function render()
26
-    {
27
-        $languages[0] = $this->getLanguageService()->getDefaultFlag();
20
+	/**
21
+	 * Returns an array of available languages.
22
+	 *
23
+	 * @return array
24
+	 */
25
+	public function render()
26
+	{
27
+		$languages[0] = $this->getLanguageService()->getDefaultFlag();
28 28
 
29
-        foreach ($this->getLanguageService()->getLanguages() as $language) {
30
-            $languages[$language['uid']] = $language['flag'];
31
-        }
29
+		foreach ($this->getLanguageService()->getLanguages() as $language) {
30
+			$languages[$language['uid']] = $language['flag'];
31
+		}
32 32
 
33
-        return $languages;
34
-    }
33
+		return $languages;
34
+	}
35 35
 
36
-    /**
37
-     * @return LanguageService|object
38
-     */
39
-    protected function getLanguageService()
40
-    {
41
-        return GeneralUtility::makeInstance(LanguageService::class);
42
-    }
36
+	/**
37
+	 * @return LanguageService|object
38
+	 */
39
+	protected function getLanguageService()
40
+	{
41
+		return GeneralUtility::makeInstance(LanguageService::class);
42
+	}
43 43
 }
Please login to merge, or discard this patch.
Classes/ViewHelpers/IsRelatedToViewHelper.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -18,46 +18,46 @@
 block discarded – undo
18 18
  */
19 19
 class IsRelatedToViewHelper extends AbstractViewHelper
20 20
 {
21
-    /**
22
-     * @return void
23
-     */
24
-    public function initializeArguments()
25
-    {
26
-        $this->registerArgument('relatedContent', Content::class, 'The related content', true);
27
-    }
28
-
29
-    /**
30
-     * Tells whether a Content is related to another content.
31
-     * The $fieldName corresponds to the relational field name
32
-     * between the first content object and the second.
33
-     *
34
-     * @return boolean
35
-     */
36
-    public function render()
37
-    {
38
-        /** @var Content $relatedContent */
39
-        $relatedContent = $this->arguments['relatedContent'];
40
-
41
-        $isChecked = false;
42
-
43
-        // Only computes whether the object is checked if one row is beeing edited.
44
-        $numberOfObjects = $this->templateVariableContainer->get('numberOfObjects');
45
-        if ($numberOfObjects === 1) {
46
-            /** @var Content $content */
47
-            $content = $this->templateVariableContainer->get('content');
48
-            $fieldName = $this->templateVariableContainer->get('fieldName');
49
-
50
-            // Build an array of user group uids
51
-            $relatedContentsIdentifiers = [];
52
-
53
-            /** @var Content $contentObject */
54
-            foreach ($content[$fieldName] as $contentObject) {
55
-                $relatedContentsIdentifiers[] = $contentObject->getUid();
56
-            }
57
-
58
-            $isChecked = in_array($relatedContent->getUid(), $relatedContentsIdentifiers, true);
59
-        }
60
-
61
-        return $isChecked;
62
-    }
21
+	/**
22
+	 * @return void
23
+	 */
24
+	public function initializeArguments()
25
+	{
26
+		$this->registerArgument('relatedContent', Content::class, 'The related content', true);
27
+	}
28
+
29
+	/**
30
+	 * Tells whether a Content is related to another content.
31
+	 * The $fieldName corresponds to the relational field name
32
+	 * between the first content object and the second.
33
+	 *
34
+	 * @return boolean
35
+	 */
36
+	public function render()
37
+	{
38
+		/** @var Content $relatedContent */
39
+		$relatedContent = $this->arguments['relatedContent'];
40
+
41
+		$isChecked = false;
42
+
43
+		// Only computes whether the object is checked if one row is beeing edited.
44
+		$numberOfObjects = $this->templateVariableContainer->get('numberOfObjects');
45
+		if ($numberOfObjects === 1) {
46
+			/** @var Content $content */
47
+			$content = $this->templateVariableContainer->get('content');
48
+			$fieldName = $this->templateVariableContainer->get('fieldName');
49
+
50
+			// Build an array of user group uids
51
+			$relatedContentsIdentifiers = [];
52
+
53
+			/** @var Content $contentObject */
54
+			foreach ($content[$fieldName] as $contentObject) {
55
+				$relatedContentsIdentifiers[] = $contentObject->getUid();
56
+			}
57
+
58
+			$isChecked = in_array($relatedContent->getUid(), $relatedContentsIdentifiers, true);
59
+		}
60
+
61
+		return $isChecked;
62
+	}
63 63
 }
Please login to merge, or discard this patch.
Classes/ViewHelpers/Content/FindOneViewHelper.php 1 patch
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -22,157 +22,157 @@
 block discarded – undo
22 22
  */
23 23
 class FindOneViewHelper extends AbstractViewHelper
24 24
 {
25
-    /**
26
-     * @return void
27
-     */
28
-    public function initializeArguments()
29
-    {
30
-        parent::initializeArguments();
31
-
32
-        $this->registerArgument('type', 'string', 'The content type', true, '');
33
-        $this->registerArgument('matches', 'array', 'Key / value array to be used as filter. The key corresponds to a field name.', false, []);
34
-        $this->registerArgument('identifier', 'int', 'The identifier of the object to be fetched.', false, 0);
35
-        $this->registerArgument('argumentName', 'string', 'The parameter name where to retrieve the identifier', false, 'tx_vidifrontend_pi1|uid');
36
-        $this->registerArgument('as', 'string', 'The alias object', false, 'object');
37
-    }
38
-
39
-    /**
40
-     * @return string Rendered string
41
-     * @api
42
-     */
43
-    public function render()
44
-    {
45
-        return static::renderStatic(
46
-            $this->arguments,
47
-            $this->buildRenderChildrenClosure(),
48
-            $this->renderingContext
49
-        );
50
-    }
51
-
52
-    /**
53
-     * @param array $arguments
54
-     * @param \Closure $renderChildrenClosure
55
-     * @param RenderingContextInterface $renderingContext
56
-     *
57
-     * @return string
58
-     */
59
-    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
60
-    {
61
-        // Fetch the object
62
-        $matches = self::computeMatches($arguments);
63
-        $matcher = self::getMatcher($arguments['type'], $matches);
64
-
65
-        $contentRepository = ContentRepositoryFactory::getInstance($arguments['type']);
66
-        $object = $contentRepository->findOneBy($matcher);
67
-
68
-        $output = '';
69
-        if ($object) {
70
-            // Render children with "as" variable.
71
-            $templateVariableContainer = $renderingContext->getTemplateVariableContainer();
72
-            $templateVariableContainer->add($arguments['as'], $object);
73
-            $output = $renderChildrenClosure();
74
-            $templateVariableContainer->remove($arguments['as']);
75
-        }
76
-
77
-        return $output;
78
-    }
79
-
80
-    /**
81
-     * @param array $arguments
82
-     * @return array
83
-     */
84
-    protected static function computeMatches(array $arguments)
85
-    {
86
-        $matches = [];
87
-
88
-        $argumentValue = self::getArgumentValue($arguments['argumentName']);
89
-        if ($argumentValue > 0) {
90
-            $matches['uid'] = $argumentValue;
91
-        }
92
-
93
-        if ($arguments['matches']) {
94
-            $matches = $arguments['matches'];
95
-        }
96
-
97
-        if ($arguments['identifier'] > 0) {
98
-            $matches['uid'] = $arguments['identifier'];
99
-        }
100
-
101
-        // We want a default value in any case.
102
-        if (!$matches) {
103
-            $matches['uid'] = 0;
104
-        }
105
-        return $matches;
106
-    }
107
-
108
-    /**
109
-     * Returns a matcher object.
110
-     *
111
-     * @param string $dataType
112
-     * @param array $matches
113
-     * @return Matcher
114
-     */
115
-    protected static function getMatcher($dataType, array $matches = [])
116
-    {
117
-        /** @var $matcher Matcher */
118
-        $matcher = GeneralUtility::makeInstance(Matcher::class, [], $dataType);
119
-
120
-        foreach ($matches as $fieldNameAndPath => $value) {
121
-            // CSV values should be considered as "in" operator in Query, otherwise "equals".
122
-            $explodedValues = GeneralUtility::trimExplode(',', $value, true);
123
-
124
-            // The matching value contains a "1,2" as example
125
-            if (count($explodedValues) > 1) {
126
-                $resolvedDataType = self::getFieldPathResolver()->getDataType($fieldNameAndPath, $dataType);
127
-                $resolvedFieldName = self::getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $dataType);
128
-
129
-                // "equals" if in presence of a relation.
130
-                // "in" if not a relation.
131
-                if (Tca::table($resolvedDataType)->field($resolvedFieldName)->hasRelation()) {
132
-                    foreach ($explodedValues as $explodedValue) {
133
-                        $matcher->equals($fieldNameAndPath, $explodedValue);
134
-                    }
135
-                } else {
136
-                    $matcher->in($fieldNameAndPath, $explodedValues);
137
-                }
138
-            } else {
139
-                $matcher->equals($fieldNameAndPath, $explodedValues[0]);
140
-            }
141
-        }
142
-
143
-        return $matcher;
144
-    }
145
-
146
-    /**
147
-     * @return FieldPathResolver
148
-     */
149
-    protected static function getFieldPathResolver()
150
-    {
151
-        return GeneralUtility::makeInstance(FieldPathResolver::class);
152
-    }
153
-
154
-    /**
155
-     * @param string $argumentName
156
-     * @return int
157
-     */
158
-    protected static function getArgumentValue($argumentName)
159
-    {
160
-        $value = ''; // default value
161
-
162
-        // Merge parameters
163
-        $parameters = GeneralUtility::_GET();
164
-        $post = GeneralUtility::_POST();
165
-        ArrayUtility::mergeRecursiveWithOverrule($parameters, $post);
166
-
167
-        // Traverse argument parts and retrieve value.
168
-        $argumentParts = GeneralUtility::trimExplode('|', $argumentName);
169
-        foreach ($argumentParts as $argumentPart) {
170
-            if (isset($parameters[$argumentPart])) {
171
-                $value = $parameters[$argumentPart];
172
-                $parameters = $value;
173
-            }
174
-        }
175
-
176
-        return (int)$value;
177
-    }
25
+	/**
26
+	 * @return void
27
+	 */
28
+	public function initializeArguments()
29
+	{
30
+		parent::initializeArguments();
31
+
32
+		$this->registerArgument('type', 'string', 'The content type', true, '');
33
+		$this->registerArgument('matches', 'array', 'Key / value array to be used as filter. The key corresponds to a field name.', false, []);
34
+		$this->registerArgument('identifier', 'int', 'The identifier of the object to be fetched.', false, 0);
35
+		$this->registerArgument('argumentName', 'string', 'The parameter name where to retrieve the identifier', false, 'tx_vidifrontend_pi1|uid');
36
+		$this->registerArgument('as', 'string', 'The alias object', false, 'object');
37
+	}
38
+
39
+	/**
40
+	 * @return string Rendered string
41
+	 * @api
42
+	 */
43
+	public function render()
44
+	{
45
+		return static::renderStatic(
46
+			$this->arguments,
47
+			$this->buildRenderChildrenClosure(),
48
+			$this->renderingContext
49
+		);
50
+	}
51
+
52
+	/**
53
+	 * @param array $arguments
54
+	 * @param \Closure $renderChildrenClosure
55
+	 * @param RenderingContextInterface $renderingContext
56
+	 *
57
+	 * @return string
58
+	 */
59
+	public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
60
+	{
61
+		// Fetch the object
62
+		$matches = self::computeMatches($arguments);
63
+		$matcher = self::getMatcher($arguments['type'], $matches);
64
+
65
+		$contentRepository = ContentRepositoryFactory::getInstance($arguments['type']);
66
+		$object = $contentRepository->findOneBy($matcher);
67
+
68
+		$output = '';
69
+		if ($object) {
70
+			// Render children with "as" variable.
71
+			$templateVariableContainer = $renderingContext->getTemplateVariableContainer();
72
+			$templateVariableContainer->add($arguments['as'], $object);
73
+			$output = $renderChildrenClosure();
74
+			$templateVariableContainer->remove($arguments['as']);
75
+		}
76
+
77
+		return $output;
78
+	}
79
+
80
+	/**
81
+	 * @param array $arguments
82
+	 * @return array
83
+	 */
84
+	protected static function computeMatches(array $arguments)
85
+	{
86
+		$matches = [];
87
+
88
+		$argumentValue = self::getArgumentValue($arguments['argumentName']);
89
+		if ($argumentValue > 0) {
90
+			$matches['uid'] = $argumentValue;
91
+		}
92
+
93
+		if ($arguments['matches']) {
94
+			$matches = $arguments['matches'];
95
+		}
96
+
97
+		if ($arguments['identifier'] > 0) {
98
+			$matches['uid'] = $arguments['identifier'];
99
+		}
100
+
101
+		// We want a default value in any case.
102
+		if (!$matches) {
103
+			$matches['uid'] = 0;
104
+		}
105
+		return $matches;
106
+	}
107
+
108
+	/**
109
+	 * Returns a matcher object.
110
+	 *
111
+	 * @param string $dataType
112
+	 * @param array $matches
113
+	 * @return Matcher
114
+	 */
115
+	protected static function getMatcher($dataType, array $matches = [])
116
+	{
117
+		/** @var $matcher Matcher */
118
+		$matcher = GeneralUtility::makeInstance(Matcher::class, [], $dataType);
119
+
120
+		foreach ($matches as $fieldNameAndPath => $value) {
121
+			// CSV values should be considered as "in" operator in Query, otherwise "equals".
122
+			$explodedValues = GeneralUtility::trimExplode(',', $value, true);
123
+
124
+			// The matching value contains a "1,2" as example
125
+			if (count($explodedValues) > 1) {
126
+				$resolvedDataType = self::getFieldPathResolver()->getDataType($fieldNameAndPath, $dataType);
127
+				$resolvedFieldName = self::getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $dataType);
128
+
129
+				// "equals" if in presence of a relation.
130
+				// "in" if not a relation.
131
+				if (Tca::table($resolvedDataType)->field($resolvedFieldName)->hasRelation()) {
132
+					foreach ($explodedValues as $explodedValue) {
133
+						$matcher->equals($fieldNameAndPath, $explodedValue);
134
+					}
135
+				} else {
136
+					$matcher->in($fieldNameAndPath, $explodedValues);
137
+				}
138
+			} else {
139
+				$matcher->equals($fieldNameAndPath, $explodedValues[0]);
140
+			}
141
+		}
142
+
143
+		return $matcher;
144
+	}
145
+
146
+	/**
147
+	 * @return FieldPathResolver
148
+	 */
149
+	protected static function getFieldPathResolver()
150
+	{
151
+		return GeneralUtility::makeInstance(FieldPathResolver::class);
152
+	}
153
+
154
+	/**
155
+	 * @param string $argumentName
156
+	 * @return int
157
+	 */
158
+	protected static function getArgumentValue($argumentName)
159
+	{
160
+		$value = ''; // default value
161
+
162
+		// Merge parameters
163
+		$parameters = GeneralUtility::_GET();
164
+		$post = GeneralUtility::_POST();
165
+		ArrayUtility::mergeRecursiveWithOverrule($parameters, $post);
166
+
167
+		// Traverse argument parts and retrieve value.
168
+		$argumentParts = GeneralUtility::trimExplode('|', $argumentName);
169
+		foreach ($argumentParts as $argumentPart) {
170
+			if (isset($parameters[$argumentPart])) {
171
+				$value = $parameters[$argumentPart];
172
+				$parameters = $value;
173
+			}
174
+		}
175
+
176
+		return (int)$value;
177
+	}
178 178
 }
Please login to merge, or discard this patch.