18
18
use Umanit \SeoBundle \Entity \UrlHistory ;
19
19
use Umanit \SeoBundle \Utils \EntityParser \Excerpt ;
20
20
use Umanit \SeoBundle \Utils \EntityParser \Title ;
21
+ use Umanit \SeoBundle \Utils \SeoMetadataResolver ;
21
22
22
23
/**
23
24
* Class SeoMetadataType
@@ -40,25 +41,26 @@ class SeoMetadataType extends AbstractType
40
41
41
42
/** @var EntityManagerInterface */
42
43
private $ em ;
44
+ /**
45
+ * @var SeoMetadataResolver
46
+ */
47
+ private $ seoMetadataResolver ;
43
48
44
49
/**
45
50
* SeoMetadataType constructor.
46
51
*
47
- * @param Excerpt $excerpt
48
- * @param Title $title
52
+ * @param SeoMetadataResolver $seoMetadataResolver
49
53
* @param TranslatorInterface|\Symfony\Component\Translation\TranslatorInterface $translator
50
- * @param EntityManagerInterface $em
51
- * @param array $metadataConfig
54
+ * @param EntityManagerInterface $em
55
+ * @param array $metadataConfig
52
56
*/
53
57
public function __construct (
54
- Excerpt $ excerpt ,
55
- Title $ title ,
58
+ SeoMetadataResolver $ seoMetadataResolver ,
56
59
$ translator ,
57
60
EntityManagerInterface $ em ,
58
61
array $ metadataConfig
59
62
) {
60
- $ this ->excerpt = $ excerpt ;
61
- $ this ->title = $ title ;
63
+ $ this ->seoMetadataResolver = $ seoMetadataResolver ;
62
64
$ this ->metadataConfig = $ metadataConfig ;
63
65
$ this ->translator = $ translator ;
64
66
$ this ->em = $ em ;
@@ -94,25 +96,15 @@ public function buildForm(FormBuilderInterface $builder, array $options)
94
96
$ locale = method_exists ($ parentModelData , 'getLocale ' ) ? $ parentModelData ->getLocale () : null ;
95
97
// Title
96
98
if (null === $ seoMetadata ->getTitle ()) {
97
- $ title = $ this ->title ->fromEntity ($ parentModelData ) ?? $ this ->translator ->trans (
98
- $ this ->metadataConfig ['default_title ' ],
99
- [],
100
- $ options ['translation_domain ' ],
101
- $ locale
102
- );
99
+ $ title = $ this ->seoMetadataResolver ->metaTitle ($ parentModelData );
103
100
104
101
$ this ->setSubFormOption ($ seoForm , 'title ' , 'attr ' , [
105
102
'placeholder ' => html_entity_decode ($ title ),
106
103
]);
107
104
}
108
105
// Description
109
106
if (null === $ seoMetadata ->getDescription ()) {
110
- $ description = $ this ->excerpt ->fromEntity ($ parentModelData ) ?? $ this ->translator ->trans (
111
- $ this ->metadataConfig ['default_description ' ],
112
- [],
113
- $ options ['translation_domain ' ],
114
- $ locale
115
- );
107
+ $ description = $ this ->seoMetadataResolver ->metaDescription ($ parentModelData );
116
108
117
109
$ this ->setSubFormOption ($ seoForm , 'description ' , 'attr ' , [
118
110
'placeholder ' => html_entity_decode ($ description ),
0 commit comments