From 0878790ef294f67ddf5808c665915fbb52c9a801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20K=C3=B6rner?= Date: Wed, 13 May 2026 16:02:52 +0200 Subject: [PATCH 1/2] Remove legacy tag integration --- README.md | 4 +- config/services.yaml | 7 - config/tags.yaml | 129 ------------------ .../Compiler/AdjustContainerPass.php | 45 ------ .../HeimrichHannotHeadBundleExtension.php | 1 - .../Contao/ParseTemplateListener.php | 5 - src/HeadTag/BaseTag.php | 1 - src/HeadTag/HeadTagFactory.php | 13 +- src/HeadTag/Link/CanonicalLink.php | 1 - src/HeimrichHannotContaoHeadBundle.php | 17 --- src/Helper/LegacyHelper.php | 68 --------- src/Manager/HtmlHeadTagManager.php | 26 +--- src/Manager/TagManager.php | 112 --------------- src/Tag/AbstractLinkTag.php | 73 ---------- src/Tag/AbstractMetaTag.php | 80 ----------- src/Tag/AbstractTag.php | 108 --------------- src/Tag/Link/LinkCanonical.php | 24 ---- src/Tag/Link/LinkNext.php | 24 ---- src/Tag/Link/LinkPrev.php | 24 ---- src/Tag/Meta/MetaCharset.php | 63 --------- src/Tag/Meta/MetaDate.php | 24 ---- src/Tag/Meta/MetaDescription.php | 47 ------- src/Tag/Meta/MetaKeywords.php | 24 ---- src/Tag/Meta/MetaLanguage.php | 24 ---- src/Tag/Meta/MetaRobots.php | 24 ---- src/Tag/Meta/MetaTitle.php | 24 ---- src/Tag/Meta/OG/OGDescription.php | 54 -------- src/Tag/Meta/OG/OGImage.php | 31 ----- src/Tag/Meta/OG/OGLocale.php | 31 ----- src/Tag/Meta/OG/OGSiteName.php | 31 ----- src/Tag/Meta/OG/OGTitle.php | 31 ----- src/Tag/Meta/OG/OGType.php | 31 ----- src/Tag/Meta/OG/OGUrl.php | 31 ----- src/Tag/Meta/Twitter/TwitterCard.php | 24 ---- src/Tag/Meta/Twitter/TwitterCreator.php | 24 ---- src/Tag/Meta/Twitter/TwitterDescription.php | 47 ------- src/Tag/Meta/Twitter/TwitterImage.php | 24 ---- src/Tag/Meta/Twitter/TwitterImageAlt.php | 24 ---- src/Tag/Meta/Twitter/TwitterPlayer.php | 24 ---- src/Tag/Meta/Twitter/TwitterPlayerHeight.php | 24 ---- src/Tag/Meta/Twitter/TwitterPlayerStream.php | 24 ---- .../TwitterPlayerStreamContentType.php | 24 ---- src/Tag/Meta/Twitter/TwitterPlayerWidth.php | 24 ---- src/Tag/Meta/Twitter/TwitterSite.php | 24 ---- src/Tag/Meta/Twitter/TwitterTitle.php | 24 ---- src/Tag/Misc/Base.php | 44 ------ src/Tag/Misc/Title.php | 31 ----- src/Tag/TagInterface.php | 43 ------ 48 files changed, 4 insertions(+), 1657 deletions(-) delete mode 100644 config/tags.yaml delete mode 100644 src/DependencyInjection/Compiler/AdjustContainerPass.php delete mode 100644 src/Helper/LegacyHelper.php delete mode 100644 src/Manager/TagManager.php delete mode 100644 src/Tag/AbstractLinkTag.php delete mode 100644 src/Tag/AbstractMetaTag.php delete mode 100644 src/Tag/AbstractTag.php delete mode 100644 src/Tag/Link/LinkCanonical.php delete mode 100644 src/Tag/Link/LinkNext.php delete mode 100644 src/Tag/Link/LinkPrev.php delete mode 100644 src/Tag/Meta/MetaCharset.php delete mode 100644 src/Tag/Meta/MetaDate.php delete mode 100644 src/Tag/Meta/MetaDescription.php delete mode 100644 src/Tag/Meta/MetaKeywords.php delete mode 100644 src/Tag/Meta/MetaLanguage.php delete mode 100644 src/Tag/Meta/MetaRobots.php delete mode 100644 src/Tag/Meta/MetaTitle.php delete mode 100644 src/Tag/Meta/OG/OGDescription.php delete mode 100644 src/Tag/Meta/OG/OGImage.php delete mode 100644 src/Tag/Meta/OG/OGLocale.php delete mode 100644 src/Tag/Meta/OG/OGSiteName.php delete mode 100644 src/Tag/Meta/OG/OGTitle.php delete mode 100644 src/Tag/Meta/OG/OGType.php delete mode 100644 src/Tag/Meta/OG/OGUrl.php delete mode 100644 src/Tag/Meta/Twitter/TwitterCard.php delete mode 100644 src/Tag/Meta/Twitter/TwitterCreator.php delete mode 100644 src/Tag/Meta/Twitter/TwitterDescription.php delete mode 100644 src/Tag/Meta/Twitter/TwitterImage.php delete mode 100644 src/Tag/Meta/Twitter/TwitterImageAlt.php delete mode 100644 src/Tag/Meta/Twitter/TwitterPlayer.php delete mode 100644 src/Tag/Meta/Twitter/TwitterPlayerHeight.php delete mode 100644 src/Tag/Meta/Twitter/TwitterPlayerStream.php delete mode 100644 src/Tag/Meta/Twitter/TwitterPlayerStreamContentType.php delete mode 100644 src/Tag/Meta/Twitter/TwitterPlayerWidth.php delete mode 100644 src/Tag/Meta/Twitter/TwitterSite.php delete mode 100644 src/Tag/Meta/Twitter/TwitterTitle.php delete mode 100644 src/Tag/Misc/Base.php delete mode 100644 src/Tag/Misc/Title.php delete mode 100644 src/Tag/TagInterface.php diff --git a/README.md b/README.md index ac90888..ede6455 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ class SomeEventListener -## Legacy integration +## Template output Be sure, `huh_head.use_contao_head` and/or `huh_head.use_contao_variables` are not set to true. @@ -157,7 +157,7 @@ Make sure, that you remove (are outputted by $this->meta() if `huh_head.use_cont ``` -The `meta` function accepts currently one parameter that can contain service names (array) that should be skipped. +The `meta` function accepts currently one parameter that can contain tag names (array) that should be skipped. ## Developers diff --git a/config/services.yaml b/config/services.yaml index 9170a6e..de6fb59 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -7,7 +7,6 @@ services: HeimrichHannot\HeadBundle\: resource: '../src/{EventListener,Helper}/*' - exclude: '../src/Helper/LegacyHelper.php' bind: $bundleConfig: '%huh_head%' @@ -18,9 +17,3 @@ services: HeimrichHannot\HeadBundle\HeadTag\HeadTagFactory: autoconfigure: true - - huh.head.tag_manager: - class: HeimrichHannot\HeadBundle\Manager\TagManager - public: true - deprecated: ~ - HeimrichHannot\HeadBundle\Manager\TagManager: '@huh.head.tag_manager' diff --git a/config/tags.yaml b/config/tags.yaml deleted file mode 100644 index f1f6765..0000000 --- a/config/tags.yaml +++ /dev/null @@ -1,129 +0,0 @@ -services: - _defaults: - public: true - - huh.head.tag.base: - class: HeimrichHannot\HeadBundle\Tag\Misc\Base - arguments: ['@huh.head.tag_manager'] - huh.head.tag.title: - class: HeimrichHannot\HeadBundle\Tag\Misc\Title - arguments: ['@huh.head.tag_manager'] - huh.head.tag.meta_date: - class: HeimrichHannot\HeadBundle\Tag\Meta\MetaDate - arguments: ['@huh.head.tag_manager'] - huh.head.tag.meta_language: - class: HeimrichHannot\HeadBundle\Tag\Meta\MetaLanguage - arguments: ['@huh.head.tag_manager'] - huh.head.tag.meta_charset: - class: HeimrichHannot\HeadBundle\Tag\Meta\MetaCharset - arguments: ['@huh.head.tag_manager'] - huh.head.tag.meta_title: - class: HeimrichHannot\HeadBundle\Tag\Meta\MetaTitle - arguments: ['@huh.head.tag_manager'] - huh.head.tag.meta_description: - class: HeimrichHannot\HeadBundle\Tag\Meta\MetaDescription - arguments: ['@huh.head.tag_manager'] - huh.head.tag.meta_keywords: - class: HeimrichHannot\HeadBundle\Tag\Meta\MetaKeywords - arguments: ['@huh.head.tag_manager'] - huh.head.tag.meta_robots: - class: HeimrichHannot\HeadBundle\Tag\Meta\MetaRobots - arguments: ['@huh.head.tag_manager'] - huh.head.tag.og_title: - class: HeimrichHannot\HeadBundle\Tag\Meta\OG\OGTitle - arguments: ['@huh.head.tag_manager'] - huh.head.tag.og_type: - class: HeimrichHannot\HeadBundle\Tag\Meta\OG\OGType - arguments: ['@huh.head.tag_manager'] - huh.head.tag.og_url: - class: HeimrichHannot\HeadBundle\Tag\Meta\OG\OGUrl - arguments: ['@huh.head.tag_manager'] - huh.head.tag.og_description: - class: HeimrichHannot\HeadBundle\Tag\Meta\OG\OGDescription - arguments: ['@huh.head.tag_manager'] - huh.head.tag.og_image: - class: HeimrichHannot\HeadBundle\Tag\Meta\OG\OGImage - arguments: ['@huh.head.tag_manager'] - huh.head.tag.og_locale: - class: HeimrichHannot\HeadBundle\Tag\Meta\OG\OGLocale - arguments: ['@huh.head.tag_manager'] - huh.head.tag.og_site_name: - class: HeimrichHannot\HeadBundle\Tag\Meta\OG\OGSiteName - arguments: ['@huh.head.tag_manager'] - huh.head.tag.twitter_card: - class: HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterCard - arguments: ['@huh.head.tag_manager'] - huh.head.tag.twitter_site: - class: HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterSite - arguments: ['@huh.head.tag_manager'] - huh.head.tag.twitter_creator: - class: HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterCreator - arguments: ['@huh.head.tag_manager'] - huh.head.tag.twitter_title: - class: HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterTitle - arguments: ['@huh.head.tag_manager'] - huh.head.tag.twitter_description: - class: HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterDescription - arguments: ['@huh.head.tag_manager'] - huh.head.tag.twitter_image: - class: HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterImage - arguments: ['@huh.head.tag_manager'] - huh.head.tag.twitter_image_alt: - class: HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterImageAlt - arguments: ['@huh.head.tag_manager'] - huh.head.tag.twitter_player: - class: HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterPlayer - arguments: ['@huh.head.tag_manager'] - huh.head.tag.twitter_player_width: - class: HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterPlayerWidth - arguments: ['@huh.head.tag_manager'] - huh.head.tag.twitter_player_height: - class: HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterPlayerHeight - arguments: ['@huh.head.tag_manager'] - huh.head.tag.twitter_player_stream: - class: HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterPlayerStream - arguments: ['@huh.head.tag_manager'] - huh.head.tag.twitter_player_stream_content_type: - class: HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterPlayerStreamContentType - arguments: ['@huh.head.tag_manager'] - huh.head.tag.link_prev: - class: HeimrichHannot\HeadBundle\Tag\Link\LinkPrev - arguments: ['@huh.head.tag_manager'] - huh.head.tag.link_next: - class: HeimrichHannot\HeadBundle\Tag\Link\LinkNext - arguments: ['@huh.head.tag_manager'] - huh.head.tag.link_canonical: - class: HeimrichHannot\HeadBundle\Tag\Link\LinkCanonical - arguments: ['@huh.head.tag_manager'] - - HeimrichHannot\HeadBundle\Tag\Misc\Base: '@huh.head.tag.base' - HeimrichHannot\HeadBundle\Tag\Misc\Title: '@huh.head.tag.title' - HeimrichHannot\HeadBundle\Tag\Meta\MetaDate: '@huh.head.tag.meta_date' - HeimrichHannot\HeadBundle\Tag\Meta\MetaLanguage: '@huh.head.tag.meta_language' - HeimrichHannot\HeadBundle\Tag\Meta\MetaCharset: '@huh.head.tag.meta_charset' - HeimrichHannot\HeadBundle\Tag\Meta\MetaTitle: '@huh.head.tag.meta_title' - HeimrichHannot\HeadBundle\Tag\Meta\MetaDescription: '@huh.head.tag.meta_description' - HeimrichHannot\HeadBundle\Tag\Meta\MetaKeywords: '@huh.head.tag.meta_keywords' - HeimrichHannot\HeadBundle\Tag\Meta\MetaRobots: '@huh.head.tag.meta_robots' - HeimrichHannot\HeadBundle\Tag\Meta\OG\OGTitle: '@huh.head.tag.og_title' - HeimrichHannot\HeadBundle\Tag\Meta\OG\OGType: '@huh.head.tag.og_type' - HeimrichHannot\HeadBundle\Tag\Meta\OG\OGUrl: '@huh.head.tag.og_url' - HeimrichHannot\HeadBundle\Tag\Meta\OG\OGDescription: '@huh.head.tag.og_description' - HeimrichHannot\HeadBundle\Tag\Meta\OG\OGImage: '@huh.head.tag.og_image' - HeimrichHannot\HeadBundle\Tag\Meta\OG\OGLocale: '@huh.head.tag.og_locale' - HeimrichHannot\HeadBundle\Tag\Meta\OG\OGSiteName: '@huh.head.tag.og_site_name' - HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterCard: '@huh.head.tag.twitter_card' - HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterSite: '@huh.head.tag.twitter_site' - HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterCreator: '@huh.head.tag.twitter_creator' - HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterTitle: '@huh.head.tag.twitter_title' - HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterDescription: '@huh.head.tag.twitter_description' - HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterImage: '@huh.head.tag.twitter_image' - HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterImageAlt: '@huh.head.tag.twitter_image_alt' - HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterPlayer: '@huh.head.tag.twitter_player' - HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterPlayerWidth: '@huh.head.tag.twitter_player_width' - HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterPlayerHeight: '@huh.head.tag.twitter_player_height' - HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterPlayerStream: '@huh.head.tag.twitter_player_stream' - HeimrichHannot\HeadBundle\Tag\Meta\Twitter\TwitterPlayerStreamContentType: '@huh.head.tag.twitter_player_stream_content_type' - HeimrichHannot\HeadBundle\Tag\Link\LinkPrev: '@huh.head.tag.link_prev' - HeimrichHannot\HeadBundle\Tag\Link\LinkNext: '@huh.head.tag.link_next' - HeimrichHannot\HeadBundle\Tag\Link\LinkCanonical: '@huh.head.tag.link_canonical' diff --git a/src/DependencyInjection/Compiler/AdjustContainerPass.php b/src/DependencyInjection/Compiler/AdjustContainerPass.php deleted file mode 100644 index 4fe1334..0000000 --- a/src/DependencyInjection/Compiler/AdjustContainerPass.php +++ /dev/null @@ -1,45 +0,0 @@ -processLegacy($container); - } - - /** - * @todo remove in next major version - * - * @noinspection PhpDeprecationInspection - */ - private function processLegacy(ContainerBuilder $container): void - { - $tags = []; - $definitions = $container->getDefinitions(); - - foreach ($definitions as $service => $definition) { - try { - $r = $container->getReflectionClass($definition->getClass()); - - if (null !== $r && $r->implementsInterface(TagInterface::class)) { - $tags[$definition->getClass()] = $service; - } - } catch (\Exception $e) { - } - } - - $container->setParameter('huh.head.tags', $tags); - } -} diff --git a/src/DependencyInjection/HeimrichHannotHeadBundleExtension.php b/src/DependencyInjection/HeimrichHannotHeadBundleExtension.php index 5da8631..f705d23 100644 --- a/src/DependencyInjection/HeimrichHannotHeadBundleExtension.php +++ b/src/DependencyInjection/HeimrichHannotHeadBundleExtension.php @@ -25,7 +25,6 @@ public function load(array $configs, ContainerBuilder $container): void $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../config')); $loader->load('services.yaml'); - $loader->load('tags.yaml'); if (class_exists(DisableCanonicalFieldsListener::class)) { $container->removeDefinition(CanonicalListener::class); diff --git a/src/EventListener/Contao/ParseTemplateListener.php b/src/EventListener/Contao/ParseTemplateListener.php index 3bcac85..a6d8a17 100644 --- a/src/EventListener/Contao/ParseTemplateListener.php +++ b/src/EventListener/Contao/ParseTemplateListener.php @@ -10,7 +10,6 @@ use Contao\CoreBundle\ServiceAnnotation\Hook; use Contao\Template; -use HeimrichHannot\HeadBundle\Helper\LegacyHelper; use HeimrichHannot\HeadBundle\Manager\HtmlHeadTagManager; /** @@ -40,10 +39,6 @@ protected function addLegacyMetaMethod(Template $template): void if (!($this->bundleConfig['use_contao_variables'] ?? false)) { $template->meta = function (array $skip = []) { - foreach ($skip as &$tag) { - $tag = LegacyHelper::mapServiceToTag($tag, $tag); - } - return $this->headTagManager->renderTags([ 'skip_tags' => $skip, ]); diff --git a/src/HeadTag/BaseTag.php b/src/HeadTag/BaseTag.php index 6c11ffe..5c19ed3 100644 --- a/src/HeadTag/BaseTag.php +++ b/src/HeadTag/BaseTag.php @@ -11,7 +11,6 @@ class BaseTag extends AbstractHeadTag { public const NAME = 'base'; - public const LEGACY_NAME = 'huh.head.tag.base'; public function __construct(string $href) { diff --git a/src/HeadTag/HeadTagFactory.php b/src/HeadTag/HeadTagFactory.php index a529b49..8f2ef42 100644 --- a/src/HeadTag/HeadTagFactory.php +++ b/src/HeadTag/HeadTagFactory.php @@ -11,7 +11,6 @@ use HeimrichHannot\HeadBundle\HeadTag\Meta\CharsetMetaTag; use HeimrichHannot\HeadBundle\HeadTag\Meta\HttpEquivMetaTag; use HeimrichHannot\HeadBundle\HeadTag\Meta\PropertyMetaTag; -use HeimrichHannot\HeadBundle\Helper\LegacyHelper; use HeimrichHannot\HeadBundle\Helper\TagHelper; class HeadTagFactory @@ -28,19 +27,9 @@ public function __construct(TagHelper $tagHelper) * For tags with multiple occurrences like meta, prefix name with tag name, * for example meta_ (meta_description, meta_og:title, ...) for meta tags. * - * Options: - * - skip_legacy_mapping: (bool) do not check for legacy tag service names */ - public function createTagByName(string $name, ?string $value = null, array $options = []): ?AbstractHeadTag + public function createTagByName(string $name, ?string $value = null): ?AbstractHeadTag { - $options = array_merge([ - 'skip_legacy_mapping' => false, - ], $options); - - if (!$options['skip_legacy_mapping']) { - $name = LegacyHelper::mapServiceToTag($name, $name); - } - if ('base' === $name) { return new BaseTag($value); } diff --git a/src/HeadTag/Link/CanonicalLink.php b/src/HeadTag/Link/CanonicalLink.php index 3e647d5..bea022d 100644 --- a/src/HeadTag/Link/CanonicalLink.php +++ b/src/HeadTag/Link/CanonicalLink.php @@ -13,7 +13,6 @@ class CanonicalLink extends LinkTag { public const TYPE = 'canonical'; - public const LEGACY_NAME = 'huh.head.tag.link.canonical'; public function __construct(string $href) { diff --git a/src/HeimrichHannotContaoHeadBundle.php b/src/HeimrichHannotContaoHeadBundle.php index 779bd4b..a3bfd18 100644 --- a/src/HeimrichHannotContaoHeadBundle.php +++ b/src/HeimrichHannotContaoHeadBundle.php @@ -8,29 +8,12 @@ namespace HeimrichHannot\HeadBundle; -use HeimrichHannot\HeadBundle\DependencyInjection\Compiler\AdjustContainerPass; use HeimrichHannot\HeadBundle\DependencyInjection\HeimrichHannotHeadBundleExtension; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; use Symfony\Component\HttpKernel\Bundle\Bundle; class HeimrichHannotContaoHeadBundle extends Bundle { - /** - * Builds the bundle. - * - * It is only ever called once when the cache is empty. - * - * This method can be overridden to register compilation passes, - * other extensions, ... - * - * @param ContainerBuilder $container A ContainerBuilder instance - */ - public function build(ContainerBuilder $container): void - { - $container->addCompilerPass(new AdjustContainerPass()); - } - public function getContainerExtension(): ?ExtensionInterface { return new HeimrichHannotHeadBundleExtension(); diff --git a/src/Helper/LegacyHelper.php b/src/Helper/LegacyHelper.php deleted file mode 100644 index e0e373b..0000000 --- a/src/Helper/LegacyHelper.php +++ /dev/null @@ -1,68 +0,0 @@ - 'base', - 'huh.head.tag.title' => 'title', - 'huh.head.tag.meta_date' => 'meta_date', - 'huh.head.tag.meta_language' => 'meta_language', - 'huh.head.tag.meta_charset' => 'meta_charset', - 'huh.head.tag.meta_title' => 'meta_title', - 'huh.head.tag.meta_description' => 'meta_description', - 'huh.head.tag.meta_keywords' => 'meta_keywords', - 'huh.head.tag.meta_robots' => 'meta_robots', - 'huh.head.tag.og_title' => 'meta_og:title', - 'huh.head.tag.og_type' => 'meta_og:type', - 'huh.head.tag.og_url' => 'meta_og:url', - 'huh.head.tag.og_description' => 'meta_og:description', - 'huh.head.tag.og_image' => 'meta_og:image', - 'huh.head.tag.og_locale' => 'meta_og:locale', - 'huh.head.tag.og_site_name' => 'meta_og:site_name', - 'huh.head.tag.twitter_card' => 'meta_twitter:card', - 'huh.head.tag.twitter_site' => 'meta_twitter:site', - 'huh.head.tag.twitter_creator' => 'meta_twitter:creator', - 'huh.head.tag.twitter_title' => 'meta_twitter:title', - 'huh.head.tag.twitter_description' => 'meta_twitter:description', - 'huh.head.tag.twitter_image' => 'meta_twitter:image', - 'huh.head.tag.twitter_image_alt' => 'meta_twitter:image:alt', - 'huh.head.tag.twitter_player' => 'meta_twitter:player', - 'huh.head.tag.twitter_player_width' => 'meta_twitter:player:width', - 'huh.head.tag.twitter_player_height' => 'meta_twitter:player:height', - 'huh.head.tag.twitter_player_stream' => 'meta_twitter:player:stream', - 'huh.head.tag.twitter_player_stream_content_type' => 'twitter:player:stream:content_type', - 'huh.head.tag.link_prev' => 'link_prev', - 'huh.head.tag.link_next' => 'link_next', - 'huh.head.tag.link_canonical' => 'link_canonical', - - // External bundles - // 'huh.head.tag.pwa.link_manifest' => 'link_manifest', - 'huh.head.tag.pwa.meta_themecolor' => 'meta_theme-color', - // 'huh.head.tag.pwa.script' => '', - ]; - - public static function mapTagToService(string $tag): ?string - { - if ($service = array_search($tag, static::SERVICE_MAP)) { - return $service; - } - - return null; - } - - public static function mapServiceToTag(string $service, $fallbackValue = null): ?string - { - return static::SERVICE_MAP[$service] ?? $fallbackValue; - } -} diff --git a/src/Manager/HtmlHeadTagManager.php b/src/Manager/HtmlHeadTagManager.php index 6c13d9f..9e6d785 100644 --- a/src/Manager/HtmlHeadTagManager.php +++ b/src/Manager/HtmlHeadTagManager.php @@ -18,12 +18,10 @@ use HeimrichHannot\HeadBundle\HeadTag\LinkTag; use HeimrichHannot\HeadBundle\HeadTag\MetaTag; use HeimrichHannot\HeadBundle\HeadTag\TitleTag; -use HeimrichHannot\HeadBundle\Helper\LegacyHelper; class HtmlHeadTagManager { private ?BaseTag $baseTag = null; - private TagManager $legacyTagManager; /** * @var MetaTag[] */ @@ -34,11 +32,9 @@ class HtmlHeadTagManager private InsertTagParser $insertTagParser; public function __construct( - TagManager $legacyTagManager, HeadTagFactory $headTagFactory, InsertTagParser $insertTagParser, ) { - $this->legacyTagManager = $legacyTagManager; $this->headTagFactory = $headTagFactory; $this->insertTagParser = $insertTagParser; } @@ -217,11 +213,6 @@ public function renderTags(array $options = []): string continue; } - if (\in_array(LegacyHelper::mapTagToService('meta_' . $metaTag->getName()), $options['skip_tags'])) { - unset($options['skip_tags'][LegacyHelper::mapTagToService('meta_' . $metaTag->getName())]); - - continue; - } $buffer .= $metaTag->generate() . "\n"; } @@ -232,20 +223,10 @@ public function renderTags(array $options = []): string continue; } - if (\in_array(LegacyHelper::mapTagToService('link_' . $linkTag->getName()), $options['skip_tags'])) { - unset($options['skip_tags'][LegacyHelper::mapTagToService('link_' . $linkTag->getName())]); - - continue; - } - $buffer .= $linkTag->generate() . "\n"; } - /* @noinspection PhpDeprecationInspection */ - return $buffer . implode("\n", $this->legacyTagManager->getTags(array_merge( - array_keys(LegacyHelper::SERVICE_MAP), - $options['skip_tags'] - ))); + return $buffer; } public function getHeadTagFactory(): HeadTagFactory @@ -253,11 +234,6 @@ public function getHeadTagFactory(): HeadTagFactory return $this->headTagFactory; } - public function getLegacyTagManager(): TagManager - { - return $this->legacyTagManager; - } - /** * Converts an input-encoded string to plain text UTF-8. * diff --git a/src/Manager/TagManager.php b/src/Manager/TagManager.php deleted file mode 100644 index 1f4527b..0000000 --- a/src/Manager/TagManager.php +++ /dev/null @@ -1,112 +0,0 @@ -container = $container; - $this->insertTagParser = $insertTagParser; - } - - public function registerTag(TagInterface $tag): void - { - /** - * @phpstan-ignore method.notFound - */ - $services = $this->container->getParameter('huh.head.tags'); - - $className = get_class($tag); - - if (!isset($services[$className])) { - return; - } - - $this->tags[$services[$className]] = $tag; - } - - public function hasTag(string $name): bool - { - return isset($this->tags[$name]); - } - - public function getTagInstance(string $name): ?TagInterface - { - return $this->tags[$name] ?? null; - } - - public function removeTag(string $name): void - { - if (isset($this->tags[$name])) { - unset($this->tags[$name]); - } - } - - public function loadTagFromService(string $name): ?TagInterface - { - /** - * @phpstan-ignore method.notFound - */ - $services = $this->container->getParameter('huh.head.tags'); - - if (!in_array($name, $services)) { - return null; - } - - if ($this->container->has($name)) { - return $this->container->get($name); - } - - return null; - } - - /** - * Get the generated tags as array. - * - * @param array $skip List of service ids that should be skipped - * - * @return array - * - * @deprecated Use HeadTagManager::renderTags instead - */ - public function getTags(array $skip = []) - { - $tags = []; - - foreach ($this->tags as $service => $tag) { - if (!$tag->hasContent()) { - continue; - } - - if (!empty($skip) && in_array($service, $skip)) { - continue; - } - - $tags[] = StringUtil::stripInsertTags($this->insertTagParser->replace($tag->generate())); - } - - return $tags; - } -} diff --git a/src/Tag/AbstractLinkTag.php b/src/Tag/AbstractLinkTag.php deleted file mode 100644 index 235e67b..0000000 --- a/src/Tag/AbstractLinkTag.php +++ /dev/null @@ -1,73 +0,0 @@ -get(HtmlHeadTagManager::class)->addLinkTag($tag); - } else { - parent::setContent($content); - } - } - - public function getContent(): ?string - { - if (isset(static::$name)) { - $tag = System::getContainer()->get(HtmlHeadTagManager::class)->getLinkTag(static::$name); - - if ($tag) { - return $tag->getAttributes()['href']; - } - - return null; - } - - return parent::getContent(); - } - - /** - * Generate the tag output. - * - * @return string - */ - public function generate() - { - return sprintf('<%s %s="%s" href="%s">', static::$tag, static::$key, static::$name, $this->escapeForHtmlAttribute($this->getContent())); - } -} diff --git a/src/Tag/AbstractMetaTag.php b/src/Tag/AbstractMetaTag.php deleted file mode 100644 index 334beaf..0000000 --- a/src/Tag/AbstractMetaTag.php +++ /dev/null @@ -1,80 +0,0 @@ -', static::$tag, static::$key, static::$name, $this->escapeForHtmlAttribute($this->getContent())); - } - - public function setContent($content): void - { - if (isset(static::$name)) { - if (null !== $content) { - if ('property' === static::$key) { - $tag = new PropertyMetaTag(static::$name, $content); - } else { - $tag = new MetaTag(static::$name, $content); - } - System::getContainer()->get(HtmlHeadTagManager::class)->addMetaTag($tag); - } else { - if ('property' === static::$key) { - $name = str_replace(':', '_', static::$name); - System::getContainer()->get(HtmlHeadTagManager::class)->removeMetaTag($name); - } else { - System::getContainer()->get(HtmlHeadTagManager::class)->removeMetaTag(static::$name); - } - } - } else { - parent::setContent($content); - } - } - - public function getContent() - { - if (isset(static::$name)) { - if ($tag = System::getContainer()->get(HtmlHeadTagManager::class)->getMetaTag(static::$name)) { - return $tag->getContent(); - } - - return null; - } - - return parent::getContent(); - } -} diff --git a/src/Tag/AbstractTag.php b/src/Tag/AbstractTag.php deleted file mode 100644 index 646c6ff..0000000 --- a/src/Tag/AbstractTag.php +++ /dev/null @@ -1,108 +0,0 @@ -manager = $manager; - $this->manager->registerTag($this); - } - - /** - * The tag content value. - * - * @param string $content - */ - public function setContent($content) - { - $this->content = $content; - } - - /** - * Check if content is set. - * - * @return bool - */ - public function hasContent() - { - return !empty($this->getContent()); - } - - /** - * Get the tag content value. - * - * @return string - */ - public function getContent() - { - return $this->content; - } - - /** - * Generate the tag output. - * - * @return string - */ - abstract public function generate(); - - /** - * Escapes double quotes. - */ - public function escapeForHtmlAttribute($content) - { - $insertTagParser = System::getContainer()->get('contao.insert_tag.parser'); - - return str_replace('"', '"', StringUtil::stripInsertTags($insertTagParser->replace($content))); - } -} diff --git a/src/Tag/Link/LinkCanonical.php b/src/Tag/Link/LinkCanonical.php deleted file mode 100644 index c22e199..0000000 --- a/src/Tag/Link/LinkCanonical.php +++ /dev/null @@ -1,24 +0,0 @@ -', static::$tag, static::$key, $this->escapeForHtmlAttribute($this->getContent())); - } - - public function setContent($content): void - { - if (null !== $content) { - $tag = new CharsetMetaTag($content); - System::getContainer()->get(HtmlHeadTagManager::class)->addMetaTag($tag); - } else { - System::getContainer()->get(HtmlHeadTagManager::class)->removeMetaTag(static::$name); - } - } - - public function getContent() - { - if ($tag = System::getContainer()->get(HtmlHeadTagManager::class)->getMetaTag('charset')) { - return $tag->getAttributes()['charset'] ?? null; - } - - return null; - } -} diff --git a/src/Tag/Meta/MetaDate.php b/src/Tag/Meta/MetaDate.php deleted file mode 100644 index 94c8e80..0000000 --- a/src/Tag/Meta/MetaDate.php +++ /dev/null @@ -1,24 +0,0 @@ -get('contao.insert_tag.parser'); - - $content = parent::getContent(); - - $content = StringUtil::decodeEntities($content); - $content = $insertTagParser->replace($content); - $content = strip_tags($content); - $content = str_replace("\n", ' ', $content); - $content = StringUtil::substr($content, 320); - - return sprintf( - '<%s %s="%s" content="%s">', - static::$tag, - static::$key, - static::$name, - $this->escapeForHtmlAttribute($content) - ); - } -} diff --git a/src/Tag/Meta/MetaKeywords.php b/src/Tag/Meta/MetaKeywords.php deleted file mode 100644 index fd6a3a7..0000000 --- a/src/Tag/Meta/MetaKeywords.php +++ /dev/null @@ -1,24 +0,0 @@ -get('contao.insert_tag.parser'); - - $content = parent::getContent(); - - $content = StringUtil::decodeEntities($content); - $content = $insertTagParser->replace($content); - $content = strip_tags($content); - $content = str_replace("\n", ' ', $content); - $content = StringUtil::substr($content, 320); - - return sprintf( - '<%s %s="%s" content="%s">', - static::$tag, - static::$key, - static::$name, - $this->escapeForHtmlAttribute($content) - ); - } -} diff --git a/src/Tag/Meta/OG/OGImage.php b/src/Tag/Meta/OG/OGImage.php deleted file mode 100644 index ef14c25..0000000 --- a/src/Tag/Meta/OG/OGImage.php +++ /dev/null @@ -1,31 +0,0 @@ -get('contao.insert_tag.parser'); - - $content = parent::getContent(); - - $content = StringUtil::decodeEntities($content); - $content = $insertTagParser->replace($content); - $content = strip_tags($content); - $content = str_replace("\n", ' ', $content); - $content = StringUtil::substr($content, 320); - - return sprintf( - '<%s %s="%s" content="%s">', - static::$tag, - static::$key, - static::$name, - $this->escapeForHtmlAttribute($content) - ); - } -} diff --git a/src/Tag/Meta/Twitter/TwitterImage.php b/src/Tag/Meta/Twitter/TwitterImage.php deleted file mode 100644 index cb53eaa..0000000 --- a/src/Tag/Meta/Twitter/TwitterImage.php +++ /dev/null @@ -1,24 +0,0 @@ -get(HtmlHeadTagManager::class)->setBaseTag($content); - } - - public function getContent() - { - if (($baseTag = System::getContainer()->get(HtmlHeadTagManager::class)->getBaseTag()) - && $baseTag->hasAttribute('href')) { - return $baseTag->getAttributes()['href']; - } - - return null; - } - - /** - * Generate the tag output. - * - * @return string - */ - public function generate() - { - return sprintf('', $this->escapeForHtmlAttribute($this->getContent())); - } -} diff --git a/src/Tag/Misc/Title.php b/src/Tag/Misc/Title.php deleted file mode 100644 index 8f53ecc..0000000 --- a/src/Tag/Misc/Title.php +++ /dev/null @@ -1,31 +0,0 @@ -%s', - htmlentities($this->getContent(), ENT_COMPAT, Config::get('characterSet')) - ); - } -} diff --git a/src/Tag/TagInterface.php b/src/Tag/TagInterface.php deleted file mode 100644 index 8fce8bb..0000000 --- a/src/Tag/TagInterface.php +++ /dev/null @@ -1,43 +0,0 @@ - Date: Wed, 13 May 2026 16:08:04 +0200 Subject: [PATCH 2/2] fix exception --- config/services.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index de6fb59..583dc87 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -2,8 +2,6 @@ services: _defaults: autowire: true autoconfigure: true - bind: - Psr\Container\ContainerInterface: '@service_container' HeimrichHannot\HeadBundle\: resource: '../src/{EventListener,Helper}/*'