0

I have my own contact us module in magento.I want to remove default contact us link from footer and add my own link. I have remove default contact page link and add my own link. I want that when my module is disabled then default contactus link will not remove from footer.

<referenceBlock name="contact-us-link" remove="true"/>

<referenceBlock name="footer_links">
    <block class="Magento\Framework\View\Element\Html\Link\Current" name="contact-us-link2" ifconfig="contactus/active_display/enabled_contactus">
        <arguments>
            <argument name="label" xsi:type="string">Contact Us2</argument>
            <argument name="path" xsi:type="string">contactus/front/index</argument>
        </arguments>


    </block>
</referenceBlock>

1 Answer 1

0

You can hide or show link from the backend

Stores >> Configuration >> General >> Contacts

You can enable or disable the default link

EDIT

You can do this by observer

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

     <event name="admin_system_config_changed_section_YourSectionName">
        <observer instance="Namespace\Modulename\Observer\ContactUsLink" name="admin_system_config_changed_section_yoursectionname"/>
    </event>
</config>

ContactUsLink.php

<?php
namespace Pkit\JobPortal\Observer;
use Magento\Framework\Event\Observer as EventObserver;

class ContactUsLink implements \Magento\Framework\Event\ObserverInterface {

    const XML_PATH_CONTACTUS = 'contact/contact/enabled'; //defualt magento contact us system path
    const XML_PATH_YOURCONTACTUS = 'section/group/field'; //your contact us system path


    protected $_scopeConfig;

    protected $_configInterface;

    public function __construct(
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Framework\App\Config\ConfigResource\ConfigInterface $configInterface
    )
    {
        $this->_scopeConfig = $scopeConfig;
        $this->_configInterface = $configInterface;
    }

    public function execute(EventObserver $observer)
    {

        if($this->_scopeConfig->getValue(self::XML_PATH_YOURCONTACTUS)){
            $this->_configInterface
                    ->saveConfig(self::XML_PATH_CONTACTUS, 0 , 'default', 0);
        } else if(!$this->_scopeConfig->getValue(self::XML_PATH_YOURCONTACTUS)){
            $this->_configInterface
                    ->saveConfig(self::XML_PATH_CONTACTUS, 1 , 'default', 0);
        }
    }
}
2
  • thanks for reply but actually i want to enable or disable dynamically from xml based on my own config value.
    – Ashar Riaz
    Oct 20, 2016 at 12:56
  • You can do this by observer . I edited my answer
    – Priyank
    Oct 20, 2016 at 13:17

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.