/** * Fetch the files given an object assuming * * @param $propertyName * @param Content $object * @return File[] */ protected function findByFileReference($propertyName, Content $object) { $fileField = 'uid_local'; $tableName = 'sys_file_reference'; $clause = sprintf('tablenames = "%s" %s AND fieldname = "%s" AND uid_foreign = %s', $object->getDataType(), $this->getWhereClauseForEnabledFields($tableName), GeneralUtility::camelCaseToLowerCaseUnderscored($propertyName), $object->getUid()); $rows = $this->getDatabaseConnection()->exec_SELECTgetRows($fileField, $tableName, $clause); // Build array of Files $files = array(); foreach ($rows as $row) { $files[] = ResourceFactory::getInstance()->getFileObject($row[$fileField]); } return $files; }
/** * @param Content $object * @param string $fieldNameAndPath * @return string */ public function getDataType(Content $object, $fieldNameAndPath) { // Important to notice the field name can contains a path, e.g. metadata.title and must be sanitized. $relationalFieldName = $this->getFieldPathResolver()->stripFieldName($fieldNameAndPath); // ex: metadata.title -> metadata // Handle case when field name leads to a relation. if ($object[$relationalFieldName] instanceof Content) { $resolvedDataType = $object[$relationalFieldName]->getDataType(); } else { $resolvedDataType = $object->getDataType(); } return $resolvedDataType; }
/** * @param string|Content $tableNameOrContentObject * @return $this */ public function of($tableNameOrContentObject) { // Resolve the table name. self::$currentTable = $tableNameOrContentObject instanceof Content ? $tableNameOrContentObject->getDataType() : $tableNameOrContentObject; return $this; }
/** * Removes an object from this repository. * * @param Content $content * @return boolean */ public function remove($content) { $dataType = $content->getDataType(); $handler = $this->getDataHandlerFactory()->action(ProcessAction::REMOVE)->forType($dataType)->getDataHandler(); $handlerResult = $handler->processRemove($content); $this->errorMessages = $handler->getErrorMessages(); return $handlerResult; }
/** * @param Content $object * @return string */ protected function getEditParameterName(Content $object) { return sprintf('edit[%s][%s]', $object->getDataType(), $object->getUid()); }
/** * Returns the title of a content object. * * @param Content $content * @return string */ public function render(Content $content) { $table = Tca::table($content->getDataType()); return $content[$table->getLabelField()]; }
/** * Check whether the given object is meant to include files in some fields. * * @param Content $object * @return void */ protected function checkWhetherObjectMayIncludeFiles(Content $object) { if (Tca::grid($object->getDataType())->areFilesIncludedInExport()) { foreach ($object->toFields() as $fieldName) { $fieldType = Tca::table($object->getDataType())->field($fieldName)->getType(); if ($fieldType === FieldType::FILE) { $this->fileTypeProperties[] = GeneralUtility::camelCaseToLowerCaseUnderscored($fieldName); } } } }
/** * Process Content with action "localize". * * @param Content $content * @param int $language * @return bool */ public function processLocalize(Content $content, $language) { $command[$content->getDataType()][$content->getUid()]['localize'] = $language; $dataHandler = $this->getDataHandler(); $dataHandler->start(array(), $command); $dataHandler->process_datamap(); $dataHandler->process_cmdmap(); $this->errorMessages = $dataHandler->errorLog; // Returns TRUE is log does not contain errors. return empty($dataHandler->errorLog); }
/** * Renders a "delete" button to be placed in the grid. * * @param Content $object * @return string */ public function render(Content $object = NULL) { $labelField = Tca::table($object->getDataType())->getLabelField(); $label = $object[$labelField] ? $object[$labelField] : $object->getUid(); return $this->makeLinkButton()->setHref($this->getDeleteUri($object))->setDataAttributes(['uid' => $object->getUid(), 'toggle' => 'tooltip', 'label' => $label])->setClasses('btn-delete')->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:delete'))->setIcon($this->getIconFactory()->getIcon('actions-edit-delete', Icon::SIZE_SMALL))->render(); }
/** * Process the value * * @todo implement me as a processor chain to be cleaner implementation wise. Look out at the performance however! * e.g DefaultValueGridProcessor, TextAreaGridProcessor, ... * * @param string $value * @param \Fab\Vidi\Domain\Model\Content $object * @param string $fieldNameAndPath * @return string */ protected function processValue($value, Content $object, $fieldNameAndPath) { // Set default value if $field name correspond to the label of the table $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); if (Tca::table($object->getDataType())->getLabelField() === $fieldName && empty($value)) { $value = sprintf('[%s]', $this->getLabelService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title', 1)); } // Sanitize the value in case of "select" or "radio button". if (is_scalar($value)) { $fieldType = Tca::table($object->getDataType())->field($fieldNameAndPath)->getType(); if ($fieldType !== FieldType::TEXTAREA) { $value = htmlspecialchars($value); } elseif ($fieldType === FieldType::TEXTAREA && !$this->isClean($value)) { $value = htmlspecialchars($value); // Avoid bad surprise, converts characters to HTML. } elseif ($fieldType === FieldType::TEXTAREA && !$this->hasHtml($value)) { $value = nl2br($value); } } return $value; }
/** * Returns a "table" service instance ("ctrl" part of the TCA). * * @param string|Content $tableNameOrContentObject * @return \Fab\Vidi\Tca\TableService */ public static function table($tableNameOrContentObject = '') { $tableName = $tableNameOrContentObject instanceof Content ? $tableNameOrContentObject->getDataType() : $tableNameOrContentObject; return self::getService($tableName, self::TYPE_TABLE); }