/** * Checks if a key for a field is available * * @param array $params Array of parameters from the AJAX interface, not * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler * @author Benjamin Butschell <*****@*****.**> * @return void */ public function checkFieldKey($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) { $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); $this->storageRepository = $this->objectManager->get("MASK\\Mask\\Domain\\Repository\\StorageRepository"); // Get parameters, is there a better way? $params is not used yet $fieldKey = $_GET["key"]; if ($_GET["table"]) { $table = $_GET["table"]; } else { $table = "tt_content"; } // check if fieldKey is available for this table $isAvailable = TRUE; if ($this->storageRepository->loadField($table, $fieldKey)) { $isAvailable = FALSE; } // return infos as json $ajaxObj->setContentFormat("plain"); $ajaxObj->addContent("isAvailable", json_encode($isAvailable)); }
/** * Returns the formType of a field in an element * * @param string $fieldKey Key if Field * @param string $elementKey Key of Element * @param string $type elementtype * @return string formType * @author Benjamin Butschell <*****@*****.**> */ public function getFormType($fieldKey, $elementKey = "", $type = "tt_content") { $this->storageRepository = $this->objectManager->get("MASK\\Mask\\Domain\\Repository\\StorageRepository"); $formType = "String"; // Load element and TCA of field if ($elementKey) { $element = $this->storageRepository->loadElement($type, $elementKey); } // load tca for field from $GLOBALS $tca = $GLOBALS["TCA"][$type]["columns"][$fieldKey]; if (!$tca["config"]) { $tca = $GLOBALS["TCA"][$type]["columns"]["tx_mask_" . $fieldKey]; } if (!$tca["config"]) { $tca = $element["tca"][$fieldKey]; } // if field is in inline table, load tca from json if (!in_array($type, array("tt_content", "pages"))) { $tca = $this->storageRepository->loadField($type, $fieldKey); if (!$tca["config"]) { $tca = $this->storageRepository->loadField($type, "tx_mask_" . $fieldKey); } } $tcaType = $tca["config"]["type"]; $evals = explode(",", $tca["config"]["eval"]); if ($tca["options"] == "file") { $formType = "File"; } // And decide via different tca settings which formType it is switch ($tcaType) { case "input": $formType = "String"; if (array_search(strtolower("int"), $evals) !== FALSE) { $formType = "Integer"; } else { if (array_search(strtolower("double2"), $evals) !== FALSE) { $formType = "Float"; } else { if (array_search(strtolower("date"), $evals) !== FALSE) { $formType = "Date"; } else { if (array_search(strtolower("datetime"), $evals) !== FALSE) { $formType = "Datetime"; } else { if (is_array($tca["config"]["wizards"]["link"])) { $formType = "Link"; } else { $formType = "String"; } } } } } break; case "text": $formType = "Text"; if (in_array($type, array("tt_content", "pages"))) { if ($elementKey) { $fieldNumberKey = -1; if (is_array($element["columns"])) { foreach ($element["columns"] as $numberKey => $column) { if ($column == $fieldKey) { $fieldNumberKey = $numberKey; } } } if ($fieldNumberKey >= 0) { $option = $element["options"][$fieldNumberKey]; if ($option == "rte") { $formType = "Richtext"; } else { $formType = "Text"; } } } else { $formType = "Text"; } } else { if ($tca["rte"]) { $formType = "Richtext"; } else { $formType = "Text"; } } break; case "check": $formType = "Check"; break; case "radio": $formType = "Radio"; break; case "select": $formType = "Select"; break; case "group": break; case "none": break; case "passthrough": break; case "user": break; case "flex": break; case "inline": $formType = "Inline"; if ($tca["config"]["foreign_table"] == "sys_file_reference") { $formType = "File"; } else { $formType = "Inline"; } break; default: break; } return $formType; }