PHP code example of sandstorm / gedmotranslatableconnector

1. Go to this page and download the library: Download sandstorm/gedmotranslatableconnector library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sandstorm / gedmotranslatableconnector example snippets


class Event {
    use TranslatableTrait;
    
    /**
     * @var array
     * @Flow\Transient
     */
    protected $translationAssociationMapping = array(
        'assetIdentifier' => 'asset'
    );
    
    /**
     * @Gedmo\Translatable
     * @var string
     */
    protected $assetIdentifier;

    /**
     * @Flow\Inject
     * @var AssetRepository
     */
    protected $assetRepository;

    /**
     * @Flow\Inject
     * @var PersistenceManagerInterface
     */
    protected $persistenceManager;

    /**
     * @Flow\Inject
     * @var PropertyMapper
     */
    protected $propertyMapper;


    /**
     * @return \Neos\Media\Domain\Model\Asset
     */
    public function getAsset() {
        return $this->assetOnLoad($this->assetIdentifier);
    }

    /**
     * !!! This accepts the raw array as the user uploaded it; as we need to trigger the property mapper inside
     *     assetOnSave manually.
     *
     * @param array $asset
     */
    public function setAsset($asset) {
        $this->assetIdentifier = $this->assetOnSave($asset);
    }

    /**
     * This method is called in two places:
     * - inside setAsset()
     * - automatically by the TranslatableTrait
     * 
     * @param array $asset
     */
    public function assetOnSave($asset) {
        $asset = $this->propertyMapper->convert($asset, 'Neos\Media\Domain\Model\AssetInterface');
        if ($asset === NULL) {
            $this->assetRepository->remove($asset);
            return NULL;
        } elseif ($this->persistenceManager->isNewObject($asset)) {
            $this->assetRepository->add($asset);
            return $this->persistenceManager->getIdentifierByObject($asset);
        } else {
            $this->assetRepository->update($asset);
            return $this->persistenceManager->getIdentifierByObject($asset);
        }
    }

    /**
     * This method is called in two places:
     * - inside getAsset()
     * - automatically by the TranslatableTrait
     * 
     * @param array $asset
     */
    public function assetOnLoad($assetIdentifier) {
        return $this->assetRepository->findByIdentifier($assetIdentifier);
    }
}