Skip to content

WIP: Add head_shortcut_icon_absolute and header_logo_src_absolute fields t… #33577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ThemeGraphQl\Model\Resolver;

use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\Value;
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
use Magento\Theme\Model\Favicon\Favicon;

class HeadShortcutIconResolver implements ResolverInterface
{
/**
* @var ValueFactory
*/
private $valueFactory;

/**
* @var Favicon
*/
private $favicon;

/**
* @param ValueFactory $valueFactory
*/
public function __construct(ValueFactory $valueFactory, Favicon $favicon)
{
$this->valueFactory = $valueFactory;
$this->favicon = $favicon;
}

/**
* Fetch and format configurable variants.
*
* {@inheritdoc}
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
$result = function () {
$value = $this->favicon->getFaviconFile();
if ($value === false) {
$value = null;
}
return $value;
};

return $this->valueFactory->create($result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ThemeGraphQl\Model\Resolver;

use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\Value;
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
use Magento\Theme\Block\Html\Header\Logo;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Api\Data\StoreConfigInterface;
use Magento\Store\Api\StoreConfigManagerInterface;
use Magento\Store\Model\ResourceModel\StoreWebsiteRelation;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Api\Data\StoreInterface;

class HeaderLogoSrcResolver implements ResolverInterface
{
/**
* @var ValueFactory
*/
private $valueFactory;

/**
* @var Logo
*/
private $logoBlock;

/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* @param ValueFactory $valueFactory
*/
public function __construct(ValueFactory $valueFactory, ScopeConfigInterface $scopeConfig, Logo $logoBlock)
{
$this->valueFactory = $valueFactory;
$this->scopeConfig = $scopeConfig;
$this->logoBlock = $logoBlock;
}

/**
* Fetch and format configurable variants.
*
* {@inheritdoc}
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
$result = function () use ($context) {
$storeId = $context->getExtensionAttributes()->getStore()->getId();

$logoSrc = $this->scopeConfig->getValue(
'design/header/logo_src',
ScopeInterface::SCOPE_STORE,
$storeId
);

// Get the full path
if ($logoSrc !== null) {
$logoSrc = $this->logoBlock->getLogoSrc();
}
return $logoSrc;
};

return $this->valueFactory->create($result);
}
}
12 changes: 12 additions & 0 deletions app/code/Magento/ThemeGraphQl/etc/graphql/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@
<type name="Magento\Framework\Data\Collection">
<plugin name="currentPageDetection" disabled="true"/>
</type>
<virtualType name="graphQlLogo" type="Magento\Theme\Block\Html\Header\Logo">
<arguments>
<argument name="data" xsi:type="array">
<item name="logoPathResolver" xsi:type="object">Magento\Theme\ViewModel\Block\Html\Header\LogoPathResolver</item>
</argument>
</arguments>
</virtualType>
<type name="Magento\ThemeGraphQl\Model\Resolver\HeaderLogoSrcResolver">
<arguments>
<argument name="logoBlock" xsi:type="object">graphQlLogo</argument>
</arguments>
</type>
</config>
2 changes: 2 additions & 0 deletions app/code/Magento/ThemeGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ type StoreConfig @doc(description: "The type contains information about a store
logo_alt : String @doc(description: "Logo Image Alt")
absolute_footer : String @doc(description: "Footer Miscellaneous HTML")
copyright : String @doc(description: "Copyright")
head_shortcut_icon_absolute : String @doc(description: "Favicon Icon with an absolute url") @resolver(class: "Magento\\ThemeGraphQl\\Model\\Resolver\\HeadShortcutIconResolver")
header_logo_src_absolute : String @doc(description: "Logo Image with an absolute url") @resolver(class: "Magento\\ThemeGraphQl\\Model\\Resolver\\HeaderLogoSrcResolver")
}