Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
novicell/custom_forms / modules / payment / src / Entity / CustomFormsPaymentMethod.php
Size: Mime:
<?php

namespace Drupal\custom_forms_payment\Entity;

use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\custom_forms_payment\CustomFormsPaymentMethodInterface;

/**
 * Defines the custom_forms_payment_method entity type.
 *
 * @ConfigEntityType(
 *   id = "custom_forms_payment_method",
 *   label = @Translation("Custom forms payment method"),
 *   label_collection = @Translation("Custom forms payment methods"),
 *   label_singular = @Translation("Custom forms payment method"),
 *   label_plural = @Translation("Custom forms payment methods"),
 *   label_count = @PluralTranslation(
 *     singular = "@count Custom forms payment method",
 *     plural = "@count Custom forms payment methods",
 *   ),
 *   handlers = {
 *     "list_builder" = "Drupal\custom_forms_payment\CustomFormsPaymentMethodListBuilder",
 *     "form" = {
 *       "add" = "Drupal\custom_forms_payment\Form\CustomFormsPaymentMethodForm",
 *       "edit" = "Drupal\custom_forms_payment\Form\CustomFormsPaymentMethodForm",
 *       "delete" = "Drupal\Core\Entity\EntityDeleteForm"
 *     }
 *   },
 *   config_prefix = "payment_method",
 *   admin_permission = "administer custom forms payment methods",
 *   links = {
 *     "collection" = "/admin/custom_forms/settings/payment_methods",
 *     "add-form" = "/admin/custom_forms/settings/payment_methods/add",
 *     "edit-form" = "/admin/custom_forms/settings/payment_methods/{custom_forms_payment_method}",
 *     "delete-form" = "/admin/custom_forms/settings/payment_methods/{custom_forms_payment_method}/delete"
 *   },
 *   entity_keys = {
 *     "id" = "id",
 *     "label" = "label",
 *     "uuid" = "uuid"
 *   },
 *   config_export = {
 *     "id",
 *     "label",
 *     "plugin",
 *     "test_mode",
 *     "settings"
 *   }
 * )
 */
class CustomFormsPaymentMethod extends ConfigEntityBase implements CustomFormsPaymentMethodInterface {

  /**
   * The Custom forms payment method ID.
   *
   * @var string
   */
  protected $id;

  /**
   * The Custom forms payment method label.
   *
   * @var string
   */
  protected $label;

  /**
   * The Custom forms payment method status.
   *
   * @var bool
   */
  protected $status;

  /**
   * The Custom forms payment method plugin.
   *
   * @var string
   */
  protected $plugin;

  /**
   * The array of settings used by the payment method.
   *
   * @var array
   */
  protected $settings;

  /**
   * The Custom forms payment method test mode.
   *
   * @var bool
   */
  protected $test_mode;

  /**
   * {@inheritdoc}
   */
  public function getPaymentPluginDefinition() {
    /** @var \Drupal\custom_forms_payment\CustomFormsPaymentMethodManager $plugin_manager */
    $plugin_manager = \Drupal::service('plugin.manager.custom_forms_payment_methods');

    $plugin_definition = $plugin_manager->getDefinition($this->plugin);

    if (!empty($plugin_definition)) {
      return $plugin_definition;
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getPaymentPlugin() {
    /** @var \Drupal\custom_forms_payment\CustomFormsPaymentMethodManager $plugin_manager */
    $plugin_manager = \Drupal::service('plugin.manager.custom_forms_payment_methods');

    $settings = !empty($this->settings) ? $this->settings : [];
    $plugin = $plugin_manager->createInstance($this->plugin, $settings);

    if (!empty($plugin)) {
      return $plugin;
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getPaymentPluginId() {
    if (!empty($this->plugin)) {
      return $this->plugin;
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getPluginSettings() {
    return $this->settings ?? [];
  }

}