0

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?

1 Answer 1

2

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);
1
  • 1
    Happy to help :) Happy coding !! Nov 14, 2019 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.