diff --git a/EMS/core-bundle/src/Form/DataField/JsonMenuNestedLinkFieldType.php b/EMS/core-bundle/src/Form/DataField/JsonMenuNestedLinkFieldType.php index 8b83fb8ef..1ebf60a67 100644 --- a/EMS/core-bundle/src/Form/DataField/JsonMenuNestedLinkFieldType.php +++ b/EMS/core-bundle/src/Form/DataField/JsonMenuNestedLinkFieldType.php @@ -9,7 +9,9 @@ use EMS\CoreBundle\Entity\FieldType; use EMS\CoreBundle\Form\Field\AnalyzerPickerType; use EMS\CoreBundle\Form\Field\CodeEditorType; +use EMS\CoreBundle\Form\Field\EnvironmentPickerType; use EMS\CoreBundle\Service\ElasticsearchService; +use EMS\CoreBundle\Service\EnvironmentService; use EMS\Helpers\Standard\Json; use Psr\Log\LoggerInterface; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; @@ -31,6 +33,7 @@ public function __construct( FormRegistryInterface $formRegistry, ElasticsearchService $elasticsearchService, private readonly ElasticaService $elasticaService, + private readonly EnvironmentService $environmentService, private readonly Environment $twig, private readonly LoggerInterface $logger ) { @@ -120,6 +123,7 @@ public function configureOptions(OptionsResolver $resolver): void 'json_menu_nested_field' => null, 'json_menu_nested_unique' => false, 'query' => null, + 'environment' => null, 'choices_template' => null, 'display_template' => null, ]) @@ -142,6 +146,11 @@ public function buildOptionsForm(FormBuilderInterface $builder, array $options): ->add('json_menu_nested_field', TextType::class, ['required' => true]) ->add('json_menu_nested_unique', CheckboxType::class, ['required' => false]) ->add('query', CodeEditorType::class, ['required' => false, 'language' => 'ace/mode/json']) + ->add('environment', EnvironmentPickerType::class, [ + 'required' => false, + 'managedOnly' => false, + 'userPublishEnvironments' => false, + ]) ->add('choices_template', CodeEditorType::class, ['required' => false, 'min-lines' => 10, 'language' => 'ace/mode/twig']) ->add('display_template', CodeEditorType::class, ['required' => false, 'min-lines' => 10, 'language' => 'ace/mode/twig']) ; @@ -250,7 +259,10 @@ private function buildChoices( $assignedUuids = !$migration && $jmnUnique ? $this->searchAssignedUuids($fieldType, $rawData) : []; - $index = $fieldType->giveContentType()->giveEnvironment()->getAlias(); + $environmentName = $fieldType->getDisplayOption('environment'); + $environment = $environmentName ? $this->environmentService->giveByName($environmentName) : null; + + $index = $environment ? $environment->getAlias() : $fieldType->giveContentType()->giveEnvironment()->getAlias(); $jmnMenu = $this->createJsonMenuNested($index, $jmnQuery, $jmnField); $items = []; diff --git a/EMS/core-bundle/src/Resources/config/form.xml b/EMS/core-bundle/src/Resources/config/form.xml index 79b561672..3d931b534 100644 --- a/EMS/core-bundle/src/Resources/config/form.xml +++ b/EMS/core-bundle/src/Resources/config/form.xml @@ -209,6 +209,7 @@ + diff --git a/EMS/core-bundle/src/Resources/views/macros/data-field-type.html.twig b/EMS/core-bundle/src/Resources/views/macros/data-field-type.html.twig index 173941c44..f7fb24d79 100644 --- a/EMS/core-bundle/src/Resources/views/macros/data-field-type.html.twig +++ b/EMS/core-bundle/src/Resources/views/macros/data-field-type.html.twig @@ -1030,7 +1030,12 @@ {%- set jmnQuery = displayOptions.query|default(false) -%} {%- if jmnField and jmnQuery and dataField.rawData is not null -%} - {%- set hits = { index: dataField.fieldType.contentType.environment.alias, body: jmnQuery}|search.hits.hits -%} + {% if displayOptions.environment is not null %} + {% set index = displayOptions.environment|emsco_get_environment.alias %} + {% else %} + {% set index = dataField.fieldType.contentType.environment.alias %} + {% endif %} + {%- set hits = { index: index, body: jmnQuery}|search.hits.hits -%} {%- set structures = [] -%} {%- for h in hits -%} {% set structures = structures|merge([{