function BinaryData::setValue

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/TypedData/Plugin/DataType/BinaryData.php \Drupal\Core\TypedData\Plugin\DataType\BinaryData::setValue()
  2. 8.9.x core/lib/Drupal/Core/TypedData/Plugin/DataType/BinaryData.php \Drupal\Core\TypedData\Plugin\DataType\BinaryData::setValue()
  3. 10 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 54

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);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.