cloudinary-8.x-1.x-dev/modules/cloudinary_media_library_widget/src/Plugin/Field/FieldType/CloudinaryFieldItemTrait.php
modules/cloudinary_media_library_widget/src/Plugin/Field/FieldType/CloudinaryFieldItemTrait.php
<?php
namespace Drupal\cloudinary_media_library_widget\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
/**
* Build a trait to use for cloudinary specific schema and properties.
*/
trait CloudinaryFieldItemTrait {
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
// Inherit schema from parent class if applicable.
if (is_callable([parent::class, 'schema'])) {
$schema = parent::schema($field_definition);
}
$schema['columns']['public_id'] = [
'description' => 'The public id of the asset.',
'type' => 'varchar',
'length' => 512,
];
$schema['columns']['transformation'] = [
'description' => 'Specifies the transformation parameters for the representation.',
'type' => 'varchar',
'length' => 512,
];
$schema['columns']['resource_type'] = [
'description' => 'The type of the asset.',
'type' => 'varchar',
'length' => 32,
];
$schema['columns']['delivery_type'] = [
'description' => 'The delivery type of the asset.',
'type' => 'varchar',
'length' => 32,
];
return $schema;
}
/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
// Inherit properties from parent class if applicable.
if (is_callable([parent::class, 'propertyDefinitions'])) {
$properties = parent::propertyDefinitions($field_definition);
}
$properties['public_id'] = DataDefinition::create('string')
->setLabel(t('Public ID'))
->setRequired(TRUE)
->setDescription(t('The public if of the asset.'));
$properties['transformation'] = DataDefinition::create('string')
->setLabel(t('Transformation'))
->setDescription(t('Specifies the transformation parameters for the representation.'));
$properties['resource_type'] = DataDefinition::create('string')
->setLabel(t('Resource type'))
->setRequired(TRUE)
->setDescription(t('The type of the asset.'));
$properties['delivery_type'] = DataDefinition::create('string')
->setLabel(t('Delivery type'))
->setRequired(TRUE)
->setDescription(t('The delivery type of the asset.'));
return $properties;
}
}
