0

We want to create a different page, very similar to the contact page, in which we ask for feedback about our service.

The idea is to have an exact copy of the /contact page, changing only the name of fields and the descriptive text at the top of the page.

How do we copy all the elements of the /contact page and rename them to created a new page linked to the /feedback url ?

1
  • You can create cms page with url_identifier as feedback then you can copy contact us form to that or if you want to implement any grid or email in the sense better go with custom module with route name as 'feedback'. Mar 8, 2019 at 9:52

1 Answer 1

0

You could make a new page in the Magento backend in Content->pages in which you insert the contact block in the page content:

{{block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form.phtml"}}

In order to make the page visible in your header, you can make an observer on the page block topmenu as follows:

<event name="page_block_html_topmenu_gethtml_before">
    <observer name="cc_add_contact" instance="Vendor\Modulename\Observer\Topmenu" />
</event>

The observer would look something like this:

<?php

namespace Vendor\Module\Observer;

use Magento\Framework\Event\Observer as 
EventObserver;
use Magento\Framework\Data\Tree\Node;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\UrlInterface;
use Magento\Catalog\Model\CategoryRepository;
class Topmenu implements ObserverInterface
{
/**
 * @var UrlInterface
 */
protected $url;
/**
 * @var CategoryRepository
 */
protected $categoryRepository;

/**
 * Topmenu constructor.
 * @param UrlInterface $url
 * @param CategoryRepository $categoryRepository
 */
public function __construct
(
    UrlInterface $url,
    CategoryRepository $categoryRepository
)
{
    $this->url = $url;
    $this->categoryRepository = $categoryRepository;
}

/**
 * @param EventObserver $observer
 * @return $this
 */
public function execute(EventObserver $observer)
{
    /** @var \Magento\Framework\Data\Tree\Node $menu */
    $menu = $observer->getMenu();
    $tree = $menu->getTree();
    $data = [
        'name'      => __('Feedback'),
        'id'        => 'feedback',
        'url'       => '/feedback',
        'is_active' => $this->isActiveFeedback()
    ];

    $node = new Node($data, 'id', $tree, $menu);
    $menu->addChild($node);

    return $this;
}

/**
 * @return int
 */
public function isActiveFeedback(){
    $url = $this->url->getCurrentUrl();
    if (substr($url,-9)=="/feedback"){
        return 1;
    }
    return 0;
}
}

Your Answer

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

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