LicenseTypeBase.php in Commerce License 8.2
File
src/Plugin/Commerce/LicenseType/LicenseTypeBase.php
View source
<?php
namespace Drupal\commerce_license\Plugin\Commerce\LicenseType;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\commerce_license\Entity\LicenseInterface;
abstract class LicenseTypeBase extends PluginBase implements LicenseTypeInterface {
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this
->setConfiguration($configuration);
}
public function getLabel() {
return $this->pluginDefinition['label'];
}
public function getWorkflowId() {
return 'license_default';
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return [];
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValue($form['#parents']);
$property_names = array_keys($this
->defaultConfiguration());
foreach ($property_names as $property) {
$this->configuration[$property] = $values[$property];
}
}
public function getConfiguration() {
return $this->configuration;
}
public function setConfiguration(array $configuration) {
$this->configuration = NestedArray::mergeDeep($this
->defaultConfiguration(), $configuration);
}
public function setConfigurationValuesOnLicense(LicenseInterface $license) {
foreach ($this->configuration as $key => $value) {
$license->{$key} = $value;
}
}
public function defaultConfiguration() {
return [];
}
public function calculateDependencies() {
return [];
}
public function buildFieldDefinitions() {
return [];
}
}