diff --git a/manifest.php b/manifest.php index d43052c4d..1f1ea4b2f 100755 --- a/manifest.php +++ b/manifest.php @@ -26,6 +26,7 @@ // phpcs:disable Generic.Files.LineLength use oat\taoQtiTest\models\classes\render\CustomInteraction\ServiceProvider\CustomInteractionPostProcessingServiceProvider; // phpcs:enable Generic.Files.LineLength +use oat\taoQtiTest\models\Form\ServiceProvider\FormServiceProvider; use oat\taoQtiTest\models\render\ItemsReferencesServiceProvider; use oat\taoQtiTest\models\TestSessionState\Container\TestSessionStateServiceProvider; use oat\taoQtiTest\models\xmlEditor\XmlEditorInterface; @@ -185,6 +186,7 @@ ItemsReferencesServiceProvider::class, TestQtiServiceProvider::class, TestSessionStateServiceProvider::class, - MetadataServiceProvider::class + MetadataServiceProvider::class, + FormServiceProvider::class, ], ]; diff --git a/models/classes/Form/Modifier/EditTranslationInstanceFormModifier.php b/models/classes/Form/Modifier/EditTranslationInstanceFormModifier.php new file mode 100644 index 000000000..5d63ef523 --- /dev/null +++ b/models/classes/Form/Modifier/EditTranslationInstanceFormModifier.php @@ -0,0 +1,56 @@ +ontology = $ontology; + $this->testQtiService = $testQtiService; + } + + public function supports(Form $form, array $options = []): bool + { + $instanceUri = $form->getValue(self::FORM_INSTANCE_URI); + + if (!$instanceUri) { + return false; + } + + $instance = $this->ontology->getResource($instanceUri); + + // @TODO Check if FF for translation enabled + return $instance->isInstanceOf($this->ontology->getClass(TaoOntology::CLASS_URI_TEST)); + } + + public function modify(Form $form, array $options = []): void + { + $uniqueIdElement = $form->getElement(tao_helpers_Uri::encode(TaoOntology::PROPERTY_UNIQUE_IDENTIFIER)); + + if (!$uniqueIdElement) { + return; + } + + $instance = $this->ontology->getResource($form->getValue(self::FORM_INSTANCE_URI)); + $jsonTest = $this->testQtiService->getJsonTest($instance); + $id = json_decode($jsonTest, true)['identifier'] ?? null; + + if ($id) { + $uniqueIdElement->setValue($id); + } + } +} diff --git a/models/classes/Form/ServiceProvider/FormServiceProvider.php b/models/classes/Form/ServiceProvider/FormServiceProvider.php new file mode 100644 index 000000000..ad118d3df --- /dev/null +++ b/models/classes/Form/ServiceProvider/FormServiceProvider.php @@ -0,0 +1,36 @@ +services(); + + $services + ->set(EditTranslationInstanceFormModifier::class, EditTranslationInstanceFormModifier::class) + ->args([ + service(Ontology::SERVICE_ID), + service(taoQtiTest_models_classes_QtiTestService::class), + ]); + + $formModifierManager = $services->get(FormModifierManager::class); + $formModifierManager + ->call( + 'add', + [ + service(EditTranslationInstanceFormModifier::class), + EditTranslationInstanceFormModifier::ID, + ] + ); + } +} \ No newline at end of file