How to get the media_url in custom GraphQl in Magento 2.3?
-
19-03-2021 - |
문제
I have a custom module to update Faq of the website.question and answers can update from the back-end.Answer field is wysiwyg editor.Can upload image to the answer content.
If i get the result using graphQl , for the answer which have image retrieving the image path as below.
<img src=\"{{media url="wysiwyg/what_next.jpg"}}\" alt=\"\" width=\"560\" height=\"460\">
If i use this in front end the image is broken.Image is not showing.
My GraphQl query
type Query {
faqs : [Faqs] @resolver( class: "Ayakil\\Faq\\Model\\Resolver\\Faq") @doc(description: "Get list of active answered FAQS")
}
type Faqs {
id : Int @doc(description: "Id")
question : String @doc(description: "Question")
answer : String @doc(description: "Answer")
}
My resolver File
public function getFaq( )
{
try {
$collection = $this->_faqFactory->create()->getCollection();
$collection->addFieldToFilter('faq_active',1);
$collection->setOrder('short_order', 'ASC');
$faqData = $collection->getData();
foreach($collection as $faq){
$faq_id = $faq->getId();
$news_data[$faq_id]['id'] = $faq_id;
$news_data[$faq_id]['question'] = $faq->getQuestion();
$news_data[$faq_id]['answer'] = $faq->getAnswer();
}
} catch (NoSuchEntityException $e) {
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
}
return $faqData;
}
How Can i get the actual file path here?
해결책
Use this below code where you pass your wysiwyg editor content :
protected $filterManager;
public function __construct(
\Magento\Cms\Model\Template\FilterProvider $filterManager
){
$this->filterManager = $filterManager;
}
Now, pass your wysiwyg editor content in filter() function:
$this->filterManager->getPageFilter()->filter($content);
제휴하지 않습니다 magento.stackexchange