Question

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=&quot;wysiwyg/what_next.jpg&quot;}}\" 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?

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top