phptypo3typo3-extensionsextension-builder3

TYPO3 extension builder multiple images upload not working


My goal is to create extension using extension builder in TYPO3 7.6.2 version. I created Category Product extension from extension builder document, it works perfect except upload single image.

But I have to create functionality to add multiple images to single product and display images carousel on frontend. But extension builder does not work with file uploads.

I am new in TYPO3, so I don't understand how to add multiple images to that? I read too many documents but did not found perfect solution.

I just want to know the process how to add multiple images to products?

Thanks in advance!


Solution

  • Finally I got the solution to this question.

    Go to your extension and follow the steps -

    1. /Classes/Domain/Model/YourModel.php

          /**
           * yourPictures
           *
           * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
           * @lazy
           */
          protected $yourPictures = NULL;
      
          /**
           * Constructor
           *
           * @return AbstractObject
           */
          public function __construct() {
                  // ObjectStorage is needed to reference multiple files to one field
                  // see also @var before variable and @return before the respective get() method
                  $this->yourPictures = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
          }
      
          /**
           * returns yourPictures
           *
           * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
           */
          public function getYourPictures() {
                  return $this->yourPictures;
          }
      
          /**
           * sets yourPictures
           *
           * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $yourPictures
           * @return void
           */
          public function setYourPictures($yourPictures) {
                  $this->yourPictures = $yourPictures;
          }
      
    2. /Configuration/TCA/YourModel.php

      Add field name in array 'types' and in array 'columns' add this -

           'your_pictures' => array(
                    'exclude' => 1,
                    'label' => 'LLL:EXT:your_ext/Resources/Private/Language/locallang_db.xlf:tx_yourext_domain_model_yourmodel.your_pictures',
                    'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
                            'yourPictures',
                            array('minitems'=>0,'maxitems'=>10),
                            $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
                    ),
            ),
    
    1. /ext_tables.sql

    add my_pictures varchar(255) DEFAULT '' NOT NULL,

    1. To display in fluid template -
    <f:for each="{yourDomain.myPictures}" as="pic">
                <f:image src="{pic.originalResource.publicUrl}" alt="{pic.originalResource.alternative}" title="{pic.originalResource.title}" ></f:image>
                {pic.originalResource.description}
        </f:for>
    

    Thats it ! Hope it will help someone.

    Thanks