/** * Return all resources that are already stored in the file system. This includes * file references that are already persisted and files that were uploaded, but * are not persisted yet because a mapping/validation error occured. * * @return array<\TYPO3\CMS\Extbase\Domain\Model\FileReference> */ protected function getUploadedResources() { // TODO: If a mapping error occurs and Extbase redirects to the edit action, // the properties of the form object still contain the mapped values, not // the persisted ones! So if you unceck an image in the Multiupload.Delete // viewhelper, it disappears from the property and we lose it here as well. // This means: we need another way to remember which file references were // rendered the first time somewhere ... $resources = $this->getPropertyValue(); if ($resources instanceof \TYPO3\CMS\Extbase\Persistence\ObjectStorage || $resources instanceof \TYPO3\CMS\Extbase\Persistence\QueryResultInterface) { $resources = $resources->toArray(); } else { if (!is_array($resources)) { $resources = array(); } } if ($this->configurationManager->isFeatureEnabled('rewrittenPropertyMapper') && $this->hasMappingErrorOccurred()) { foreach ($this->getLastSubmittedFormData() as $lastSubmittedRecord) { $convertedResource = $this->propertyMapper->convert($lastSubmittedRecord, 'TYPO3\\CMS\\Extbase\\Domain\\Model\\FileReference'); if ($convertedResource !== NULL && !in_array($convertedResource, $resources)) { $resources[] = $convertedResource; } } } return $resources; }
/** * Return a previously uploaded resource. * Return NULL if errors occurred during property mapping for this property. * * @return \TYPO3\CMS\Extbase\Domain\Model\FileReference */ protected function getUploadedResource() { if ($this->getMappingResultsForProperty()->hasErrors()) { return NULL; } $resource = $this->getValue(FALSE); if ($resource instanceof \TYPO3\CMS\Extbase\Domain\Model\FileReference) { return $resource; } return $this->propertyMapper->convert($resource, 'TYPO3\\CMS\\Extbase\\Domain\\Model\\FileReference'); }
/** * Return a previously uploaded resource. * Return NULL if errors occurred during property mapping for this property. * * @return \TYPO3\CMS\Extbase\Domain\Model\FileReference */ protected function getUploadedResource() { if ($this->getMappingResultsForProperty()->hasErrors()) { return null; } $resource = $this->getValue(false); if ($resource instanceof \TYPO3\CMS\Extbase\Domain\Model\FileReference) { return $resource; } return $this->propertyMapper->convert($resource, FileReference::class); }
/** * Sets the value of this argument. * * @param mixed $rawValue The value of this argument * @return \TYPO3\CMS\Extbase\Mvc\Controller\Argument * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentValueException if the argument is not a valid object of type $dataType */ public function setValue($rawValue) { if ($this->configurationManager->isFeatureEnabled('rewrittenPropertyMapper')) { if ($rawValue === NULL) { $this->value = NULL; return $this; } if (is_object($rawValue) && $rawValue instanceof $this->dataType) { $this->value = $rawValue; return $this; } $this->value = $this->propertyMapper->convert($rawValue, $this->dataType, $this->propertyMappingConfiguration); $this->validationResults = $this->propertyMapper->getMessages(); if ($this->validator !== NULL) { // TODO: Validation API has also changed!!! $validationMessages = $this->validator->validate($this->value); $this->validationResults->merge($validationMessages); } return $this; } else { if ($rawValue === NULL || is_object($rawValue) && $rawValue instanceof $this->dataType) { $this->value = $rawValue; } else { $this->value = $this->transformValue($rawValue); } return $this; } }
/** * action update * * @param \Aijko\SharepointConnector\Domain\Model\Mapping\Lists $list * @param array $attributeData * @dontvalidate $mappingLists * @dontvalidate $attributeData * @return void */ public function updateAction(\Aijko\SharepointConnector\Domain\Model\Mapping\Lists $list, array $attributeData) { $attributesArray = array(); if (count($attributeData['available']) > 0) { foreach ($attributeData['available'] as $key => $attributes) { $attributesArray[] = $attributes; $mappingAttribute = $this->propertyMapper->convert($attributes, 'Aijko\\SharepointConnector\\Domain\\Model\\Mapping\\Attribute'); $this->mappingAttributeRepository->update($mappingAttribute); } } if (count($attributeData['new']) > 0) { foreach ($attributeData['new'] as $key => $attributes) { if (!$attributes['activated']) { continue; } unset($attributes['activated']); $attributesArray[] = $attributes; $mappingAttribute = $this->propertyMapper->convert($attributes, 'Aijko\\SharepointConnector\\Domain\\Model\\Mapping\\Attribute'); $list->addAttribute($mappingAttribute); } } $this->mappingListsRepository->update($list); $this->flashMessageContainer->add('ListMapping "' . $list->getSharepointListTitle() . '" was updated.'); Logger::info('MappingController:updateAction', array('listMappingUid' => $list->getUid(), 'sharepointListIdentifier' => $list->getSharepointListIdentifier(), 'typo3ListTitle' => $list->getTypo3ListTitle(), 'attributes' => json_encode($attributesArray))); $this->redirect('edit', NULL, NULL, array('list' => $list)); }
/** * Sets the value of this argument. * * @param mixed $rawValue The value of this argument * * @return \TYPO3\CMS\Extbase\Mvc\Controller\Argument * @throws \TYPO3\CMS\Extbase\Property\Exception */ public function setValue($rawValue) { if ($rawValue === null) { $this->value = null; return $this; } if (is_object($rawValue) && $rawValue instanceof $this->dataType) { $this->value = $rawValue; return $this; } try { $this->value = $this->propertyMapper->convert($rawValue, $this->dataType, $this->propertyMappingConfiguration); } catch (TargetNotFoundException $e) { // for optional arguments no exeption is thrown. if ($this->isRequired()) { throw $e; } } $this->validationResults = $this->propertyMapper->getMessages(); if ($this->validator !== null) { // @todo Validation API has also changed!!! $validationMessages = $this->validator->validate($this->value); $this->validationResults->merge($validationMessages); } return $this; }
/** * Sets the value of this argument. * * @param mixed $rawValue The value of this argument * @return \TYPO3\CMS\Extbase\Mvc\Controller\Argument * @throws \TYPO3\CMS\Extbase\Property\Exception */ public function setValue($rawValue) { if ($this->configurationManager->isFeatureEnabled('rewrittenPropertyMapper')) { if ($rawValue === NULL) { $this->value = NULL; return $this; } if (is_object($rawValue) && $rawValue instanceof $this->dataType) { $this->value = $rawValue; return $this; } try { $this->value = $this->propertyMapper->convert($rawValue, $this->dataType, $this->propertyMappingConfiguration); } catch (TargetNotFoundException $e) { // for optional arguments no exeption is thrown. if ($this->isRequired()) { throw $e; } } $this->validationResults = $this->propertyMapper->getMessages(); if ($this->validator !== NULL) { // TODO: Validation API has also changed!!! $validationMessages = $this->validator->validate($this->value); $this->validationResults->merge($validationMessages); } return $this; } else { if ($rawValue === NULL || is_object($rawValue) && $rawValue instanceof $this->dataType) { $this->value = $rawValue; } else { $this->value = $this->transformValue($rawValue); } return $this; } }
/** * Builds a Page from a TYPO3.CMS `pages` associative record array * * @param array $data * * @return Page * * @throws \InvalidArgumentException */ public function createFromAssociativeArray(array $data) { $identifier = Identifier::fromString($data['uid']); $data['_pageId'] = $identifier; try { $data['_teaserImage'] = $this->teaserImageResourceFactory->createFromPageIdentifier($identifier); } catch (\InvalidArgumentException $exc) { } $page = $this->mapper->convert($data, Page::class, $this->mapperConfiguration); return $page; }
/** * Setup */ public function setUp() { parent::setUp(); $this->propertyManager = new \TYPO3\CMS\Extbase\Property\PropertyMapper(); $configurationBuilder = new \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationBuilder(); $this->inject($this->propertyManager, 'configurationBuilder', $configurationBuilder); $this->inject($this->propertyManager, 'objectManager', $this->objectManager); $this->propertyManager->initializeObject(); $dummyList = new \stdClass(); $dummyList->id = '{0344CAA0-94D5-40DE-A6EC-0D551BAC869D}'; $dummyList->title = 'Kontakte'; $this->fixtureList[] = $dummyList; $dummyList = new \stdClass(); $dummyList->id = '{BF306B2A-CBB7-4284-A17C-BEC46F3FE6C1}'; $dummyList->title = 'Artikel'; $this->fixtureList[] = $dummyList; $this->sharepointHandler = $this->getMockBuilder('Thybag\\SharePointAPI')->disableOriginalConstructor()->getMock(); $this->sharepointHandler->expects($this->any())->method('setReturnType')->will($this->returnValue('')); $this->sharepointHandler->expects($this->any())->method('getLists')->will($this->returnValue($this->fixtureList)); }
/** * Sets the value of this argument. * * @param mixed $rawValue The value of this argument * @return \TYPO3\CMS\Extbase\Mvc\Controller\Argument * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentValueException if the argument is not a valid object of type $dataType */ public function setValue($rawValue) { if ($rawValue === NULL) { $this->value = NULL; return $this; } if (is_object($rawValue) && $rawValue instanceof $this->dataType) { $this->value = $rawValue; return $this; } $this->value = $this->propertyMapper->convert($rawValue, $this->dataType, $this->propertyMappingConfiguration); $this->validationResults = $this->propertyMapper->getMessages(); if ($this->validator !== NULL) { // TODO: Validation API has also changed!!! $validationMessages = $this->validator->validate($this->value); $this->validationResults->merge($validationMessages); } return $this; }
/** * @return \DateTime */ protected function getSelectedDate() : \DateTime { $fluidFormRenderer = $this->viewHelperVariableContainer->getView(); $formRuntime = $fluidFormRenderer->getFormRuntime(); $date = $formRuntime[$this->arguments['property']]; if ($date instanceof \DateTime) { return $date; } if ($date !== null) { $date = $this->propertyMapper->convert($date, 'DateTime'); if (!$date instanceof \DateTime) { return null; } return $date; } if ($this->hasArgument('initialDate')) { return new \DateTime($this->arguments['initialDate']); } }
/** * Returns a domain model for the given API path and data * This method will load existing models. * * @param array|string|int $data Data of the new model or it's UID * @param string $path API path to get the repository for * @return \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface */ public function getModelWithDataForPath($data, $path) { $modelClass = $this->getModelClassForPath($path); // If no data is given return a new instance if (!$data) { return $this->getEmptyModelForPath($path); } else { if (is_scalar($data)) { // If it is a scalar treat it as identity return $this->getModelWithIdentityForPath($data, $path); } } $data = $this->prepareModelData($data); try { $model = $this->propertyMapper->convert($data, $modelClass); } catch (\TYPO3\CMS\Extbase\Property\Exception $exception) { $model = NULL; $message = 'Uncaught exception #' . $exception->getCode() . ': ' . $exception->getMessage(); $this->getLogger()->log(LogLevel::ERROR, $message, array('exception' => $exception)); } return $model; }