local/modules/CanonicalUrl/Hook/SeoUpdateFormHook.php line 22

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Thelia package.
  4.  * http://www.thelia.net
  5.  *
  6.  * (c) OpenStudio <info@thelia.net>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace CanonicalUrl\Hook;
  12. use CanonicalUrl\CanonicalUrl;
  13. use Thelia\Core\Event\Hook\HookRenderEvent;
  14. use Thelia\Core\Hook\BaseHook;
  15. use Thelia\Model\MetaDataQuery;
  16. class SeoUpdateFormHook extends BaseHook
  17. {
  18.     public function addInputs(HookRenderEvent $event): void
  19.     {
  20.         $id $event->getArgument('id');
  21.         $type $event->getArgument('type');
  22.         $canonical null;
  23.         $canonicalMetaData MetaDataQuery::create()
  24.             ->filterByMetaKey(CanonicalUrl::SEO_CANONICAL_META_KEY)
  25.             ->filterByElementKey($type)
  26.             ->filterByElementId($id)
  27.             ->findOneOrCreate();
  28.         $canonicalMetaDataValues json_decode($canonicalMetaData->getValue(), true);
  29.         $lang $this->getSession()->getAdminEditionLang();
  30.         if (isset($canonicalMetaDataValues[$lang->getLocale()])) {
  31.             $canonical $canonicalMetaDataValues[$lang->getLocale()];
  32.         }
  33.         $event->add($this->render(
  34.             'hook-seo-update-form.html',
  35.             [
  36.                 'form' => $event->getArgument('form'),
  37.                 'canonical' => $canonical,
  38.             ]
  39.         ));
  40.     }
  41. }