Skip to content

Commit

Permalink
chore: use proxies instead of manager
Browse files Browse the repository at this point in the history
  • Loading branch information
shpran committed Sep 10, 2024
1 parent b93da9f commit 1a91a2d
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 193 deletions.
15 changes: 7 additions & 8 deletions helpers/form/class.FormContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

use oat\oatbox\service\ServiceManager;
use oat\oatbox\validator\ValidatorInterface;
use oat\tao\model\form\Modifier\FormModifierManager;
use oat\tao\model\form\Modifier\AbstractFormModifier;
use oat\tao\model\security\xsrf\TokenService;
use Psr\Container\ContainerInterface;
use tao_helpers_form_FormFactory as FormFactory;
Expand Down Expand Up @@ -121,8 +121,12 @@ public function __construct(array $data = [], array $options = [])
// initialize the elements of the form
$this->initElements();

if (!empty($options[self::FORM_MODIFIERS])) {
$this->getFormModifierManager()->modify($this->form, $options[self::FORM_MODIFIERS]);
foreach ($options[self::FORM_MODIFIERS] ?? [] as $modifierClass) {
$modifier = $this->getContainer()->get($modifierClass);

if ($modifier instanceof AbstractFormModifier) {
$modifier->modify($this->form, $options);
}
}

if ($this->form !== null) {
Expand Down Expand Up @@ -330,11 +334,6 @@ private function getSanitizerValidationFeeder(): SanitizerValidationFeederInterf
return $this->sanitizerValidationFeeder;
}

private function getFormModifierManager(): FormModifierManager
{
return $this->getContainer()->get(FormModifierManager::class);
}

private function withServiceManager(array &$options): void
{
if (
Expand Down
2 changes: 0 additions & 2 deletions manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
use oat\tao\model\featureFlag\FeatureFlagServiceProvider;
use oat\tao\model\featureVisibility\FeatureVisibilityServiceProvider;
use oat\tao\model\form\DataProvider\FormDataProviderServiceProvider;
use oat\tao\model\form\Modifier\FormModifierServiceProvider;
use oat\tao\model\import\ServiceProvider\ImportServiceProvider;
use oat\tao\model\LanguageServiceProvider;
use oat\tao\model\listener\PropertyServiceProvider;
Expand Down Expand Up @@ -422,7 +421,6 @@
FormDataProviderServiceProvider::class,
PropertyServiceProvider::class,
DynamicConfigServiceProvider::class,
FormModifierServiceProvider::class,
TranslationServiceProvider::class
],
'middlewares' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,31 @@

namespace oat\tao\model\Translation\Form\Modifier;

use oat\generis\model\data\Ontology;
use oat\tao\model\featureFlag\FeatureFlagCheckerInterface;
use oat\tao\model\form\Modifier\AbstractFormModifier;
use oat\tao\model\TaoOntology;
use tao_helpers_form_Form as Form;
use tao_helpers_form_Form;
use tao_helpers_Uri;

class TranslationInstanceFormModifier extends AbstractFormModifier
class TranslationFormModifier extends AbstractFormModifier
{
public const ID = 'tao.form_modifier.translation_instance';

private FeatureFlagCheckerInterface $featureFlagChecker;

public function __construct(Ontology $ontology, FeatureFlagCheckerInterface $featureFlagChecker)
public function __construct(FeatureFlagCheckerInterface $featureFlagChecker)
{
parent::__construct($ontology);

$this->featureFlagChecker = $featureFlagChecker;
}

public function supports(Form $form, array $options = []): bool
{
$instance = $this->getInstance($form, $options);

if ($instance === null) {
return false;
}

return $instance->isInstanceOf($this->ontology->getClass(TaoOntology::CLASS_URI_ITEM))
|| $instance->isInstanceOf($this->ontology->getClass(TaoOntology::CLASS_URI_TEST));
}

public function modify(Form $form, array $options = []): void
public function modify(tao_helpers_form_Form $form, array $options = []): void
{
foreach ($this->getTranslationElementsToRemove($form) as $elementUri) {
$form->removeElement(tao_helpers_Uri::encode($elementUri));
}
}

private function getTranslationElementsToRemove(Form $form): array
private function getTranslationElementsToRemove(tao_helpers_form_Form $form): array
{
if (!$this->featureFlagChecker->isEnabled(FeatureFlagCheckerInterface::FEATURE_TRANSLATION_ENABLED)) {
if (!$this->featureFlagChecker->isEnabled('FEATURE_TRANSLATION_ENABLED')) {
return [
TaoOntology::PROPERTY_UNIQUE_IDENTIFIER,
TaoOntology::PROPERTY_LANGUAGE,
Expand All @@ -74,6 +57,11 @@ private function getTranslationElementsToRemove(Form $form): array
}

$elementsToRemove = [];

if (!$this->featureFlagChecker->isEnabled('FEATURE_TRANSLATION_DEVELOPER_MODE')) {
$elementsToRemove[] = TaoOntology::PROPERTY_TRANSLATION_TYPE;
}

$translationTypeValue = $form->getValue(tao_helpers_Uri::encode(TaoOntology::PROPERTY_TRANSLATION_TYPE));
$isTranslationTypeValueEmpty = empty($translationTypeValue);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService;
use oat\oatbox\log\LoggerService;
use oat\tao\model\featureFlag\FeatureFlagChecker;
use oat\tao\model\form\Modifier\FormModifierManager;
use oat\tao\model\Translation\Factory\ResourceTranslatableFactory;
use oat\tao\model\Translation\Factory\ResourceTranslationFactory;
use oat\tao\model\Translation\Form\Modifier\TranslationInstanceFormModifier;
use oat\tao\model\Translation\Form\Modifier\TranslationFormModifier;
use oat\tao\model\Translation\Repository\ResourceTranslatableRepository;
use oat\tao\model\Translation\Repository\ResourceTranslationRepository;
use oat\tao\model\Translation\Service\ResourceMetadataPopulateService;
Expand Down Expand Up @@ -106,20 +105,9 @@ public function __invoke(ContainerConfigurator $configurator): void
->public();

$services
->set(TranslationInstanceFormModifier::class, TranslationInstanceFormModifier::class)
->set(TranslationFormModifier::class, TranslationFormModifier::class)
->args([
service(Ontology::SERVICE_ID),
service(FeatureFlagChecker::class),
]);

$formModifierManager = $services->get(FormModifierManager::class);
$formModifierManager
->call(
'add',
[
service(TranslationInstanceFormModifier::class),
TranslationInstanceFormModifier::ID,
]
);
}
}
1 change: 0 additions & 1 deletion models/classes/featureFlag/FeatureFlagCheckerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ interface FeatureFlagCheckerInterface
public const FEATURE_FLAG_PASSWORD_CHANGE_DISABLED = 'FEATURE_FLAG_PASSWORD_CHANGE_DISABLED';
public const FEATURE_FLAG_TAO_AS_A_TOOL = 'FEATURE_FLAG_TAO_AS_A_TOOL';
public const FEATURE_FLAG_SOLAR_DESIGN_ENABLED = 'FEATURE_FLAG_SOLAR_DESIGN_ENABLED';
public const FEATURE_TRANSLATION_ENABLED = 'FEATURE_TRANSLATION_ENABLED';

public function isEnabled(string $feature): bool;
}
25 changes: 11 additions & 14 deletions models/classes/form/Modifier/AbstractFormModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,24 @@

namespace oat\tao\model\form\Modifier;

use core_kernel_classes_Resource;
use oat\generis\model\data\Ontology;
use tao_helpers_form_Form;

abstract class AbstractFormModifier implements FormModifierInterface
abstract class AbstractFormModifier
{
protected Ontology $ontology;
/** @var AbstractFormModifier[] */
private array $modifiers = [];

public function __construct(Ontology $ontology)
public function addModifier(AbstractFormModifier $modifier): void
{
$this->ontology = $ontology;
if (!in_array($modifier, $this->modifiers, true)) {
$this->modifiers[] = $modifier;
}
}

protected function getInstance(tao_helpers_form_Form $form, array $options = []): ?core_kernel_classes_Resource
public function modify(tao_helpers_form_Form $form, array $options = []): void
{
if (($options[self::OPTION_INSTANCE] ?? null) instanceof core_kernel_classes_Resource) {
return $options[self::OPTION_INSTANCE];
foreach ($this->modifiers as $modifier) {
$modifier->modify($form, $options);
}

$instanceUri = $form->getValue(self::FORM_INSTANCE_URI);

return $instanceUri ? $this->ontology->getResource($instanceUri) : null;
}
}
}
35 changes: 0 additions & 35 deletions models/classes/form/Modifier/FormModifierInterface.php

This file was deleted.

58 changes: 0 additions & 58 deletions models/classes/form/Modifier/FormModifierManager.php

This file was deleted.

38 changes: 0 additions & 38 deletions models/classes/form/Modifier/FormModifierServiceProvider.php

This file was deleted.

0 comments on commit 1a91a2d

Please sign in to comment.