You are here

public function DateIntervalData::setValue in Duration Field 8.2

Same name and namespace in other branches
  1. 3.0.x src/Plugin/DataType/DateIntervalData.php \Drupal\duration_field\Plugin\DataType\DateIntervalData::setValue()

Sets the data value.

Parameters

mixed|null $value: The value to set in the format as documented for the data type or NULL to unset the data value.

bool $notify: (optional) Whether to notify the parent object of the change. Defaults to TRUE. If a property is updated from a parent object, set it to FALSE to avoid being notified again.

Throws

\InvalidArgumentException If the value input is inappropriate.

\Drupal\Core\TypedData\Exception\ReadOnlyException If the data is read-only.

Overrides PrimitiveBase::setValue

File

src/Plugin/DataType/DateIntervalData.php, line 25

Class

DateIntervalData
Provides the Date Interval data type.

Namespace

Drupal\duration_field\Plugin\DataType

Code

public function setValue($value, $notify = TRUE) {
  $duration_service = \Drupal::service('duration_field.service');
  if (is_a($value, 'DateInterval')) {

    // The value should always be an ISO 8601 Duration String.
    $value = $duration_service
      ->getDurationStringFromDateInterval($value);
  }
  $duration_service
    ->checkDurationInvalid($value);
  parent::setValue($value, $notify);
}