Skip to content

Commit

Permalink
fix(admin/jmn): link fieldType needs environment (#640)
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidmattei authored Oct 17, 2023
1 parent 8364a72 commit 5680aab
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
Expand Down Expand Up @@ -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,
])
Expand All @@ -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'])
;
Expand Down Expand Up @@ -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 = [];
Expand Down
1 change: 1 addition & 0 deletions EMS/core-bundle/src/Resources/config/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
<argument type="service" id="form.registry" />
<argument type="service" id="ems.service.elasticsearch" />
<argument type="service" id="ems_common.service.elastica" />
<argument type="service" id="EMS\CoreBundle\Service\EnvironmentService" />
<argument type="service" id="twig" />
<argument type="service" id="emsco.logger" />
<tag name="ems.form.datafieldtype" alias="json_menu_nested_link" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([{
Expand Down

0 comments on commit 5680aab

Please sign in to comment.