You are here

public function BinaryData::setValue in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/TypedData/Plugin/DataType/BinaryData.php \Drupal\Core\TypedData\Plugin\DataType\BinaryData::setValue()

Overrides TypedData::setValue().

Supports a PHP file resource or an (absolute) stream resource URI as value.

Overrides PrimitiveBase::setValue

File

core/lib/Drupal/Core/TypedData/Plugin/DataType/BinaryData.php, line 53

Class

BinaryData
The binary data type.

Namespace

Drupal\Core\TypedData\Plugin\DataType

Code

public function setValue($value, $notify = TRUE) {
  if (!isset($value)) {
    $this->handle = NULL;
    $this->uri = NULL;
  }
  elseif (is_string($value)) {

    // Note: For performance reasons we store the given URI and access the
    // resource upon request. See BinaryData::getValue()
    $this->uri = $value;
    $this->handle = NULL;
  }
  else {
    $this->handle = $value;
  }

  // Notify the parent of any changes.
  if ($notify && isset($this->parent)) {
    $this->parent
      ->onChange($this->name);
  }
}