Skip to content

Commit

Permalink
Merge branch '4.4' into 5.2
Browse files Browse the repository at this point in the history
* 4.4:
  [DoctrineBridge] fix setting default mapping type to attribute/annotation on php 8/7 respectively
  do not render the same label id attribute twice
  • Loading branch information
nicolas-grekas committed Jul 12, 2021
2 parents d432821 + 7253299 commit 17b0187
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bridge\Doctrine\DependencyInjection;

use Symfony\Component\Config\Resource\GlobResource;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
Expand Down Expand Up @@ -88,6 +89,25 @@ protected function loadMappingInformation(array $objectManager, ContainerBuilder
if (!$mappingConfig) {
continue;
}
} elseif (!$mappingConfig['type'] && \PHP_VERSION_ID < 80000) {
$mappingConfig['type'] = 'annotation';
} elseif (!$mappingConfig['type']) {
$mappingConfig['type'] = 'attribute';

$glob = new GlobResource($mappingConfig['dir'], '*', true);
$container->addResource($glob);

foreach ($glob as $file) {
$content = file_get_contents($file);

if (preg_match('/^#\[.*Entity\b/m', $content)) {
break;
}
if (preg_match('/^ \* @.*Entity\b/m', $content)) {
$mappingConfig['type'] = 'annotation';
break;
}
}
}

$this->assertValidMappingConfiguration($mappingConfig, $objectManager['name']);
Expand Down
Expand Up @@ -125,7 +125,7 @@
{% if app is defined and app.request is defined %}{%- set input_lang = app.request.locale -%}{%- endif -%}
{%- set attr = {lang: input_lang} | merge(attr) -%}
{{- block('form_widget_simple') -}}
{%- set label_attr = label_attr|merge({ class: (label_attr.class|default('') ~ ' custom-file-label')|trim }) -%}
{%- set label_attr = label_attr|merge({ class: (label_attr.class|default('') ~ ' custom-file-label')|trim })|filter((value, key) => key != 'id') -%}
<label for="{{ form.vars.id }}" {% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}>
{%- if attr.placeholder is defined and attr.placeholder is not none -%}
{{- translation_domain is same as(false) ? attr.placeholder : attr.placeholder|trans({}, translation_domain) -}}
Expand Down
Expand Up @@ -1121,6 +1121,24 @@ public function testFile()
);
}

public function testFileLabelIdNotDuplicated()
{
$form = $this->factory->createNamed('name', FileType::class);

$this->assertWidgetMatchesXpath($form->createView(), ['id' => 'n/a', 'attr' => ['class' => 'my&class form-control-file'], 'label_attr' => ['id' => 'label-id']],
'/div
[@class="custom-file"]
[
./input
[@type="file"]
[@name="name"]
/following-sibling::label
[@for="name"][not(@id)]
]
'
);
}

public function testFileWithPlaceholder()
{
$form = $this->factory->createNamed('name', FileType::class);
Expand Down

0 comments on commit 17b0187

Please sign in to comment.