| Conditions | 16 |
| Paths | 8320 |
| Total Lines | 106 |
| Code Lines | 81 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 53 | public function render() |
||
| 54 | { |
||
| 55 | $resultArray = $this->initializeResultArray(); |
||
| 56 | $parameterArray = $this->data['parameterArray']; |
||
| 57 | $formElementId = md5($parameterArray['itemFormElName']); |
||
| 58 | |||
| 59 | // Field configuration from TCA: |
||
| 60 | $config = $parameterArray['fieldConf']['config']; |
||
| 61 | $readOnly = !empty($config['readOnly']) ? 'true' : 'false'; |
||
| 62 | $exclusiveKeys = !empty($config['exclusiveKeys']) ? $config['exclusiveKeys'] : ''; |
||
| 63 | $exclusiveKeys = $exclusiveKeys . ','; |
||
| 64 | $appearance = !empty($config['treeConfig']['appearance']) ? $config['treeConfig']['appearance'] : []; |
||
| 65 | $expanded = !empty($appearance['expandAll']); |
||
| 66 | $showHeader = !empty($appearance['showHeader']); |
||
| 67 | if (isset($config['size']) && (int)$config['size'] > 0) { |
||
| 68 | $height = max($this->minItemsToShow, (int)$config['size']); |
||
| 69 | } else { |
||
| 70 | $height = $this->itemsToShow; |
||
| 71 | } |
||
| 72 | $heightInPx = $height * $this->itemHeight; |
||
| 73 | $treeWrapperId = 'tree_' . $formElementId; |
||
| 74 | |||
| 75 | $fieldName = $this->data['fieldName']; |
||
| 76 | |||
| 77 | $dataStructureIdentifier = ''; |
||
| 78 | $flexFormSheetName = ''; |
||
| 79 | $flexFormFieldName = ''; |
||
| 80 | $flexFormContainerName = ''; |
||
| 81 | $flexFormContainerIdentifier = ''; |
||
| 82 | $flexFormContainerFieldName = ''; |
||
| 83 | $flexFormSectionContainerIsNew = false; |
||
| 84 | if ($this->data['processedTca']['columns'][$fieldName]['config']['type'] === 'flex') { |
||
| 85 | $dataStructureIdentifier = $this->data['processedTca']['columns'][$fieldName]['config']['dataStructureIdentifier']; |
||
| 86 | if (isset($this->data['flexFormSheetName'])) { |
||
| 87 | $flexFormSheetName = $this->data['flexFormSheetName']; |
||
| 88 | } |
||
| 89 | if (isset($this->data['flexFormFieldName'])) { |
||
| 90 | $flexFormFieldName = $this->data['flexFormFieldName']; |
||
| 91 | } |
||
| 92 | if (isset($this->data['flexFormContainerName'])) { |
||
| 93 | $flexFormContainerName = $this->data['flexFormContainerName']; |
||
| 94 | } |
||
| 95 | if (isset($this->data['flexFormContainerFieldName'])) { |
||
| 96 | $flexFormContainerFieldName = $this->data['flexFormContainerFieldName']; |
||
| 97 | } |
||
| 98 | if (isset($this->data['flexFormContainerIdentifier'])) { |
||
| 99 | $flexFormContainerIdentifier = $this->data['flexFormContainerIdentifier']; |
||
| 100 | } |
||
| 101 | // Add a flag this is a tree in a new flex section container element. This is needed to initialize |
||
| 102 | // the databaseRow with this container again so the tree data provider is able to calculate tree items. |
||
| 103 | if (!empty($this->data['flexSectionContainerPreparation'])) { |
||
| 104 | $flexFormSectionContainerIsNew = true; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | $fieldInformationResult = $this->renderFieldInformation(); |
||
| 109 | $fieldInformationHtml = $fieldInformationResult['html']; |
||
| 110 | $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $fieldInformationResult, false); |
||
| 111 | |||
| 112 | $html = []; |
||
| 113 | $html[] = '<div class="formengine-field-item t3js-formengine-field-item">'; |
||
| 114 | if (!$readOnly) { |
||
| 115 | $html[] = $fieldInformationHtml; |
||
| 116 | } |
||
| 117 | $html[] = '<div class="form-control-wrap">'; |
||
| 118 | $html[] = '<div class="typo3-tceforms-tree">'; |
||
| 119 | $html[] = '<input class="treeRecord" type="hidden"'; |
||
| 120 | $html[] = ' data-formengine-validation-rules="' . htmlspecialchars($this->getValidationDataAsJsonString($config)) . '"'; |
||
| 121 | $html[] = ' data-relatedfieldname="' . htmlspecialchars($parameterArray['itemFormElName']) . '"'; |
||
| 122 | $html[] = ' data-tablename="' . htmlspecialchars($this->data['tableName']) . '"'; |
||
| 123 | $html[] = ' data-fieldname="' . htmlspecialchars($this->data['fieldName']) . '"'; |
||
| 124 | $html[] = ' data-uid="' . (int)$this->data['vanillaUid'] . '"'; |
||
| 125 | $html[] = ' data-recordtypevalue="' . htmlspecialchars($this->data['recordTypeValue']) . '"'; |
||
| 126 | $html[] = ' data-datastructureidentifier="' . htmlspecialchars($dataStructureIdentifier) . '"'; |
||
| 127 | $html[] = ' data-flexformsheetname="' . htmlspecialchars($flexFormSheetName) . '"'; |
||
| 128 | $html[] = ' data-flexformfieldname="' . htmlspecialchars($flexFormFieldName) . '"'; |
||
| 129 | $html[] = ' data-flexformcontainername="' . htmlspecialchars($flexFormContainerName) . '"'; |
||
| 130 | $html[] = ' data-flexformcontaineridentifier="' . htmlspecialchars($flexFormContainerIdentifier) . '"'; |
||
| 131 | $html[] = ' data-flexformcontainerfieldname="' . htmlspecialchars($flexFormContainerFieldName) . '"'; |
||
| 132 | $html[] = ' data-flexformsectioncontainerisnew="' . htmlspecialchars($flexFormSectionContainerIsNew) . '"'; |
||
| 133 | $html[] = ' data-command="' . htmlspecialchars($this->data['command']) . '"'; |
||
| 134 | $html[] = ' data-read-only="' . $readOnly . '"'; |
||
| 135 | $html[] = ' data-tree-exclusive-keys="' . htmlspecialchars($exclusiveKeys) . '"'; |
||
| 136 | $html[] = ' data-tree-expand-up-to-level="' . ($expanded ? '999' : '1') . '"'; |
||
| 137 | $html[] = ' data-tree-show-toolbar="' . $showHeader . '"'; |
||
| 138 | $html[] = ' name="' . htmlspecialchars($parameterArray['itemFormElName']) . '"'; |
||
| 139 | $html[] = ' id="treeinput' . $formElementId . '"'; |
||
| 140 | $html[] = ' value=""'; |
||
| 141 | $html[] = '/>'; |
||
| 142 | $html[] = '</div>'; |
||
| 143 | $html[] = '<div id="' . $treeWrapperId . '" class="svg-tree-wrapper" style="height: ' . $heightInPx . 'px;"></div>'; |
||
| 144 | $html[] = '<script type="text/javascript">var ' . $treeWrapperId . ' = ' . $this->getTreeOnChangeJs() . '</script>'; |
||
| 145 | $html[] = '</div>'; |
||
| 146 | $html[] = '</div>'; |
||
| 147 | |||
| 148 | $resultArray['html'] = implode(LF, $html); |
||
| 149 | |||
| 150 | // add necessary labels for tree header |
||
| 151 | if ($showHeader) { |
||
| 152 | $resultArray['additionalInlineLanguageLabelFiles'][] = 'EXT:core/Resources/Private/Language/locallang_csh_corebe.xlf'; |
||
| 153 | } |
||
| 154 | $resultArray['requireJsModules']['selectTreeElement'] = [ |
||
| 155 | 'TYPO3/CMS/Backend/FormEngine/Element/SelectTreeElement' => 'function (SelectTreeElement) { SelectTreeElement.initialize(); }' |
||
| 156 | ]; |
||
| 157 | |||
| 158 | return $resultArray; |
||
| 159 | } |
||
| 174 |