Merge branch '4.4' into 5.2

* 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
This commit is contained in:
Nicolas Grekas 2021-07-12 14:57:05 +02:00
commit 17b0187fab
3 changed files with 39 additions and 1 deletions

View File

@ -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;
@ -88,6 +89,25 @@ abstract class AbstractDoctrineExtension extends Extension
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']);

View File

@ -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) -}}

View File

@ -1121,6 +1121,24 @@ abstract class AbstractBootstrap4LayoutTest extends AbstractBootstrap3LayoutTest
);
}
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);