closeWindow = sprintf( '', GeneralUtility::implodeAttributes([ 'src' => (string)PathUtility::getSystemResourceUri(self::JAVASCRIPT_HELPER, $request), 'data-action' => 'window.close', ], true) ); $parsedBody = $request->getParsedBody(); $queryParams = $request->getQueryParams(); $this->P = $parsedBody['P'] ?? $queryParams['P'] ?? []; // Used for the return URL to FormEngine so that we can close the window. $this->doClose = $parsedBody['doClose'] ?? $queryParams['doClose'] ?? 0; return $this->processRequest(); } /** * Process request function * Makes a header-location redirect to an edit form IF POSSIBLE from the passed data - otherwise the window will * just close. */ protected function processRequest(): ResponseInterface { if ($this->doClose) { return new HtmlResponse($this->closeWindow); } // Initialize: $table = $this->P['table']; $field = $this->P['field']; $schema = $this->tcaSchemaFactory->get($table); if (empty($this->P['flexFormDataStructureIdentifier'])) { // If there is not flex data structure identifier, field config is found in globals $config = $schema->getField($field)->getConfiguration(); } else { // If there is a flex data structure identifier, parse that data structure and // fetch config defined by given flex path $dataStructure = $this->flexFormTools->parseDataStructureByIdentifier($this->P['flexFormDataStructureIdentifier'], $schema); $config = ArrayUtility::getValueByPath($dataStructure, $this->P['flexFormDataStructurePath']); if (!is_array($config)) { throw new \RuntimeException( 'Something went wrong finding flex path ' . $this->P['flexFormDataStructurePath'] . ' in data structure identified by ' . $this->P['flexFormDataStructureIdentifier'], 1537356346 ); } } $urlParameters = [ 'returnUrl' => (string)$this->uriBuilder->buildUriFromRoute('wizard_edit', ['doClose' => 1]), ]; // Detecting the various allowed field type setups and acting accordingly. if ($config['type'] === 'select' && !($config['MM'] ?? false) && (int)($config['maxitems'] ?? 0) <= 1 && MathUtility::canBeInterpretedAsInteger($this->P['currentValue']) && $this->P['currentValue'] && $config['foreign_table'] ) { // SINGLE value $urlParameters['edit[' . $config['foreign_table'] . '][' . $this->P['currentValue'] . ']'] = 'edit'; // Redirect to FormEngine // Note: no 'module' context here, since we're opening in a popup $url = $this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters); return new RedirectResponse($url); } if (!empty($config['type']) && !empty($this->P['currentSelectedValues']) && ( $config['type'] === 'select' && !empty($config['foreign_table']) || $config['type'] === 'group' && !empty($config['allowed']) ) ) { // MULTIPLE VALUES: // Init settings: $allowedTables = $config['type'] === 'group' ? $config['allowed'] : $config['foreign_table']; // Selecting selected values into an array: $relationHandler = GeneralUtility::makeInstance(RelationHandler::class); $relationHandler->start($this->P['currentSelectedValues'], $allowedTables); $value = $relationHandler->getValueArray(true); // Traverse that array and make parameters for FormEngine foreach ($value as $rec) { $recTableUidParts = GeneralUtility::revExplode('_', $rec, 2); $urlParameters['edit[' . $recTableUidParts[0] . '][' . $recTableUidParts[1] . ']'] = 'edit'; } // Redirect to FormEngine $url = $this->uriBuilder->buildUriFromRoute('record_edit', $urlParameters); return new RedirectResponse($url); } return new HtmlResponse($this->closeWindow); } }