<?php
namespace Drupal\image\Type;
use Drupal\Core\Entity\Field\FieldItemBase;
class ImageItem extends FieldItemBase {
static $propertyDefinitions;
public function getPropertyDefinitions() {
if (!isset(static::$propertyDefinitions)) {
static::$propertyDefinitions['fid'] = array(
'type' => 'integer',
'label' => t('Referenced file id.'),
);
static::$propertyDefinitions['alt'] = array(
'type' => 'boolean',
'label' => t("Alternative image text, for the image's 'alt' attribute."),
);
static::$propertyDefinitions['title'] = array(
'type' => 'string',
'label' => t("Image title text, for the image's 'title' attribute."),
);
static::$propertyDefinitions['width'] = array(
'type' => 'integer',
'label' => t('The width of the image in pixels.'),
);
static::$propertyDefinitions['height'] = array(
'type' => 'integer',
'label' => t('The height of the image in pixels.'),
);
static::$propertyDefinitions['entity'] = array(
'type' => 'entity',
'constraints' => array(
'EntityType' => 'file',
),
'label' => t('Image'),
'description' => t('The referenced file'),
'computed' => TRUE,
'read-only' => FALSE,
'settings' => array(
'id source' => 'fid',
),
);
}
return static::$propertyDefinitions;
}
public function setValue($values, $notify = TRUE) {
if (isset($values) && !is_array($values)) {
$values = array(
'entity' => $values,
);
}
if (isset($values['fid']) && !isset($values['entity'])) {
$values['entity'] = $values['fid'];
}
parent::setValue($values, $notify);
}
}