Issue #2217783 by mondrake: Remove $extension and $mimeType from Image, use image_type_to_xxx function in the getters instead.
parent
c1cf341bdd
commit
2176bfda8c
|
@ -47,13 +47,6 @@ class Image implements ImageInterface {
|
|||
*/
|
||||
protected $width = 0;
|
||||
|
||||
/**
|
||||
* Commonly used file extension for the image.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $extension = '';
|
||||
|
||||
/**
|
||||
* Image type represented by a PHP IMAGETYPE_* constant (e.g. IMAGETYPE_JPEG).
|
||||
*
|
||||
|
@ -61,13 +54,6 @@ class Image implements ImageInterface {
|
|||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* MIME type (e.g. 'image/jpeg', 'image/gif', 'image/png').
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mimeType = '';
|
||||
|
||||
/**
|
||||
* File size in bytes.
|
||||
*
|
||||
|
@ -110,14 +96,6 @@ class Image implements ImageInterface {
|
|||
return $this->processed;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getExtension() {
|
||||
$this->processInfo();
|
||||
return $this->extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -171,7 +149,7 @@ class Image implements ImageInterface {
|
|||
*/
|
||||
public function getMimeType() {
|
||||
$this->processInfo();
|
||||
return $this->mimeType;
|
||||
return $this->type ? image_type_to_mime_type($this->type) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -250,15 +228,7 @@ class Image implements ImageInterface {
|
|||
$this->height = $details['height'];
|
||||
$this->width = $details['width'];
|
||||
$this->type = $details['type'];
|
||||
$this->mimeType = $details['mime_type'];
|
||||
$this->fileSize = filesize($destination);
|
||||
$this->extension = pathinfo($destination, PATHINFO_EXTENSION);
|
||||
|
||||
// It may be a temporary file, without extension, or an image created from
|
||||
// an image resource. Fallback to default extension for this image type.
|
||||
if (empty($this->extension)) {
|
||||
$this->extension = image_type_to_extension($this->type, FALSE);
|
||||
}
|
||||
|
||||
$this->processed = TRUE;
|
||||
}
|
||||
|
|
|
@ -28,14 +28,6 @@ interface ImageInterface {
|
|||
*/
|
||||
public function isExisting();
|
||||
|
||||
/**
|
||||
* Returns the extension of the image file.
|
||||
*
|
||||
* @return string
|
||||
* The extension of the file, or an empty string if the file is invalid.
|
||||
*/
|
||||
public function getExtension();
|
||||
|
||||
/**
|
||||
* Returns the height of the image file.
|
||||
*
|
||||
|
@ -93,7 +85,8 @@ interface ImageInterface {
|
|||
* Returns the MIME type of the image file.
|
||||
*
|
||||
* @return string
|
||||
* The MIME type of the file, or an empty string if the file is invalid.
|
||||
* The MIME type of the image file, or an empty string if the image is
|
||||
* invalid.
|
||||
*/
|
||||
public function getMimeType();
|
||||
|
||||
|
|
|
@ -199,7 +199,6 @@ interface ImageToolkitInterface extends PluginInspectionInterface {
|
|||
* - "width": Width, in pixels.
|
||||
* - "height": Height, in pixels.
|
||||
* - "type": Image type represented as an IMAGETYPE_* constant.
|
||||
* - "mime_type": MIME type (e.g. 'image/jpeg', 'image/gif', 'image/png').
|
||||
*
|
||||
* @see \Drupal\Core\Image\ImageInterface::processInfo()
|
||||
*/
|
||||
|
|
|
@ -166,7 +166,7 @@ class ImageWidget extends FileWidget {
|
|||
}
|
||||
else {
|
||||
$image = \Drupal::service('image.factory')->get($file->getFileUri());
|
||||
if ($image->getExtension()) {
|
||||
if ($image->isExisting()) {
|
||||
$variables['width'] = $image->getWidth();
|
||||
$variables['height'] = $image->getHeight();
|
||||
}
|
||||
|
|
|
@ -309,7 +309,6 @@ class GDToolkit extends ImageToolkitBase {
|
|||
'width' => $data[0],
|
||||
'height' => $data[1],
|
||||
'type' => $data[2],
|
||||
'mime_type' => $data['mime'],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -253,7 +253,7 @@ class ToolkitGdTest extends DrupalUnitTestBase {
|
|||
|
||||
$directory = $this->public_files_directory .'/imagetest';
|
||||
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
|
||||
$image->save($directory . '/' . $op . '.' . $image->getExtension());
|
||||
$image->save($directory . '/' . $op . image_type_to_extension($image->getType()));
|
||||
|
||||
$this->assertTrue($correct_dimensions_real, String::format('Image %file after %action action has proper dimensions.', array('%file' => $file, '%action' => $op)));
|
||||
$this->assertTrue($correct_dimensions_object, String::format('Image %file object after %action action is reporting the proper height and width values.', array('%file' => $file, '%action' => $op)));
|
||||
|
|
|
@ -59,7 +59,6 @@ class TestToolkit extends ImageToolkitBase {
|
|||
'width' => $data[0],
|
||||
'height' => $data[1],
|
||||
'type' => $data[2],
|
||||
'mime_type' => $data['mime'],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -77,13 +77,6 @@ class ImageTest extends UnitTestCase {
|
|||
->getMock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests \Drupal\Core\Image\Image::getExtension().
|
||||
*/
|
||||
public function testGetExtension() {
|
||||
$this->assertEquals($this->image->getExtension(), 'png');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests \Drupal\Core\Image\Image::getHeight().
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue