/** * @param string $fieldName * @throws \Exception * @return \Fab\Vidi\Tca\FieldService */ public function field($fieldName) { // In case field contains items.tx_table for field type "group" $compositeField = ''; if (strpos($fieldName, '.') !== FALSE) { $compositeField = $fieldName; $fieldParts = explode('.', $compositeField, 2); $fieldName = $fieldParts[0]; // Special when field has been instantiated without the field name and path. if (!empty($this->instances[$fieldName])) { /** @var FieldService $field */ $field = $this->instances[$fieldName]; $field->setCompositeField($compositeField); } } // True for system fields such as uid, pid that don't necessarily have a TCA. if (empty($this->columnTca[$fieldName]) && in_array($fieldName, Tca::getSystemFields())) { $this->columnTca[$fieldName] = array(); } elseif (empty($this->columnTca[$fieldName])) { $message = sprintf('Does the field really exist? No TCA entry found for field "%s" for table "%s"', $fieldName, $this->tableName); throw new \Exception($message, 1385554481); } if (empty($this->instances[$fieldName])) { $instance = GeneralUtility::makeInstance('Fab\\Vidi\\Tca\\FieldService', $fieldName, $this->columnTca[$fieldName], $this->tableName, $compositeField); $this->instances[$fieldName] = $instance; } return $this->instances[$fieldName]; }
/** * Returns an array containing column names for the Grid. * * @return array */ public function getAllFields() { // Cache this operation since it can take some time. if (is_null($this->allFields)) { $fields = is_array($this->tca['columns']) ? $this->tca['columns'] : array(); $gridFieldNames = array_keys($fields); // Fetch all fields of the TCA and merge it back to the fields configured for Grid. $tableFieldNames = Tca::table($this->tableName)->getFields(); // Just remove system fields from the Grid. foreach ($tableFieldNames as $key => $fieldName) { if (in_array($fieldName, Tca::getSystemFields())) { unset($tableFieldNames[$key]); } } $additionalFields = array_diff($tableFieldNames, $gridFieldNames); if (!empty($additionalFields)) { // Pop out last element of the key // Idea is to place new un-configured columns in between. By default, they will be hidden. end($fields); $lastColumnKey = key($fields); $lastColumn = array_pop($fields); // Feed up the grid fields with un configured elements foreach ($additionalFields as $additionalField) { $fields[$additionalField] = array('visible' => FALSE); // Try to guess the format of the field. $fieldType = Tca::table($this->tableName)->field($additionalField)->getType(); if ($fieldType === FieldType::DATE) { $fields[$additionalField]['format'] = 'Fab\\Vidi\\Formatter\\Date'; } elseif ($fieldType === FieldType::DATETIME) { $fields[$additionalField]['format'] = 'Fab\\Vidi\\Formatter\\Datetime'; } } $fields[$lastColumnKey] = $lastColumn; } $this->allFields = $fields; } return $this->allFields; }
/** * Tells whether the field is considered as system field, e.g. uid, crdate, tstamp, etc... * * @return bool */ public function isSystem() { return in_array($this->fieldName, Tca::getSystemFields()); }