You are here

interface LicenseTypeInterface in Commerce License 8.2

Defines the interface for license types.

License type plugins provide the functionality for what the license grants access to.

They participate in different ways at various points of the license's lifecycle:

  • When a product is created that sells a license, the license type plugin's configuration represents the details of the license to be sold. This is stored as a configured plugin on a field on the product variation (this field is provided by our commerce_license entity trait on product variation types).
  • When a product is purchased, the configured plugin on the product variation is used to set field values on the newly created license entity. In effect, the configured plugin is used as a template for the new license. These fields are provided by the license type plugin behaving as a bundle plugin. Accordingly, the plugin configuration defined in defaultConfiguration() and the bundle fields defined in buildFieldDefinitions() should usually match. The license has a reference to the plugin type in its bundle field, but when a license obtains its plugin to work with, it is no longer configured as this would duplicate the fields (which we use rather than the plugin configuration so they can be queried for).
  • When a license is granted or revoked, the plugin's grantLicense() and revokeLicense() methods are responsible for making changes to the system, such as adding or removing a role on the license's owner.

Hierarchy

Expanded class hierarchy of LicenseTypeInterface

All classes that implement LicenseTypeInterface

3 files declare their use of LicenseTypeInterface
License.php in src/Entity/License.php
LicenseInterface.php in src/Entity/LicenseInterface.php
LicenseTypeManager.php in src/LicenseTypeManager.php

File

src/Plugin/Commerce/LicenseType/LicenseTypeInterface.php, line 39

Namespace

Drupal\commerce_license\Plugin\Commerce\LicenseType
View source
interface LicenseTypeInterface extends BundlePluginInterface, ConfigurableInterface, DependentPluginInterface, PluginFormInterface {

  /**
   * Gets the license type label.
   *
   * @return string
   *   The license type label.
   */
  public function getLabel();

  /**
   * Builds a label for the given license.
   *
   * @param \Drupal\commerce_license\Entity\LicenseInterface $license
   *   The license.
   *
   * @return string
   *   The label.
   */
  public function buildLabel(LicenseInterface $license);

  /**
   * Gets the workflow ID this this license type should use.
   *
   * @return string
   *   The ID of the workflow used for this license type.
   */
  public function getWorkflowId();

  /**
   * Copy configuration values to a license entity.
   *
   * This does not save the license; it is the caller's responsibility to do so.
   *
   * This should only be called on a plugin which has configuration. It should
   * not be called on a plugin obtained from LicenseInterface::getTypePlugin(),
   * as that has no configuration.
   *
   * @param \Drupal\commerce_license\Entity\LicenseInterface $license
   *   The license entity.
   */
  public function setConfigurationValuesOnLicense(LicenseInterface $license);

  /**
   * Reacts to the license being activated.
   *
   * The license's privileges should be granted to its user. This is called
   * during preSave(), so values may be set on the license entity.
   *
   * @param \Drupal\commerce_license\Entity\LicenseInterface $license
   *   The license entity.
   */
  public function grantLicense(LicenseInterface $license);

  /**
   * Reacts to the license being revoked.
   *
   * The license's privileges should be removed from its user. This is called
   * during preSave(), so values may be set on the license entity.
   *
   * @param \Drupal\commerce_license\Entity\LicenseInterface $license
   *   The license entity.
   */
  public function revokeLicense(LicenseInterface $license);

}

Members

Namesort descending Modifiers Type Description Overrides
BundlePluginInterface::buildFieldDefinitions public function Builds the field definitions for entities of this bundle. 2
ConfigurableInterface::defaultConfiguration public function Gets default configuration for this plugin. 11
ConfigurableInterface::getConfiguration public function Gets this plugin's configuration. 12
ConfigurableInterface::setConfiguration public function Sets the configuration for this plugin instance. 12
DependentPluginInterface::calculateDependencies public function Calculates dependencies for the configured plugin. 19
LicenseTypeInterface::buildLabel public function Builds a label for the given license. 3
LicenseTypeInterface::getLabel public function Gets the license type label. 2
LicenseTypeInterface::getWorkflowId public function Gets the workflow ID this this license type should use. 1
LicenseTypeInterface::grantLicense public function Reacts to the license being activated. 2
LicenseTypeInterface::revokeLicense public function Reacts to the license being revoked. 2
LicenseTypeInterface::setConfigurationValuesOnLicense public function Copy configuration values to a license entity. 1
PluginFormInterface::buildConfigurationForm public function Form constructor. 36
PluginFormInterface::submitConfigurationForm public function Form submission handler. 32
PluginFormInterface::validateConfigurationForm public function Form validation handler. 18
PluginInspectionInterface::getPluginDefinition public function Gets the definition of the plugin implementation. 4
PluginInspectionInterface::getPluginId public function Gets the plugin_id of the plugin instance. 2