function ImageItem::preSave
Same name in other branches
- 9 core/modules/image/src/Plugin/Field/FieldType/ImageItem.php \Drupal\image\Plugin\Field\FieldType\ImageItem::preSave()
- 10 core/modules/image/src/Plugin/Field/FieldType/ImageItem.php \Drupal\image\Plugin\Field\FieldType\ImageItem::preSave()
- 11.x core/modules/image/src/Plugin/Field/FieldType/ImageItem.php \Drupal\image\Plugin\Field\FieldType\ImageItem::preSave()
Overrides EntityReferenceItem::preSave
File
-
core/
modules/ image/ src/ Plugin/ Field/ FieldType/ ImageItem.php, line 312
Class
- ImageItem
- Plugin implementation of the 'image' field type.
Namespace
Drupal\image\Plugin\Field\FieldTypeCode
public function preSave() {
parent::preSave();
$width = $this->width;
$height = $this->height;
// Determine the dimensions if necessary.
if ($this->entity && $this->entity instanceof EntityInterface) {
if (empty($width) || empty($height)) {
$image = \Drupal::service('image.factory')->get($this->entity
->getFileUri());
if ($image->isValid()) {
$this->width = $image->getWidth();
$this->height = $image->getHeight();
}
}
}
else {
trigger_error(sprintf("Missing file with ID %s.", $this->target_id), E_USER_WARNING);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.