Created
September 8, 2014 08:20
-
-
Save sorenmalling/d39f8c1237e7fe88968f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Meteko\Extrapages\Service; | |
| use Meteko\Extrapages\Domain\Model\Page; | |
| class AdditionalAttributesService { | |
| /** | |
| * entryRepository | |
| * | |
| * @var \TYPO3\DyconSogneadmin\Domain\Repository\FileRepository | |
| * @inject | |
| */ | |
| protected $fileRepository; | |
| /** | |
| * FileReferenceRepository | |
| * | |
| * @var \TYPO3\DyconSogneadmin\Domain\Repository\FileReferenceRepository | |
| * @inject | |
| */ | |
| protected $fileReferenceRepository; | |
| /** | |
| * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface | |
| * @inject | |
| */ | |
| protected $persistenceManager; | |
| /** | |
| * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface | |
| * @inject | |
| */ | |
| protected $objectManager; | |
| /** | |
| * Settings | |
| * | |
| * @var array | |
| */ | |
| protected $settings; | |
| /** | |
| * Image function | |
| * | |
| * @param Page $page | |
| * @param array $additionalAttributes | |
| * @param array $settings | |
| */ | |
| public function image(Page $page, $additionalAttributes, $settings) { | |
| $storageRepository = $this->objectManager->get('TYPO3\CMS\Core\Resource\StorageRepository'); | |
| /** @var \TYPO3\CMS\Core\Resource\ResourceStorage $storage */ | |
| $storage = $storageRepository->findByUid($settings['fileStorage']); | |
| $contentElementArray = $page->getContentElements()->toArray(); | |
| for ($index = 0; $index < count($_FILES['tx_extrapages_manage']['name']['additionalAttributes']['image']['image']); $index++) { | |
| // setting up file data | |
| $fileData = array(); | |
| $fileData['name'] = $_FILES['tx_extrapages_manage']['name']['additionalAttributes']['image']['image'][$index]; | |
| $fileData['type'] = $_FILES['tx_extrapages_manage']['type']['additionalAttributes']['image']['image'][$index]; | |
| $fileData['tmp_name'] = $_FILES['tx_extrapages_manage']['tmp_name']['additionalAttributes']['image']['image'][$index]; | |
| $fileData['size'] = $_FILES['tx_extrapages_manage']['size']['additionalAttributes']['image']['image'][$index]; | |
| if ($fileData['name']) { | |
| // this will already handle the moving of the file to the storage: | |
| $newFileObject = $storage->addFile( | |
| $fileData['tmp_name'], | |
| $storage->getRootLevelFolder(), | |
| $fileData['name'] | |
| ); | |
| $newFileObject = $storage->getFile($newFileObject->getIdentifier()); | |
| $newFile = $this->fileRepository->findByUid($newFileObject->getProperty('uid')); | |
| /** @var \TYPO3\DyconSogneadmin\Domain\Model\FileReference $newFileReference */ | |
| $newFileReference = $this->objectManager->get('TYPO3\DyconSogneadmin\Domain\Model\FileReference'); | |
| $newFileReference->setFile($newFile); | |
| $newFileReference->setFieldname('image'); | |
| $newFileReference->setTableLocal('sys_file'); | |
| $newFileReference->setTablenames('tt_content'); | |
| $newFileReference->setUidForeign($contentElementArray[0]->getUid()); | |
| $this->fileReferenceRepository->add($newFileReference); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment