public function RealisticDummyContentAttribute::imageSave in Realistic Dummy Content 7.2
Same name and namespace in other branches
- 8.2 api/src/includes/RealisticDummyContentAttribute.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentAttribute::imageSave()
- 3.x api/src/includes/RealisticDummyContentAttribute.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentAttribute::imageSave()
Return an image file object if possible.
Parameters
object $file: The RealisticDummyContentFileGroup object.
Return value
null|object NULL if the file is not an image, or if an error occurred; otherwise a Drupal file object.
2 calls to RealisticDummyContentAttribute::imageSave()
- RealisticDummyContentImageField::implementValueFromFile in api/
src/ includes/ RealisticDummyContentImageField.php - Given a RealisticDummyContentFileGroup object, get a structured property.
- RealisticDummyContentUserPicture::implementValueFromFile in api/
src/ includes/ RealisticDummyContentUserPicture.php - Given a RealisticDummyContentFileGroup object, get a structured property.
File
- api/
src/ includes/ RealisticDummyContentAttribute.php, line 285
Class
- RealisticDummyContentAttribute
- Represents either a field or a property for an entity.
Namespace
Drupal\realistic_dummy_content_api\includesCode
public function imageSave($file) {
try {
$exists = $file
->value();
if (!$exists) {
throw new RealisticDummyContentException('Please check if the file exists before attempting to save it');
}
$return = NULL;
if (in_array($file
->getRadicalExtension(), $this
->getImageExtensions())) {
$return = $this
->fileSave($file);
$alt = $file
->attribute('alt');
if ($alt) {
$return->alt = $alt;
}
}
return $return;
} catch (Exception $e) {
return NULL;
}
}