PHPackages                             perfect-code/module-verify-connection-button - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. perfect-code/module-verify-connection-button

ActiveMagento2-module

perfect-code/module-verify-connection-button
============================================

Magento 2 module which gives you everything you need to add verify connection button to your configuration.

1.0.2(2y ago)01.0kGPL-3.0PHPPHP ^8.1

Since Apr 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/zhartaunik/magento2-verify-connection-button)[ Packagist](https://packagist.org/packages/perfect-code/module-verify-connection-button)[ RSS](/packages/perfect-code-module-verify-connection-button/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (4)Used By (0)

Overview
========

[](#overview)

This module helps you to add to your stores/configuration section button to check some connection with some system. [![](src/img/screenshot001.png)](src/img/screenshot001.png)[![](src/img/screenshot002.png)](src/img/screenshot002.png)

Usage
=====

[](#usage)

There are two ways how to use this module. Here is comparison between two possible ways. It's up to you which to use.

StepEasy and QuickMore Scalable WayDescriptionImplement an AdapterInterface++All in all you need to create an Adapter to verify the connection.Create routes.xml+Create controller+It will be an empty controller extended from original. Further injection will be inside di.xmlInject Adapter implementation++In easy way we use Original block and controller. In second way we use new created controller and virtual block.Use block in config++In first way we use original block. In second - virtual.Easy and quick start.
---------------------

[](#easy-and-quick-start)

**Useful for cases when you simply need only one button in your store. And you do not worry about perfect code.**

To add a validation button, you need:

### 1. Implement AdapterInterface.

[](#1-implement-adapterinterface)

Implement an interface where you make an attempt to establish a connection with the service you need. Examples of fields usage are described in comments to this file.

```
namespace VendorName\ModuleName\Model;
class Adapter implements \PerfectCode\ConnectionButton\Api\AdapterInterface
```

### 2. Inject implementation from the previous step.

[](#2-inject-implementation-from-the-previous-step)

Then add your Service Connector (Adapter) to `etc/adminhtml/di.xml`

```

            VendorName\ModuleName\Model\Adapter

            VendorName\ModuleName\Model\Adapter

                field_id_in_html_on_admin_area_page
                another_field_id_in_html_on_admin_area_page

```

### 3. Use the block from this module in your config.

[](#3-use-the-block-from-this-module-in-your-config)

Add the button to your `etc/adminhtml/system.xml`

```

    Test Connection
    PerfectCode\ConnectionButton\Block\Adminhtml\System\Config\TestConnection

```

Alternative (more dependency inversion principle way)
-----------------------------------------------------

[](#alternative-more-dependency-inversion-principle-way)

**According to soli\[D\] - DIP we need to work with abstractions. That's why I would recommend creating your own controller and create your own block.**

### 1. Implement AdapterInterface.

[](#1-implement-adapterinterface-1)

Implement an interface where you make an attempt to establish a connection with the service you need. Examples of fields usage are described in comments to this file.

```
namespace VendorName\ModuleName\Model;
class Adapter implements \PerfectCode\ConnectionButton\Api\AdapterInterface
```

### 2. Create routes configuration.

[](#2-create-routes-configuration)

Create etc/adminhtml/routes.xml

```

```

### 3. Create your controller and extend from existing.

[](#3-create-your-controller-and-extend-from-existing)

Your controller can be empty like this one below (we will inject our Adapter through di.xml)

```
