You are here

public function RealisticDummyContentAttribute::imageSave in Realistic Dummy Content 3.x

Same name and namespace in other branches
  1. 8.2 api/src/includes/RealisticDummyContentAttribute.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentAttribute::imageSave()
  2. 7.2 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.

1 call to RealisticDummyContentAttribute::imageSave()
RealisticDummyContentImageField::implementValueFromFile in api/src/includes/RealisticDummyContentImageField.php
Given a RealisticDummyContentFileGroup object, get a structured property.

File

api/src/includes/RealisticDummyContentAttribute.php, line 290

Class

RealisticDummyContentAttribute
Represents either a field or a property for an entity.

Namespace

Drupal\realistic_dummy_content_api\includes

Code

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 (\Throwable $t) {
    $this
      ->watchdogThrowable($t);
    return NULL;
  }
}