diff --git a/Model/BlogArchiveTypeResolver.php b/Model/BlogArchiveTypeResolver.php index 8866d11..cd444e6 100644 --- a/Model/BlogArchiveTypeResolver.php +++ b/Model/BlogArchiveTypeResolver.php @@ -15,8 +15,8 @@ */ class BlogArchiveTypeResolver implements TypeResolverInterface { - const MF_BLOG_ARCHIVE = 'MF_BLOG_ARCHIVE'; - const TYPE_RESOLVER = 'blogPostsOutput'; + private const MF_BLOG_ARCHIVE = 'MF_BLOG_ARCHIVE'; + private const TYPE_RESOLVER = 'blogPostsOutput'; /** * @inheritdoc diff --git a/Model/BlogAuthorTypeResolver.php b/Model/BlogAuthorTypeResolver.php index b350db9..b2c89e3 100644 --- a/Model/BlogAuthorTypeResolver.php +++ b/Model/BlogAuthorTypeResolver.php @@ -15,8 +15,8 @@ */ class BlogAuthorTypeResolver implements TypeResolverInterface { - const MF_BLOG_AUTHOR = 'MF_BLOG_AUTHOR'; - const TYPE_RESOLVER = 'BlogAuthor'; + private const MF_BLOG_AUTHOR = 'MF_BLOG_AUTHOR'; + private const TYPE_RESOLVER = 'BlogAuthor'; /** * @inheritdoc diff --git a/Model/BlogCategoryTypeResolver.php b/Model/BlogCategoryTypeResolver.php index 7975db7..95bef94 100644 --- a/Model/BlogCategoryTypeResolver.php +++ b/Model/BlogCategoryTypeResolver.php @@ -15,8 +15,8 @@ */ class BlogCategoryTypeResolver implements TypeResolverInterface { - const MF_BLOG_CATEGORY = 'MF_BLOG_CATEGORY'; - const TYPE_RESOLVER = 'BlogCategory'; + private const MF_BLOG_CATEGORY = 'MF_BLOG_CATEGORY'; + private const TYPE_RESOLVER = 'BlogCategory'; /** * @inheritdoc diff --git a/Model/BlogIndexTypeResolver.php b/Model/BlogIndexTypeResolver.php index 03ec57c..e51ac0a 100644 --- a/Model/BlogIndexTypeResolver.php +++ b/Model/BlogIndexTypeResolver.php @@ -15,8 +15,8 @@ */ class BlogIndexTypeResolver implements TypeResolverInterface { - const MF_BLOG_INDEX = 'MF_BLOG_INDEX'; - const TYPE_RESOLVER = 'blogPostsOutput'; + private const MF_BLOG_INDEX = 'MF_BLOG_INDEX'; + private const TYPE_RESOLVER = 'blogPostsOutput'; /** * @inheritdoc diff --git a/Model/BlogPostTypeResolver.php b/Model/BlogPostTypeResolver.php index 9118d3f..15adf56 100644 --- a/Model/BlogPostTypeResolver.php +++ b/Model/BlogPostTypeResolver.php @@ -15,8 +15,8 @@ */ class BlogPostTypeResolver implements TypeResolverInterface { - const MF_BLOG_POST = 'MF_BLOG_POST'; - const TYPE_RESOLVER = 'BlogPost'; + private const MF_BLOG_POST = 'MF_BLOG_POST'; + private const TYPE_RESOLVER = 'BlogPost'; /** * @inheritdoc diff --git a/Model/BlogSearchTypeResolver.php b/Model/BlogSearchTypeResolver.php index 25bb3f5..7177eeb 100644 --- a/Model/BlogSearchTypeResolver.php +++ b/Model/BlogSearchTypeResolver.php @@ -15,8 +15,8 @@ */ class BlogSearchTypeResolver implements TypeResolverInterface { - const MF_BLOG_SEARCH = 'MF_BLOG_SEARCH'; - const TYPE_RESOLVER = 'blogPostsOutput'; + private const MF_BLOG_SEARCH = 'MF_BLOG_SEARCH'; + private const TYPE_RESOLVER = 'blogPostsOutput'; /** * @inheritdoc diff --git a/Model/BlogTagTypeResolver.php b/Model/BlogTagTypeResolver.php index c36e6ae..451c694 100644 --- a/Model/BlogTagTypeResolver.php +++ b/Model/BlogTagTypeResolver.php @@ -15,8 +15,8 @@ */ class BlogTagTypeResolver implements TypeResolverInterface { - const MF_BLOG_TAG = 'MF_BLOG_TAG'; - const TYPE_RESOLVER = 'BlogTag'; + private const MF_BLOG_TAG = 'MF_BLOG_TAG'; + private const TYPE_RESOLVER = 'BlogTag'; /** * @inheritdoc diff --git a/Model/Categories/FilterArgument.php b/Model/Categories/FilterArgument.php index 5421520..e9264f8 100755 --- a/Model/Categories/FilterArgument.php +++ b/Model/Categories/FilterArgument.php @@ -10,10 +10,6 @@ use Magento\Framework\GraphQl\Query\Resolver\Argument\FieldEntityAttributesInterface; use Magento\Framework\GraphQl\ConfigInterface; -/** - * Class FilterArgument - * @package Magefan\BlogGraphQl\Model\Categories - */ class FilterArgument implements FieldEntityAttributesInterface { /** @var ConfigInterface */ diff --git a/Model/Comments/FilterArgument.php b/Model/Comments/FilterArgument.php index cafef39..6e49290 100755 --- a/Model/Comments/FilterArgument.php +++ b/Model/Comments/FilterArgument.php @@ -10,10 +10,6 @@ use Magento\Framework\GraphQl\Query\Resolver\Argument\FieldEntityAttributesInterface; use Magento\Framework\GraphQl\ConfigInterface; -/** - * Class FilterArgument - * @package Magefan\BlogGraphQl\Model\Comments - */ class FilterArgument implements FieldEntityAttributesInterface { /** @var ConfigInterface */ diff --git a/Model/Posts/FilterArgument.php b/Model/Posts/FilterArgument.php index d030954..45d5afd 100755 --- a/Model/Posts/FilterArgument.php +++ b/Model/Posts/FilterArgument.php @@ -10,10 +10,6 @@ use Magento\Framework\GraphQl\Query\Resolver\Argument\FieldEntityAttributesInterface; use Magento\Framework\GraphQl\ConfigInterface; -/** - * Class FilterArgument - * @package Magefan\BlogGraphQl\Model\Posts - */ class FilterArgument implements FieldEntityAttributesInterface { /** @var ConfigInterface */ diff --git a/Model/Resolver/AddCommentToPost.php b/Model/Resolver/AddCommentToPost.php index e592eb9..a74d098 100644 --- a/Model/Resolver/AddCommentToPost.php +++ b/Model/Resolver/AddCommentToPost.php @@ -22,9 +22,6 @@ use Magento\Store\Model\ScopeInterface; use Magento\Framework\Exception\NoSuchEntityException; -/** - * Class AddCommentToPost - */ class AddCommentToPost implements ResolverInterface { /** @@ -69,7 +66,7 @@ public function __construct( /** * @inheritdoc */ - public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) + public function resolve(Field $field, $context, ResolveInfo $info, ?array $value = null, ?array $args = null) { if (!$this->scopeConfig->getValue(Config::XML_PATH_EXTENSION_ENABLED, ScopeInterface::SCOPE_STORE)) { throw new GraphQlNoSuchEntityException(__( @@ -150,7 +147,9 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value } if (!$parentComment->isActive()) { - throw new GraphQlNoSuchEntityException(__('You cannot reply to this comment. Comment is not longer exist.')); + throw new GraphQlNoSuchEntityException( + __('You cannot reply to this comment. Comment is not longer exist.') + ); } if (!$parentComment->getPost() || $parentComment->getPost()->getId() != $post->getId() diff --git a/Model/Resolver/Author.php b/Model/Resolver/Author.php index 5184e33..7a26fde 100755 --- a/Model/Resolver/Author.php +++ b/Model/Resolver/Author.php @@ -14,10 +14,6 @@ use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; -/** - * Class Author - * @package Magefan\BlogGraphQl\Model\Resolver - */ class Author implements ResolverInterface { /** @@ -41,8 +37,8 @@ public function resolve( Field $field, $context, ResolveInfo $info, - array $value = null, - array $args = null + ?array $value = null, + ?array $args = null ) { $authorId = $this->getAuthorId($args); $authorData = $this->getAuthorData($authorId); @@ -50,6 +46,8 @@ public function resolve( } /** + * Get author id + * * @param array $args * @return string * @throws GraphQlInputException @@ -64,6 +62,8 @@ private function getAuthorId(array $args): string } /** + * Get author data + * * @param string $authorId * @return array * @throws GraphQlNoSuchEntityException diff --git a/Model/Resolver/Categories.php b/Model/Resolver/Categories.php index 028cb8c..73cad3b 100644 --- a/Model/Resolver/Categories.php +++ b/Model/Resolver/Categories.php @@ -16,10 +16,6 @@ use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magefan\Blog\Api\CategoryRepositoryInterface; -/** - * Class Categories - * @package Magefan\BlogGraphQl\Model\Resolver - */ class Categories implements ResolverInterface { /** @@ -80,8 +76,8 @@ public function resolve( Field $field, $context, ResolveInfo $info, - array $value = null, - array $args = null + ?array $value = null, + ?array $args = null ) { $searchCriteria = $this->searchCriteriaBuilder->build('magefan_blog_categories', $args); $statusFilter = $this->filterBuilder @@ -97,7 +93,7 @@ public function resolve( $scopeFilter = $this->filterBuilder ->setField('store_id') - ->setValue($scope) + ->setValue($args['storeId'] ?? $scope) ->setConditionType('eq') ->create(); $filterGroups[] = $this->filterGroupBuilder->addFilter($scopeFilter)->create(); diff --git a/Model/Resolver/Category.php b/Model/Resolver/Category.php index e91595f..5d0c202 100755 --- a/Model/Resolver/Category.php +++ b/Model/Resolver/Category.php @@ -14,10 +14,6 @@ use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; -/** - * Class Category - * @package Magefan\BlogGraphQl\Model\Resolver - */ class Category implements ResolverInterface { /** @@ -42,8 +38,8 @@ public function resolve( Field $field, $context, ResolveInfo $info, - array $value = null, - array $args = null + ?array $value = null, + ?array $args = null ) { $categoryId = $this->getCategoryId($args); $fields = $info ? $info->getFieldSelection(10) : null; @@ -58,6 +54,8 @@ public function resolve( } /** + * Get category id + * * @param array $args * @return string * @throws GraphQlInputException diff --git a/Model/Resolver/Comments.php b/Model/Resolver/Comments.php index 22b23e6..398e73b 100755 --- a/Model/Resolver/Comments.php +++ b/Model/Resolver/Comments.php @@ -17,10 +17,6 @@ use Magefan\Blog\Api\CommentRepositoryInterface; use Magento\Framework\Api\SortOrderBuilder; -/** - * Class Comments - * @package Magefan\BlogGraphQl\Model\Resolver - */ class Comments implements ResolverInterface { /** @@ -84,8 +80,8 @@ public function resolve( Field $field, $context, ResolveInfo $info, - array $value = null, - array $args = null + ?array $value = null, + ?array $args = null ) { $parentIdFilter = $this->filterBuilder ->setField('parent_id') diff --git a/Model/Resolver/DataProvider/Author.php b/Model/Resolver/DataProvider/Author.php index 1f9ad59..3e4582d 100755 --- a/Model/Resolver/DataProvider/Author.php +++ b/Model/Resolver/DataProvider/Author.php @@ -10,24 +10,15 @@ use Magefan\Blog\Api\AuthorRepositoryInterface; use Magento\Framework\App\Area; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\ScopeResolverInterface; use Magento\Framework\App\State; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\View\DesignInterface; use Magento\Framework\View\Design\Theme\ThemeProviderInterface; use Magento\Store\Model\ScopeInterface; -use Magento\Widget\Model\Template\FilterEmulate; -/** - * Class Author - * @package Magefan\BlogGraphQl\Model\Resolver\DataProvider - */ class Author { - /** - * @var FilterEmulate - */ - private $widgetFilter; - /** * @var AuthorRepositoryInterface */ @@ -53,32 +44,39 @@ class Author */ private $scopeConfig; + /** + * @var ScopeResolverInterface + */ + private $scopeResolver; + /** * Author constructor. * @param AuthorRepositoryInterface $authorRepository - * @param FilterEmulate $widgetFilter * @param State $state * @param DesignInterface $design * @param ThemeProviderInterface $themeProvider * @param ScopeConfigInterface $scopeConfig + * @param ScopeResolverInterface $scopeResolver */ public function __construct( AuthorRepositoryInterface $authorRepository, - FilterEmulate $widgetFilter, State $state, DesignInterface $design, ThemeProviderInterface $themeProvider, - ScopeConfigInterface $scopeConfig + ScopeConfigInterface $scopeConfig, + ScopeResolverInterface $scopeResolver ) { $this->authorRepository = $authorRepository; - $this->widgetFilter = $widgetFilter; $this->state = $state; $this->design = $design; $this->themeProvider = $themeProvider; $this->scopeConfig = $scopeConfig; + $this->scopeResolver = $scopeResolver; } /** + * Get author data + * * @param string $authorId * @return array * @throws NoSuchEntityException @@ -114,8 +112,9 @@ function () use ($author, &$data) { /** * Prepare all additional data - * @param $author - * @param null $fields + * + * @param mixed $author + * @param mixed $fields * @return mixed */ public function getDynamicData($author, $fields = null) @@ -138,11 +137,18 @@ public function getDynamicData($author, $fields = null) foreach ($keys as $key) { $method = 'get' . str_replace( - '_', - '', - ucwords($key, '_') - ); + '_', + '', + ucwords($key, '_') + ); $data[$key] = $author->$method(); + if ($key === 'author_url') { + $data[$key] = str_replace( + '/' . $this->scopeResolver->getScope()->getCode() . '/', + '/', + $data[$key] + ); + } } return $data; diff --git a/Model/Resolver/DataProvider/Category.php b/Model/Resolver/DataProvider/Category.php index 1c9c8f0..f81fa53 100755 --- a/Model/Resolver/DataProvider/Category.php +++ b/Model/Resolver/DataProvider/Category.php @@ -15,19 +15,10 @@ use Magento\Framework\View\DesignInterface; use Magento\Framework\View\Design\Theme\ThemeProviderInterface; use Magento\Store\Model\ScopeInterface; -use Magento\Widget\Model\Template\FilterEmulate; +use Magento\Framework\App\ScopeResolverInterface; -/** - * Class Category - * @package Magefan\BlogGraphQl\Model\Resolver\DataProvider - */ class Category { - /** - * @var FilterEmulate - */ - private $widgetFilter; - /** * @var CategoryRepositoryInterface */ @@ -53,34 +44,41 @@ class Category */ private $scopeConfig; + /** + * @var ScopeResolverInterface + */ + private $scopeResolver; + /** * Category constructor. * @param CategoryRepositoryInterface $categoryRepository - * @param FilterEmulate $widgetFilter * @param State $state * @param DesignInterface $design * @param ThemeProviderInterface $themeProvider * @param ScopeConfigInterface $scopeConfig + * @param ScopeResolverInterface $scopeResolver */ public function __construct( CategoryRepositoryInterface $categoryRepository, - FilterEmulate $widgetFilter, State $state, DesignInterface $design, ThemeProviderInterface $themeProvider, - ScopeConfigInterface $scopeConfig + ScopeConfigInterface $scopeConfig, + ScopeResolverInterface $scopeResolver ) { $this->categoryRepository = $categoryRepository; - $this->widgetFilter = $widgetFilter; $this->state = $state; $this->design = $design; $this->themeProvider = $themeProvider; $this->scopeConfig = $scopeConfig; + $this->scopeResolver = $scopeResolver; } /** + * Get category data + * * @param string $categoryId - * @param null $fields + * @param null|array $fields * @return array * @throws NoSuchEntityException */ @@ -115,8 +113,9 @@ function () use ($category, $fields, &$data) { /** * Prepare all additional data - * @param $category - * @param null $fields + * + * @param mixed $category + * @param null|array $fields * @return mixed */ public function getDynamicData($category, $fields = null) @@ -131,11 +130,18 @@ public function getDynamicData($category, $fields = null) foreach ($keys as $key) { $method = 'get' . str_replace( - '_', - '', - ucwords($key, '_') - ); + '_', + '', + ucwords($key, '_') + ); $data[$key] = $category->$method(); + if ($key === 'category_url') { + $data[$key] = str_replace( + '/' . $this->scopeResolver->getScope()->getCode() . '/', + '/', + $data[$key] + ); + } } if (is_array($fields) && array_key_exists('breadcrumbs', $fields)) { diff --git a/Model/Resolver/DataProvider/Comment.php b/Model/Resolver/DataProvider/Comment.php index cf320a7..d102f9e 100644 --- a/Model/Resolver/DataProvider/Comment.php +++ b/Model/Resolver/DataProvider/Comment.php @@ -17,9 +17,6 @@ use Magento\Store\Model\ScopeInterface; use Magento\Widget\Model\Template\FilterEmulate; -/** - * Class Comment - */ class Comment { /** @@ -68,8 +65,7 @@ public function __construct( DesignInterface $design, ThemeProviderInterface $themeProvider, ScopeConfigInterface $scopeConfig - ) - { + ) { $this->commentRepository = $commentRepository; $this->widgetFilter = $widgetFilter; $this->state = $state; @@ -79,8 +75,10 @@ public function __construct( } /** + * Get comment data + * * @param string $commentId - * @param null $fields + * @param null|array $fields * @return array * @throws NoSuchEntityException */ @@ -115,8 +113,9 @@ function () use ($comment, $fields, &$data) { /** * Prepare all additional data - * @param $comment - * @param null $fields + * + * @param mixed $comment + * @param null|array $fields * @return mixed */ public function getDynamicData($comment, $fields = null) diff --git a/Model/Resolver/DataProvider/Post.php b/Model/Resolver/DataProvider/Post.php index bce92ff..bc9709b 100755 --- a/Model/Resolver/DataProvider/Post.php +++ b/Model/Resolver/DataProvider/Post.php @@ -11,24 +11,15 @@ use Magefan\Blog\Model\Config; use Magento\Framework\App\Area; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\ScopeResolverInterface; use Magento\Framework\App\State; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\View\DesignInterface; use Magento\Framework\View\Design\Theme\ThemeProviderInterface; use Magento\Store\Model\ScopeInterface; -use Magento\Widget\Model\Template\FilterEmulate; -/** - * Class Post - * @package Magefan\BlogGraphQl\Model\Resolver\DataProvider - */ class Post { - /** - * @var FilterEmulate - */ - private $widgetFilter; - /** * @var Tag */ @@ -69,10 +60,14 @@ class Post */ private $scopeConfig; + /** + * @var ScopeResolverInterface + */ + private $scopeResolver; + /** * Post constructor. * @param PostRepositoryInterface $postRepository - * @param FilterEmulate $widgetFilter * @param Tag $tagDataProvider * @param Category $categoryDataProvider * @param Author $authorDataProvider @@ -80,20 +75,20 @@ class Post * @param DesignInterface $design * @param ThemeProviderInterface $themeProvider * @param ScopeConfigInterface $scopeConfig + * @param ScopeResolverInterface $scopeResolver */ public function __construct( PostRepositoryInterface $postRepository, - FilterEmulate $widgetFilter, Tag $tagDataProvider, Category $categoryDataProvider, Author $authorDataProvider, State $state, DesignInterface $design, ThemeProviderInterface $themeProvider, - ScopeConfigInterface $scopeConfig + ScopeConfigInterface $scopeConfig, + ScopeResolverInterface $scopeResolver ) { $this->postRepository = $postRepository; - $this->widgetFilter = $widgetFilter; $this->tagDataProvider = $tagDataProvider; $this->categoryDataProvider = $categoryDataProvider; $this->authorDataProvider = $authorDataProvider; @@ -101,11 +96,15 @@ public function __construct( $this->design = $design; $this->themeProvider = $themeProvider; $this->scopeConfig = $scopeConfig; + $this->scopeResolver = $scopeResolver; } /** + * Get post data + * * @param string $postId * @param array|null $fields + * @param null|int|string $storeId * @return array * @throws NoSuchEntityException */ @@ -128,7 +127,7 @@ function () use ($post, $fields, &$data, $storeId) { ); $theme = $this->themeProvider->getThemeById($themeId); $this->design->setDesignTheme($theme, Area::AREA_FRONTEND); - $post->setStoreId($storeId); + $post->setStoreId((int)$storeId); $data = $this->getDynamicData($post, $fields); return $data; @@ -140,7 +139,8 @@ function () use ($post, $fields, &$data, $storeId) { /** * Prepare all additional data - * @param $post + * + * @param mixed $post * @param null|array $fields * @return array */ @@ -166,11 +166,18 @@ public function getDynamicData($post, $fields = null) foreach ($keys as $key) { if (null === $fields || array_key_exists($key, $fields)) { $method = 'get' . str_replace( - '_', - '', - ucwords($key, '_') - ); + '_', + '', + ucwords($key, '_') + ); $data[$key] = $post->$method(); + if ($key === 'post_url') { + $data[$key] = str_replace( + '/' . $this->scopeResolver->getScope()->getCode() . '/', + '/', + $data[$key] + ); + } } } @@ -179,7 +186,7 @@ public function getDynamicData($post, $fields = null) foreach ($post->getRelatedTags() as $tag) { $tags[] = $this->tagDataProvider->getDynamicData( $tag - // isset($fields['tags']) ? $fields['tags'] : null + // isset($fields['tags']) ? $fields['tags'] : null ); } $data['tags'] = $tags; @@ -254,7 +261,7 @@ public function getDynamicData($post, $fields = null) if ($author = $post->getAuthor()) { $data['author'] = $this->authorDataProvider->getDynamicData( $author - //isset($fields['author']) ? $fields['author'] : null + //isset($fields['author']) ? $fields['author'] : null ); } } diff --git a/Model/Resolver/DataProvider/Tag.php b/Model/Resolver/DataProvider/Tag.php index 904c160..cfc6bc3 100755 --- a/Model/Resolver/DataProvider/Tag.php +++ b/Model/Resolver/DataProvider/Tag.php @@ -10,23 +10,14 @@ use Magefan\Blog\Api\TagRepositoryInterface; use Magento\Framework\App\Area; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\ScopeResolverInterface; use Magento\Framework\App\State; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\View\DesignInterface; use Magento\Framework\View\Design\Theme\ThemeProviderInterface; -use Magento\Widget\Model\Template\FilterEmulate; -/** - * Class Tag - * @package Magefan\BlogGraphQl\Model\Resolver\DataProvider - */ class Tag { - /** - * @var FilterEmulate - */ - private $widgetFilter; - /** * @var TagRepositoryInterface */ @@ -52,32 +43,39 @@ class Tag */ private $scopeConfig; + /** + * @var ScopeResolverInterface + */ + private $scopeResolver; + /** * Tag constructor. * @param TagRepositoryInterface $tagRepository - * @param FilterEmulate $widgetFilter * @param State $state * @param DesignInterface $design * @param ThemeProviderInterface $themeProvider * @param ScopeConfigInterface $scopeConfig + * @param ScopeResolverInterface $scopeResolver */ public function __construct( TagRepositoryInterface $tagRepository, - FilterEmulate $widgetFilter, State $state, DesignInterface $design, ThemeProviderInterface $themeProvider, - ScopeConfigInterface $scopeConfig + ScopeConfigInterface $scopeConfig, + ScopeResolverInterface $scopeResolver ) { $this->tagRepository = $tagRepository; - $this->widgetFilter = $widgetFilter; $this->state = $state; $this->design = $design; $this->themeProvider = $themeProvider; $this->scopeConfig = $scopeConfig; + $this->scopeResolver = $scopeResolver; } /** + * Get tag data + * * @param string $tagId * @return array * @throws NoSuchEntityException @@ -113,8 +111,9 @@ function () use ($tag, &$data) { /** * Prepare all additional data - * @param $tag - * @param null $fields + * + * @param mixed $tag + * @param null|array $fields * @return mixed */ public function getDynamicData($tag, $fields = null) @@ -129,11 +128,18 @@ public function getDynamicData($tag, $fields = null) foreach ($keys as $key) { $method = 'get' . str_replace( - '_', - '', - ucwords($key, '_') - ); + '_', + '', + ucwords($key, '_') + ); $data[$key] = $tag->$method(); + if ($key === 'tag_url') { + $data[$key] = str_replace( + '/' . $this->scopeResolver->getScope()->getCode() . '/', + '/', + $data[$key] + ); + } } return $data; diff --git a/Model/Resolver/Post.php b/Model/Resolver/Post.php index 2906869..0355be8 100755 --- a/Model/Resolver/Post.php +++ b/Model/Resolver/Post.php @@ -14,10 +14,6 @@ use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; -/** - * Class Post - * @package Magefan\BlogGraphQl\Model\Resolver - */ class Post implements ResolverInterface { /** @@ -41,8 +37,8 @@ public function resolve( Field $field, $context, ResolveInfo $info, - array $value = null, - array $args = null + ?array $value = null, + ?array $args = null ) { $storeId = (int)$context->getExtensionAttributes()->getStore()->getId(); $postId = $this->getPostId($args); @@ -58,6 +54,8 @@ public function resolve( } /** + * Get post id + * * @param array $args * @return string * @throws GraphQlInputException diff --git a/Model/Resolver/Posts.php b/Model/Resolver/Posts.php index 968ace3..7c2281b 100755 --- a/Model/Resolver/Posts.php +++ b/Model/Resolver/Posts.php @@ -18,10 +18,6 @@ use Magento\Framework\Api\SortOrderBuilder; use Magento\Framework\App\ScopeResolverInterface; -/** - * Class Posts - * @package Magefan\BlogGraphQl\Model\Resolver - */ class Posts implements ResolverInterface { /** @@ -90,8 +86,8 @@ public function resolve( Field $field, $context, ResolveInfo $info, - array $value = null, - array $args = null + ?array $value = null, + ?array $args = null ) { $storeId = (int)$context->getExtensionAttributes()->getStore()->getId(); $searchCriteria = $this->searchCriteriaBuilder->build('di_build_magefan_blog_post', $args); @@ -108,7 +104,7 @@ public function resolve( $scopeFilter = $this->filterBuilder ->setField('store_id') - ->setValue($scope) + ->setValue($args['storeId'] ?? $scope) ->setConditionType('eq') ->create(); $filterGroups[] = $this->filterGroupBuilder->addFilter($scopeFilter)->create(); diff --git a/Model/Resolver/Tag.php b/Model/Resolver/Tag.php index cc3f100..46bb778 100755 --- a/Model/Resolver/Tag.php +++ b/Model/Resolver/Tag.php @@ -14,10 +14,6 @@ use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; -/** - * Class Tag - * @package Magefan\BlogGraphQl\Model\Resolver - */ class Tag implements ResolverInterface { /** @@ -41,8 +37,8 @@ public function resolve( Field $field, $context, ResolveInfo $info, - array $value = null, - array $args = null + ?array $value = null, + ?array $args = null ) { $tagId = $this->getTagId($args); $tagData = $this->getTagData($tagId); @@ -50,6 +46,8 @@ public function resolve( } /** + * Get tag id + * * @param array $args * @return string * @throws GraphQlInputException @@ -64,6 +62,8 @@ private function getTagId(array $args): string } /** + * Get tag data + * * @param string $tagId * @return array * @throws GraphQlNoSuchEntityException diff --git a/Model/Resolver/Tags.php b/Model/Resolver/Tags.php index b0b7233..303d9e9 100644 --- a/Model/Resolver/Tags.php +++ b/Model/Resolver/Tags.php @@ -16,10 +16,6 @@ use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magefan\Blog\Api\TagRepositoryInterface; -/** - * Class Tags - * @package Magefan\BlogGraphQl\Model\Resolver - */ class Tags implements ResolverInterface { /** @@ -80,8 +76,8 @@ public function resolve( Field $field, $context, ResolveInfo $info, - array $value = null, - array $args = null + ?array $value = null, + ?array $args = null ) { $searchCriteria = $this->searchCriteriaBuilder->build('magefan_blog_tags', $args); $statusFilter = $this->filterBuilder @@ -97,7 +93,7 @@ public function resolve( $scopeFilter = $this->filterBuilder ->setField('store_id') - ->setValue($scope) + ->setValue($args['storeId'] ?? $scope) ->setConditionType('eq') ->create(); $filterGroups[] = $this->filterGroupBuilder->addFilter($scopeFilter)->create(); diff --git a/Model/Tags/FilterArgument.php b/Model/Tags/FilterArgument.php index c5f3ae3..a01125d 100755 --- a/Model/Tags/FilterArgument.php +++ b/Model/Tags/FilterArgument.php @@ -10,10 +10,6 @@ use Magento\Framework\GraphQl\Query\Resolver\Argument\FieldEntityAttributesInterface; use Magento\Framework\GraphQl\ConfigInterface; -/** - * Class FilterArgument - * @package Magefan\BlogGraphQl\Model\Tags - */ class FilterArgument implements FieldEntityAttributesInterface { /** @var ConfigInterface */ diff --git a/Plugin/Magento/UrlRewriteGraphQl/Model/Resolver/EntityUrl.php b/Plugin/Magento/UrlRewriteGraphQl/Model/Resolver/EntityUrl.php index f7ac5d8..4dad3d2 100644 --- a/Plugin/Magento/UrlRewriteGraphQl/Model/Resolver/EntityUrl.php +++ b/Plugin/Magento/UrlRewriteGraphQl/Model/Resolver/EntityUrl.php @@ -8,6 +8,8 @@ namespace Magefan\BlogGraphQl\Plugin\Magento\UrlRewriteGraphQl\Model\Resolver; use Magento\Framework\GraphQl\Config\Element\Field; +use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; +use Magento\Framework\GraphQl\Query\Resolver\Value; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magefan\Blog\Api\UrlResolverInterface; @@ -32,13 +34,15 @@ public function __construct( } /** - * @param $subject - * @param $result - * @param $field - * @param $context - * @param $info - * @param null $value - * @param null $args + * Returns a custom blog page data structure if the original result is empty. + * + * @param mixed $subject + * @param mixed|Value $result + * @param Field $field + * @param ContextInterface $context + * @param ResolveInfo $info + * @param array|null $value + * @param array|null $args * @return array * @throws \Magento\Framework\Exception\NoSuchEntityException */ diff --git a/README.md b/README.md index b9ff6a4..9d45a14 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,14 @@ [![Total Downloads](https://poser.pugx.org/magefan/module-blog-graph-ql/downloads)](https://packagist.org/packages/magefan/module-blog-graph-ql) [![Latest Stable Version](https://poser.pugx.org/magefan/module-blog-graph-ql/v/stable)](https://packagist.org/packages/magefan/module-blog-graph-ql) - - - - - [Magento 2 Blog GraphQL](https://magefan.com/magento2-blog-extension) module allows you to create a PWA Blog on your Magento 2 Store. **Attention!!!** If you use Magento lower then v2.3.4 please use BlogGraphQl extension v2.0.1. BlogGraphQl v2.0.2 is only for Magento 2.3.4 or greater. + + +## πŸ‡ΊπŸ‡¦ Stand with Ukraine! [How can you help?](https://magefan.com/blog/join-our-donations) + ## Demo Try out our open demo and if you like our extension **please give us some star on Github β˜…** @@ -73,73 +72,92 @@ https://magefan.com/contact The code is licensed under [EULA](https://magefan.com/end-user-license-agreement). ## [Magento 2 Extensions](https://magefan.com/magento-2-extensions) by Magefan -### [Magento 2 Admin Panel Extensions](https://magefan.com/magento-2-extensions/admin-extensions) - * [Magento 2 Automatic Related Products](https://magefan.com/magento-2-automatic-related-products) - * [Magento 2 Automatic Related Products Plus](https://magefan.com/magento-2-automatic-related-products/pricing) - * [Magento 2 Edit Order Extension](https://magefan.com/magento-2-edit-order-extension) - * [Magento 2 Better Order Grid Extension](https://magefan.com/magento-2-better-order-grid-extension) - * [Magento 2 Extended Product Grid](https://magefan.com/magento-2-product-grid-inline-editor) + +### [Magento 2 Google Extensions](https://magefan.com/magento-2-extensions/google-extensions) + + * [Magento 2 Google Indexing](https://magefan.com/magento-2-google-indexing-api) + * [Magento 2 Google Analytics 4](https://magefan.com/magento-2-google-analytics-4) + * [Magento 2 Google Tag Manager](https://magefan.com/magento-2-google-tag-manager) * [Magento 2 Google Shopping Feed](https://magefan.com/magento-2-google-shopping-feed-extension) - * [Magento 2 Product Tabs Extension](https://magefan.com/magento-2/extensions/product-tabs) - * [Magento 2 Admin View Extension](https://magefan.com/magento-2-admin-view-extension) - * [Magento 2 Zero Downtime Deployment](https://magefan.com/blog/magento-2-zero-downtime-deployment) - * [Magento 2 Admin Email Notifications](https://magefan.com/magento-2-admin-email-notifications) - * [Magento 2 Dynamic Categories](https://magefan.com/magento-2-dynamic-categories) - * [Magento 2 Convert Guest to Customer Extension](https://magefan.com/magento2-convert-guest-to-customer) - * [Magento 2 Conflict Detector Extension](https://magefan.com/magento2-conflict-detector) - * [Magento 2 Login As Customer Extension](https://magefan.com/login-as-customer-magento-2-extension) - * [Magento 2 Mautic Integration Extension](https://magefan.com/magento-2-mautic-extension) - * [Magento 2 CMS Display Rules Extension](https://magefan.com/magento-2-cms-display-rules-extension) - * [Magento 2 Zendesk Chat Extension](https://magefan.com/magento-2-zendesk-chat-extension) - * [Magento 2 YouTube Widget Extension](https://magefan.com/magento2-youtube-extension) - * [Magento 2 CLI Extension](https://magefan.com/magento2-cli-extension) - * [Magento 2 Facebook Pixel Extension](https://magefan.com/magento-2-facebook-pixel-extension) + * [Magento 2 Google Customer Reviews](https://magefan.com/magento-2-google-customer-reviews) -### [Magento 2 Blog Extensions](https://magefan.com/magento-2-extensions/blog-extensions) +### Magento 2 SEO Extensions - * [Magento 2 Blog Extension](https://magefan.com/magento2-blog-extension) - * [Magento 2 Blog Plus Extension](https://magefan.com/magento2-blog-extension/pricing) - * [Magento 2 Blog Extra Extension](https://magefan.com/magento2-blog-extension/pricing) - * [Magento 2 Multi Blog Extension](https://magefan.com/magento-2-multi-blog-extension) - * [Magento 2 AMP Blog Extension](https://magefan.com/magento-2-amp-blog-extension) - * [Magento 2 Product Widget Advanced Extension](https://magefan.com/magento-2-product-widget) + * [Magento 2 SEO Extension](https://magefan.com/magento-2-seo-extension) + * [Magento 2 Rich Snippets](https://magefan.com/magento-2-rich-snippets) + * [Magento 2 HTML Sitemap](https://magefan.com/magento-2-html-sitemap-extension) + * [Magento 2 XML Sitemap](https://magefan.com/magento-2-xml-sitemap-extension) + * [Magento 2 Facebook Open Graph](https://magefan.com/magento-2-open-graph-extension-og-tags) + * [Magento 2 Twitter Cards](https://magefan.com/magento-2-twitter-cards-extension) -### [Magento 2 SEO Extensions](https://magefan.com/magento-2-extensions/magento-2-seo-extensions) +### [Magento 2 Speed Optimization Extensions](https://magefan.com/magento-2-extensions/speed-optimization) - * [Magento 2 SEO Extension](https://magefan.com/magento-2-seo-extension) - * [Magento 2 Rich Snippets Extension](https://magefan.com/magento-2-rich-snippets) - * [Magento 2 HTML Sitemap Extension](https://magefan.com/magento-2-html-sitemap-extension) - * [Magento 2 XML Sitemap Extension](https://magefan.com/magento-2-xml-sitemap-extension) - * [Magento 2 SEO Suite Ultimate Extension](https://magefan.com/magento-2-seo-suite-ultimate-extension) - * [Magento 2 Twitter Cards Extension](https://magefan.com/magento-2-twitter-cards-extension) - * [Magento 2 Facebook Open Graph Extension](https://magefan.com/magento-2-open-graph-extension-og-tags) - * [Magento 2 Hreflang Tags Extension](https://magefan.com/magento2-alternate-hreflang-extension) + * [Magento 2 Google Page Speed Optimizer](https://magefan.com/magento-2-google-page-speed-optimizer) + * [Magento 2 Full Page Cache Warmer](https://magefan.com/magento-2-full-page-cache-warmer) + * [Magento 2 Image Lazy Load](https://magefan.com/magento-2-image-lazy-load-extension) + * [Magento 2 WebP Images](https://magefan.com/magento-2-webp-optimized-images) + * [Magento 2 Rocket JavaScript](https://magefan.com/rocket-javascript-deferred-javascript) -### [Magento 2 Cart Extensions](https://magefan.com/magento-2-extensions/cart-extensions) + ### [Magento 2 Admin Panel Extensions](https://magefan.com/magento-2-extensions/admin-extensions) + + * [Magento 2 Size Chart Extension](https://magefan.com/magento-2-size-chart) + * [Magento 2 Security Extension](https://magefan.com/magento-2-security-extension) + * [Magento 2 Admin Action Log](https://magefan.com/magento-2-admin-action-log) + * [Magento 2 Order Editor](https://magefan.com/magento-2-edit-order-extension) + * [Magento 2 Better Order Grid](https://magefan.com/magento-2-better-order-grid-extension) + * [Magento 2 Extended Product Grid](https://magefan.com/magento-2-product-grid-inline-editor) + * [Magento 2 Product Tabs](https://magefan.com/magento-2/extensions/product-tabs) + * [Magento 2 Facebook Pixel](https://magefan.com/magento-2-facebook-pixel-extension) + * [Magento 2 Email Attachments](https://magefan.com/magento-2-email-attachments) + * [Magento 2 Admin View](https://magefan.com/magento-2-admin-view-extension) + * [Magento 2 Admin Email Notifications](https://magefan.com/magento-2-admin-email-notifications) + * [Magento 2 Login As Customer](https://magefan.com/login-as-customer-magento-2-extension) - * [Better Magento 2 Checkout Extension](https://magefan.com/better-magento-2-checkout-extension) - * [Magento 2 Coupon Code Link](https://magefan.com/magento-2-coupon-code-link) +### Magento 2 Blog Extensions -### [Magento 2 Speed Optimization Extensions](https://magefan.com/magento-2-extensions/speed-optimization-extensions) + * [Magento 2 Blog](https://magefan.com/magento2-blog-extension) + * [Magento 2 Multi Blog](https://magefan.com/magento-2-multi-blog-extension) + * [Magento 2 Product Widget](https://magefan.com/magento-2-product-widget) - * [Magento 2 Lazy Load Extension](https://magefan.com/magento-2-image-lazy-load-extension) - * [Magento 2 WebP Optimized Images Extension](https://magefan.com/magento-2-webp-optimized-images) - * [Magento 2 Rocket JavaScript Extension](https://magefan.com/rocket-javascript-deferred-javascript) +### [Magento 2 Marketing Automation Extensions](https://magefan.com/magento-2-extensions/marketing-automation) + + * [Magento 2 Cookie Consent](https://magefan.com/magento-2-cookie-consent) + * [Magento 2 Product Labels](https://magefan.com/magento-2-product-labels) + * [Magento 2 Base Price](https://magefan.com/magento-2-base-price) + * [Magento 2 Dynamic Categories](https://magefan.com/magento-2-dynamic-categories) + * [Magento 2 Dynamic Blocks and Pages Extension](https://magefan.com/magento-2-cms-display-rules-extension) + * [Magento 2 Automatic Related Products](https://magefan.com/magento-2-automatic-related-products) + * [Magento 2 Price History](https://magefan.com/magento-2-price-history) + * [Magento 2 Mautic Integration](https://magefan.com/magento-2-mautic-extension) + * [Magento 2 YouTube Video](https://magefan.com/magento2-youtube-extension) + +### [Magento 2 Cart Extensions](https://magefan.com/magento-2-extensions/cart-extensions) + + * [Magento 2 Checkout Extension](https://magefan.com/better-magento-2-checkout-extension) + * [Magento 2 Coupon Code](https://magefan.com/magento-2-coupon-code-link) + * [Magento 2 Guest to Customer](https://magefan.com/magento2-convert-guest-to-customer) ### [Magento 2 Multi-Language Extensions](https://magefan.com/magento-2-extensions/multi-language-extensions) - * [Magento 2 Auto Currency Switcher Extension](https://magefan.com/magento-2-currency-switcher-auto-currency-by-country) - * [Magento 2 Auto Language Switcher Extension](https://magefan.com/magento-2-auto-language-switcher) - * [Magento 2 GeoIP Switcher Extension](https://magefan.com/magento-2-geoip-switcher-extension) - * [Magento 2 Translation Extension](https://magefan.com/magento-2-translation-extension) - * [Magento 2 Translation Plus Extension](https://magefan.com/magento-2-translation-extension/pricing) + * [Magento 2 Hreflang Tags](https://magefan.com/magento2-alternate-hreflang-extension) + * [Magento 2 Auto Currency Switcher](https://magefan.com/magento-2-currency-switcher-auto-currency-by-country) + * [Magento 2 Auto Language Switcher](https://magefan.com/magento-2-auto-language-switcher) + * [Magento 2 GeoIP Store Switcher](https://magefan.com/magento-2-geoip-switcher-extension) + * [Magento 2 Translation](https://magefan.com/magento-2-translation-extension) + +### [Developers Tools](https://magefan.com/magento-2-extensions/developer-tools) + + * [Magento 2 Zero Downtime Deployment](https://magefan.com/blog/magento-2-zero-downtime-deployment) + * [Magento 2 Cron Schedule](https://magefan.com/magento-2-cron-schedule) + * [Magento 2 CLI Extension](https://magefan.com/magento2-cli-extension) + * [Magento 2 Conflict Detector](https://magefan.com/magento2-conflict-detector) + + ## [Shopify Apps](https://magefan.com/shopify/apps) by Magefan - ### Magento 2 Point of Sale - * [Magento 2 POS System](https://magefan.com/magento-pos-system) - - ### Shopware Extensions - * [Shopware WebP Extension](https://magefan.com/shopware/extensions/webp) - - ### Shopify Apps * [Shopify Login As Customer](https://apps.shopify.com/login-as-customer) + * [Shopify Blog](https://apps.shopify.com/magefan-blog) + * [Shopify Size Chart](https://magefan.com/shopify/apps/size-chart) + * [Shopify Google Indexer](https://magefan.com/shopify/apps/google-indexing) + * [Shopify Product Feeds](https://magefan.com/shopify/apps/product-feed) + * [Shopify Server GTM & GA4](https://magefan.com/shopify/apps/gtm-and-ga4) diff --git a/composer.json b/composer.json index 812f3bc..bb546b1 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "magefan/module-blog-graph-ql", "description": "GrapQl for Magento 2 Blog extension by Magefan", "type": "magento2-module", - "version": "2.1.7", + "version": "2.1.11", "autoload": { "files": [ "registration.php" ], "psr-4": { diff --git a/etc/graphql/di.xml b/etc/graphql/di.xml index d279635..d3d1ea5 100644 --- a/etc/graphql/di.xml +++ b/etc/graphql/di.xml @@ -8,7 +8,7 @@ - + mfblog/design/publication_date mfblog/design/format_date mfblog/index_page/title diff --git a/etc/schema.graphqls b/etc/schema.graphqls index 403f773..d60ab6a 100644 --- a/etc/schema.graphqls +++ b/etc/schema.graphqls @@ -21,14 +21,19 @@ type Query { sort: [String] @doc(description: "Specifies which attribute to sort on, and whether to return the results in ascending or descending order.") sortFiled: String = "publish_time" @doc(description: "Specifies what field to sort posts by. The default value is publish_time.") allPosts: Boolean @doc(description: "If true get all posts.") + storeId: Int = 0 @doc(description: "Specifies the store view ID to filter the results. The default value is 0, meaning no specific store filter applied.") ): blogPostsOutput @resolver(class: "\\Magefan\\BlogGraphQl\\Model\\Resolver\\Posts") @doc(description: "The posts query searches for posts that match the criteria specified in the search and filter attributes") blogComments( filter: BlogCommentsFilterInput @doc(description: "Identifies which comment attributes to search for and return."), pageSize: Int = 5 @doc(description: "Specifies the maximum number of results to return at once. This attribute is optional."), currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1."), ):blogCommentsOutput @resolver(class: "\\Magefan\\BlogGraphQl\\Model\\Resolver\\Comments") @doc(description: "The comments query searches for posts that match the criteria specified in the search and filter attributes") - blogTags: blogTagsOutput @resolver(class: "\\Magefan\\BlogGraphQl\\Model\\Resolver\\Tags") @doc(description: "") - blogCategories: blogCategoriesOutput @resolver(class: "\\Magefan\\BlogGraphQl\\Model\\Resolver\\Categories") @doc(description: "") + blogTags( + storeId: Int = 0 @doc(description: "Specifies the store view ID to filter the results. The default value is 0, meaning no specific store filter applied.") + ): blogTagsOutput @resolver(class: "\\Magefan\\BlogGraphQl\\Model\\Resolver\\Tags") @doc(description: "") + blogCategories( + storeId: Int = 0 @doc(description: "Specifies the store view ID to filter the results. The default value is 0, meaning no specific store filter applied.") + ): blogCategoriesOutput @resolver(class: "\\Magefan\\BlogGraphQl\\Model\\Resolver\\Categories") @doc(description: "") } type Mutation { diff --git a/registration.php b/registration.php index dd8e7d9..8e275d0 100755 --- a/registration.php +++ b/registration.php @@ -4,6 +4,8 @@ * Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement). */ +declare(strict_types=1); + \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Magefan_BlogGraphQl',