public function it_sets_found_object_as_request_parameter(ParamConverter $paramConverter, TranslatableMetadata $translatableMetadata, Request $request, ParameterBag $attributes, TranslatableRepository $translatableRepository, \stdClass $object)
 {
     $paramConverter->getClass()->willReturn('TranslatableEntity');
     $paramConverter->getName()->willReturn('object');
     $translatableMetadata->hasTranslatableProperties()->willReturn(true);
     $request->getLocale()->willReturn('some_locale');
     $request->attributes = $attributes;
     $attributes->keys()->willReturn(array('translatableProperty'));
     $attributes->get('translatableProperty')->willReturn('translationValue');
     $translatableMetadata->getTranslatableProperties()->willReturn(array('translations' => array('translatableProperty' => 'translationField')));
     $translatableRepository->findTranslatableOneBy(array('translatableProperty' => 'translationValue'), null, 'some_locale')->willReturn($object);
     $attributes->set('object', $object)->shouldBeCalled();
     $this->apply($request, $paramConverter);
 }
 function it_sets_translatable_and_not_translated_to_true_when_column_has_not_translated_nested_translatable_property_in_field_mapping(ColumnTypeInterface $column, CellViewInterface $view, ClassMetadata $translatableMetadata)
 {
     $column->getOption('field_mapping')->willReturn(array('nested_object.translatable_property'));
     $nested_object = (object) array('translatable_property' => 'value', 'non_translatable_property' => 'value', 'locale' => 'de');
     $data = (object) array('nested_object' => $nested_object);
     $view->getSource()->willReturn($data);
     $translatableMetadata->hasTranslatableProperties()->willReturn(true);
     $translatableMetadata->getTranslatableProperties()->willReturn(array('translations' => array('translatable_property' => 'translation_property')));
     $translatableMetadata->localeProperty = 'locale';
     $view->setAttribute('translatable', true)->shouldBeCalled();
     $view->setAttribute('not_translated', true)->shouldBeCalled();
     $this->buildCellView($column, $view);
 }
 /**
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $baseClassMetadata
  * @param \FSi\DoctrineExtensions\Translatable\Mapping\ClassMetadata $translatableClassMetadata
  * @throws \FSi\DoctrineExtensions\Translatable\Exception\MappingException
  */
 private function validateTranslatableProperties(ClassMetadata $baseClassMetadata, TranslatableClassMetadata $translatableClassMetadata)
 {
     $translatableProperties = $translatableClassMetadata->getTranslatableProperties();
     foreach ($translatableProperties as $translation => $properties) {
         if (!$baseClassMetadata->hasAssociation($translation) || !$baseClassMetadata->isCollectionValuedAssociation($translation)) {
             throw new Exception\MappingException(sprintf("Field '%s' in entity '%s' has to be a OneToMany association", $translation, $baseClassMetadata->getName()));
         }
     }
 }
 /**
  * Helper method to insert, remove or update translations entities associated with specified object
  *
  * @param \Doctrine\Common\Persistence\ObjectManager $objectManager
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $meta
  * @param \FSi\DoctrineExtensions\Translatable\Mapping\ClassMetadata $translatableMeta
  * @param object $object
  */
 protected function updateTranslations(ObjectManager $objectManager, ClassMetadata $meta, TranslatableClassMetadata $translatableMeta, $object)
 {
     $localeProperty = $translatableMeta->localeProperty;
     $propertyObserver = $this->getPropertyObserver($objectManager);
     $locale = $objectLocale = PropertyAccess::createPropertyAccessor()->getValue($object, $localeProperty);
     $objectLanguageChanged = !$propertyObserver->hasSavedValue($object, $localeProperty) && isset($objectLocale) || $propertyObserver->hasSavedValue($object, $localeProperty) && $propertyObserver->hasValueChanged($object, $localeProperty);
     if (!isset($locale)) {
         $locale = $this->getLocale();
     }
     $translatableProperties = $translatableMeta->getTranslatableProperties();
     foreach ($translatableProperties as $translation => $properties) {
         $translationEntity = $meta->getAssociationTargetClass($translation);
         $translationMeta = $objectManager->getClassMetadata($translationEntity);
         $translationLanguageField = $this->getTranslationLanguageField($objectManager, $translationMeta->name);
         $translationAssociation = $meta->getAssociationMapping($translation);
         $translations = $meta->getFieldValue($object, $translation);
         $currentTranslation = null;
         if (isset($translations)) {
             $currentTranslation = $this->findTranslation($translations, $translationMeta, $translationLanguageField, $locale);
         }
         $propertiesFound = false;
         foreach ($properties as $property => $translationField) {
             $propertyValue = PropertyAccess::createPropertyAccessor()->getValue($object, $property);
             if (isset($propertyValue)) {
                 $propertiesFound = true;
             }
             if ($objectLanguageChanged || !$propertyObserver->hasSavedValue($object, $property) && isset($propertyValue) || $propertyObserver->hasSavedValue($object, $property) && $propertyObserver->hasValueChanged($object, $property)) {
                 if (isset($propertyValue)) {
                     if (!isset($currentTranslation)) {
                         $currentTranslation = new $translationEntity();
                         $translationMeta->setFieldValue($currentTranslation, $translationLanguageField, $locale);
                         $translationMeta->setFieldValue($currentTranslation, $translationAssociation['mappedBy'], $object);
                         if (isset($translationAssociation['indexBy'])) {
                             $index = $translationMeta->getFieldValue($currentTranslation, $translationAssociation['indexBy']);
                             $translations[$index] = $currentTranslation;
                         } else {
                             $translations[] = $currentTranslation;
                         }
                         $objectManager->persist($currentTranslation);
                     }
                     $translationMeta->setFieldValue($currentTranslation, $translationField, $propertyValue);
                 } else {
                     if ($currentTranslation) {
                         $translationMeta->setFieldValue($currentTranslation, $translationField, null);
                     }
                 }
             }
         }
         if ($propertiesFound && !isset($locale)) {
             throw new Exception\RuntimeException('Neither object\'s locale nor the default locale was defined for translatable properties');
         }
         if (!$propertiesFound && isset($currentTranslation) && isset($objectLocale)) {
             $objectManager->remove($currentTranslation);
             if ($translations->contains($currentTranslation)) {
                 $translations->removeElement($currentTranslation);
             }
         }
     }
 }
 /**
  * @param \FSi\DoctrineExtensions\Translatable\Mapping\ClassMetadata $translatableMetadata
  * @param string $field
  * @return bool
  */
 private function isFieldTranslatable(TranslatableClassMetadata $translatableMetadata, $field)
 {
     foreach ($translatableMetadata->getTranslatableProperties() as $translationAssociation => $properties) {
         if (isset($properties[$field])) {
             return true;
         }
     }
     return false;
 }
 function it_return_false_if_form_is_not_for_translatable_property(ClassMetadata $translatableMetadata, FormInterface $form)
 {
     $translatableMetadata->getTranslatableProperties()->willReturn(array());
     $this->isFormPropertyPathTranslatable($form)->shouldReturn(false);
 }