commerce_product_bundles-8.x-1.0/src/Plugin/Field/FieldType/BundleImageItem.php
src/Plugin/Field/FieldType/BundleImageItem.php
<?php namespace Drupal\commerce_product_bundles\Plugin\Field\FieldType; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\TypedData\MapDataDefinition; use Drupal\image\Plugin\Field\FieldType\ImageItem; /** * Plugin implementation of the 'bundle_image' field type. * * @FieldType( * id = "bundle_image", * label = @Translation("Bundle Image"), * description = @Translation("This field stores the ID of an image file as an integer value."), * category = @Translation("Commerce Product Bundles"), * default_widget = "bundle_image_image", * default_formatter = "image", * column_groups = { * "file" = { * "label" = @Translation("File"), * "columns" = { * "target_id", "width", "height" * }, * "require_all_groups_for_translation" = TRUE * }, * "alt" = { * "label" = @Translation("Alt"), * "translatable" = TRUE * }, * "title" = { * "label" = @Translation("Title"), * "translatable" = TRUE * }, * "product_combo" = { * "label" = @Translation("Product Combination"), * "translatable" = FALSE * }, * }, * list_class = "\Drupal\file\Plugin\Field\FieldType\FileFieldItemList", * constraints = {"ReferenceAccess" = {}, "FileValidation" = {}} * ) */ class BundleImageItem extends ImageItem { /** * {@inheritdoc} */ public static function defaultStorageSettings() { return [ 'default_image' => [ 'uuid' => NULL, 'alt' => '', 'title' => '', 'width' => NULL, 'height' => NULL, 'product_combo' => [] ], ] + parent::defaultStorageSettings(); } /** * {@inheritdoc} */ public static function schema(FieldStorageDefinitionInterface $field_definition) { $schema = parent::schema($field_definition); $schema['columns']['product_combo'] = array( 'description' => 'Product Combo ids.', 'type' => 'blob', 'size' => 'big', 'not null' => FALSE, 'serialize' => TRUE, ); return $schema; } /** * {@inheritdoc} */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties = parent::propertyDefinitions($field_definition); $properties['product_combo'] = MapDataDefinition::create() ->setLabel('Product Combo Reference'); return $properties; } /** * {@inheritdoc} */ public static function mainPropertyName() { return 'target_id'; } }