Skip to content

Commit 87d7ecd

Browse files
authored
Merge pull request #1 from Amadeco/Amadeco-patch-1
feat(seo): improve code quality in ApplySeoMetadata observer
2 parents 63b4ae3 + b1c497e commit 87d7ecd

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

Observer/ApplySeoMetadata.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,30 @@ public function execute(Observer $observer): void
6969
/** @var CustomEntity|null $entity */
7070
$entity = $this->registry->registry('current_custom_entity');
7171

72-
if (!$entity || !$entity instanceof CustomEntity) {
72+
if (!$entity || !($entity instanceof CustomEntity)) {
7373
return;
7474
}
7575

76-
// Apply meta title
77-
$metaTitle = $entity->getData('meta_title');
76+
// Apply meta title only if explicitly set
77+
$metaTitle = $entity->getMetaTitle();
7878
if (!empty($metaTitle)) {
7979
$this->pageConfig->getTitle()->set($metaTitle);
8080
}
8181

82-
// Apply meta description
83-
$metaDescription = $entity->getData('meta_description');
82+
// Apply meta description only if explicitly set
83+
$metaDescription = $entity->getMetaDescription();
8484
if (!empty($metaDescription)) {
8585
$this->pageConfig->setDescription($metaDescription);
8686
}
8787

88-
// Apply meta keywords
89-
$metaKeywords = $entity->getData('meta_keywords');
88+
// Apply meta keywords only if explicitly set
89+
$metaKeywords = $entity->getMetaKeywords();
9090
if (!empty($metaKeywords)) {
9191
$this->pageConfig->setKeywords($metaKeywords);
9292
}
9393

9494
// Apply meta robots only if explicitly set
95-
$metaRobots = $entity->getData('meta_robots');
95+
$metaRobots = $entity->getMetaRobots();
9696
if (!empty($metaRobots)) {
9797
$this->pageConfig->setRobots($metaRobots);
9898
}

Plugin/CustomEntityPlugin.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<?php
2-
2+
/**
3+
* Amadeco SmileCustomEntitySeo module
4+
*
5+
* @category Amadeco
6+
* @package Amadeco_SmileCustomEntitySeo
7+
* @copyright Ilan Parmentier
8+
*/
39
declare(strict_types=1);
410

511
namespace Amadeco\SmileCustomEntitySeo\Plugin;
@@ -28,4 +34,4 @@ public function afterGetInterfaceAttributes(CustomEntity $subject, array $result
2834
CustomEntitySeoInterface::META_ROBOTS
2935
]);
3036
}
31-
}
37+
}

0 commit comments

Comments
 (0)