DownloadLink.php in Download 8.2
File
src/Plugin/Field/FieldType/DownloadLink.php
View source
<?php
namespace Drupal\download\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\Form\FormStateInterface;
class DownloadLink extends FieldItemBase implements FieldItemInterface {
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return array(
'columns' => array(
'download_fields' => array(
'type' => 'text',
'size' => 'small',
'not null' => FALSE,
),
'download_label' => array(
'type' => 'text',
'size' => 'small',
'not null' => FALSE,
),
),
);
}
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['download_fields'] = DataDefinition::create('string')
->setLabel(t('Download Link'));
$properties['download_label'] = DataDefinition::create('string')
->setLabel(t('Text to display'));
return $properties;
}
public static function defaultFieldSettings() {
return array(
'download_filename' => 'all_files.zip',
) + parent::defaultFieldSettings();
}
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$form['download_filename'] = array(
'#type' => 'textfield',
'#title' => t('Filename for the download'),
'#description' => t('Please do NOT include the .zip extension'),
'#default_value' => $this
->getSetting('download_filename'),
);
return $form;
}
public function isEmpty() {
$value = $this
->get('download_fields')
->getValue();
return $value === null || $value === '';
}
}