1. Go to this page and download the library: Download connectsb/translationbundle 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/ */
connectsb / translationbundle example snippets
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
...
new ConnectSB\TranslationBundle\ConnectSBTranslationBundle()
);
}
}
/**
* @ORM\Table()
* @ORM\Entity
*/
class TranslationKey extends BaseTranslationKey
{
/**
* @ORM\OneToMany(targetEntity="TranslationValue", mappedBy="translationKey", cascade={"persist"})
*/
protected $translationValues;
/**
* Define connection with your entity here
*
* @ORM\ManyToOne(targetEntity="ExampleEntity", inversedBy="translationKeys", cascade={"persist"})
* @ORM\JoinColumn(name="example_entity_id", referencedColumnName="id")
*/
private $exampleEntity;
}
public function editTranslations(Request $request, ExampleEntity $exampleEntity)
{
// Set the entity ID in the request so the bundle can read it
$request->request->set('entityId', $exampleEntity->getId());
/** TranslationKey[] $translations */
$translations = $this->get('connect_sb_database_translation_service')->getTranslationsCollection();
// Set the translationKeys (this is necessary in order to build the form)
$exampleEntity->setTranslationKeys($translations);
$form = $this->createForm(
new TranslationsCollectionType($this->get('connect_sb_database_translation_service')), $exampleEntity
);
$form->handleRequest($request);
if ($form->isValid()) {
// Get the (edited) translationKeys from the form
$translationKeys = $form->getData()->getTranslationKeys();
/** TranslationKey[] $modifiedTranslationKeys */
$modifiedTranslationKeys = $this->get('connect_sb_database_translation_service')->getModifiedTranslations($translationKeys);
$exampleEntity->setTranslationKeys($modifiedTranslationKeys);
// persist and flush
}
// return and render the form
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.