PHP code example of towardstudio / linkfield

1. Go to this page and download the library: Download towardstudio/linkfield library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

towardstudio / linkfield example snippets


use craft\commerce\elements\Product;
use towardstudio\linkfield\Plugin as LinkPlugin;
use towardstudio\linkfield\events\LinkTypeEvent;
use towardstudio\linkfield\models\element\ElementLinkType;
use yii\base\Event;

/**
 * Custom module class.
 */
class Module extends \yii\base\Module
{
  public function init() {
    parent::init();
    Event::on(
      LinkPlugin::class,
      LinkPlugin::EVENT_REGISTER_LINK_TYPES,
      function(LinkTypeEvent $event) {
        $event->linkTypes['product'] = new ElementLinkType(Product::class);
      }
    );
  }
}