class File in Commerce File 8.2
The file license type.
Plugin annotation
@CommerceLicenseType(
id = "commerce_file",
label = @Translation("File"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\commerce_license\Plugin\Commerce\LicenseType\LicenseTypeBase implements LicenseTypeInterface
- class \Drupal\commerce_file\Plugin\Commerce\LicenseType\File implements ContainerFactoryPluginInterface
- class \Drupal\commerce_license\Plugin\Commerce\LicenseType\LicenseTypeBase implements LicenseTypeInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of File
3 string references to 'File'
File
- src/
Plugin/ Commerce/ LicenseType/ File.php, line 21
Namespace
Drupal\commerce_file\Plugin\Commerce\LicenseTypeView source
class File extends LicenseTypeBase implements ContainerFactoryPluginInterface {
/**
* The file download logger.
*
* @var \Drupal\commerce_file\DownloadLoggerInterface
*/
protected $downloadLogger;
/**
* Constructs a new File object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\commerce_file\DownloadLoggerInterface $download_logger
* The download logger.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, DownloadLoggerInterface $download_logger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->downloadLogger = $download_logger;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('commerce_file.download_logger'));
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'file_download_limit' => NULL,
] + parent::defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$checkbox_parents = array_merge($form['#parents'], [
'limit',
]);
$checkbox_path = array_shift($checkbox_parents);
$checkbox_path .= '[' . implode('][', $checkbox_parents) . ']';
$form['limit'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Limit the number of times a user can download a licensed file'),
'#description' => $this
->t('The value specified here overrides the globally configured download limit (Enter 0 for no limit).'),
'#default_value' => !empty($this->configuration['file_download_limit']),
];
$form['file_download_limit'] = [
'#type' => 'number',
'#title' => $this
->t('Download limit'),
'#title_display' => 'invisible',
'#default_value' => $this->configuration['file_download_limit'] ?? 100,
'#min' => 0,
'#states' => [
'visible' => [
':input[name="' . $checkbox_path . '"]' => [
'checked' => TRUE,
],
],
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValue($form['#parents']);
$this->configuration = [];
if (!empty($values['limit'])) {
$this->configuration['file_download_limit'] = $values['file_download_limit'];
}
}
/**
* {@inheritdoc}
*/
public function buildLabel(LicenseInterface $license) {
return $this
->t('License for file');
}
/**
* {@inheritdoc}
*/
public function grantLicense(LicenseInterface $license) {
// Clear the download log in order to reset download limits.
$this->downloadLogger
->clear($license);
}
/**
* {@inheritdoc}
*/
public function revokeLicense(LicenseInterface $license) {
}
/**
* {@inheritdoc}
*/
public function buildFieldDefinitions() {
$fields = parent::buildFieldDefinitions();
$fields['file_download_limit'] = BundleFieldDefinition::create('integer')
->setLabel($this
->t('Download limit'))
->setRequired(FALSE)
->setSetting('unsigned', TRUE)
->setDisplayOptions('form', [
'type' => 'commerce_file_download_limit',
]);
return $fields;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
File:: |
protected | property | The file download logger. | |
File:: |
public | function |
Form constructor. Overrides LicenseTypeBase:: |
|
File:: |
public | function |
Builds the field definitions for entities of this bundle. Overrides LicenseTypeBase:: |
|
File:: |
public | function |
Builds a label for the given license. Overrides LicenseTypeInterface:: |
|
File:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
File:: |
public | function |
Gets default configuration for this plugin. Overrides LicenseTypeBase:: |
|
File:: |
public | function |
Reacts to the license being activated. Overrides LicenseTypeInterface:: |
|
File:: |
public | function |
Reacts to the license being revoked. Overrides LicenseTypeInterface:: |
|
File:: |
public | function |
Form submission handler. Overrides LicenseTypeBase:: |
|
File:: |
public | function |
Constructs a new File object. Overrides LicenseTypeBase:: |
|
LicenseTypeBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
LicenseTypeBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
LicenseTypeBase:: |
public | function |
Gets the license type label. Overrides LicenseTypeInterface:: |
|
LicenseTypeBase:: |
public | function |
Gets the workflow ID this this license type should use. Overrides LicenseTypeInterface:: |
|
LicenseTypeBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
LicenseTypeBase:: |
public | function |
Copy configuration values to a license entity. Overrides LicenseTypeInterface:: |
|
LicenseTypeBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
1 |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |