FileUrlItem.php in File URL 2.0.x
File
src/Plugin/Field/FieldType/FileUrlItem.php
View source
<?php
namespace Drupal\file_url\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\DataReferenceTargetDefinition;
use Drupal\file\Plugin\Field\FieldType\FileItem;
class FileUrlItem extends FileItem {
public static function defaultFieldSettings() {
return [
'handler' => 'file_url_default',
] + parent::defaultFieldSettings();
}
public static function schema(FieldStorageDefinitionInterface $field_definition) {
$schema = parent::schema($field_definition);
$schema['columns']['target_id'] = [
'description' => 'The URI of the file entity.',
'type' => 'varchar',
'length' => 2048,
];
unset($schema['foreign keys']);
return $schema;
}
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties = parent::propertyDefinitions($field_definition);
$target_id_definition = DataReferenceTargetDefinition::create('string')
->setLabel(new TranslatableMarkup('@label ID', [
'@label' => 'file',
]));
$target_id_definition
->setRequired(TRUE);
$properties['target_id'] = $target_id_definition;
return $properties;
}
public function isEmpty() {
$is_empty = parent::isEmpty();
if (!$is_empty && is_string($this->target_id)) {
$target_id = trim($this->target_id);
if ($target_id === '') {
return TRUE;
}
}
return $is_empty;
}
}
Classes
Name |
Description |
FileUrlItem |
Plugin implementation of the 'file_url' field type. |