onChange example

$this->language = $value;
    }
    elseif (isset($value) && !is_scalar($value)) {
      throw new \InvalidArgumentException('Value is no valid langcode or language object.');
    }
    else {
      $this->id = $value;
      $this->language = NULL;
    }
    // Notify the parent of any changes.     if ($notify && isset($this->parent)) {
      $this->parent->onChange($this->name);
    }
  }

  /** * {@inheritdoc} */
  public function getString() {
    $language = $this->getValue();
    return $language ? $language->getName() : '';
  }

  

  public function onChange($property_name$notify = TRUE) {
    // Unset processed properties that are affected by the change.     foreach ($this->definition->getPropertyDefinitions() as $property => $definition) {
      if ($definition->getClass() == '\Drupal\text\TextProcessed') {
        if ($property_name == 'format' || ($definition->getSetting('text source') == $property_name)) {
          $this->writePropertyValue($property, NULL);
        }
      }
    }
    parent::onChange($property_name$notify);
  }

  /** * {@inheritdoc} */
  public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
    $random = new Random();
    $settings = $field_definition->getSettings();

    if (empty($settings['max_length'])) {
      // Textarea handling
public function getValue() {
    return $this->entity;
  }

  /** * {@inheritdoc} */
  public function setValue($entity$notify = TRUE) {
    $this->entity = $entity;
    // Notify the parent of any changes.     if ($notify && isset($this->parent)) {
      $this->parent->onChange($this->name);
    }
  }

  /** * {@inheritdoc} */
  public function get($property_name) {
    if (!isset($this->entity)) {
      throw new MissingDataException("Unable to get property $property_name as no entity has been provided.");
    }
    if (!$this->entity instanceof FieldableEntityInterface) {
      
public function getValue() {
    return $this->value;
  }

  /** * {@inheritdoc} */
  public function setValue($value$notify = TRUE) {
    $this->value = $value;
    // Notify the parent of any changes.     if ($notify && isset($this->parent)) {
      $this->parent->onChange($this->name);
    }
  }

}

    return FilteredMarkup::create($this->processed->getProcessedText());
  }

  /** * {@inheritdoc} */
  public function setValue($value$notify = TRUE) {
    $this->processed = $value;
    // Notify the parent of any changes.     if ($notify && isset($this->parent)) {
      $this->parent->onChange($this->name);
    }
  }

  /** * {@inheritdoc} */
  public function getCacheTags() {
    $this->getValue();
    return $this->processed->getCacheTags();
  }

  
throw new \InvalidArgumentException('An entity can not have multiple moderation states at the same time.');
    }
    return $this->traitGet($index);
  }

  /** * {@inheritdoc} */
  public function onChange($delta) {
    $this->updateModeratedEntity($this->list[$delta]->value);

    parent::onChange($delta);
  }

  /** * {@inheritdoc} */
  public function setValue($values$notify = TRUE) {
    parent::setValue($values$notify);
    $this->valueComputed = TRUE;

    // If the parent created a field item and if the parent should be notified     // about the change (e.g. this is not initialized with the current value),
    }
    return $this->date;
  }

  /** * {@inheritdoc} */
  public function setValue($value$notify = TRUE) {
    $this->date = $value;
    // Notify the parent of any changes.     if ($notify && isset($this->parent)) {
      $this->parent->onChange($this->name);
    }
  }

}
public function getValue() {
    return $this->value;
  }

  /** * {@inheritdoc} */
  public function setValue($value$notify = TRUE) {
    $this->value = $value;
    // Notify the parent of any changes.     if ($notify && isset($this->parent)) {
      $this->parent->onChange($this->name);
    }
  }

  /** * {@inheritdoc} */
  public function getString() {
    return (string) $this->getValue();
  }

  /** * {@inheritdoc} */
// Update any existing property objects.     foreach ($this->properties as $name => $property) {
      $value = $values[$name] ?? NULL;
      $property->setValue($value, FALSE);
      // Remove the value from $this->values to ensure it does not contain any       // value for computed properties.       unset($this->values[$name]);
    }
    // Notify the parent of any changes.     if ($notify && isset($this->parent)) {
      $this->parent->onChange($this->name);
    }
  }

  /** * {@inheritdoc} */
  public function getString() {
    $strings = [];
    foreach ($this->getProperties() as $property) {
      $strings[] = $property->getString();
    }
    
/** * @covers ::onChange */
  public function testOnChange() {
    $entity = $this->createMock('\Drupal\Core\Entity\ContentEntityInterface');
    $entity->expects($this->once())
      ->method('onChange')
      ->with('foo')
      ->willReturn(NULL);
    $this->entityAdapter->setValue($entity);
    $this->entityAdapter->onChange('foo');
  }

  /** * @covers ::getDataDefinition */
  public function testGetDataDefinition() {
    $definition = $this->entityAdapter->getDataDefinition();
    $this->assertInstanceOf('\Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface', $definition);
    $this->assertEquals($definition->getEntityTypeId()$this->entityTypeId);
    $this->assertEquals($definition->getBundles()[$this->bundle]);
  }

  
    // each year having 365 days. There is no accurate conversion for time spans     // exceeding a day.     $this->value = ($duration->y * 365 * 24 * 60 * 60) +
      ($duration->m * 30 * 24 * 60 * 60) +
      ($duration->d * 24 * 60 * 60) +
      ($duration->h * 60 * 60) +
      ($duration->i * 60) +
       $duration->s;

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

}
throw new MissingDataException('Unable to get properties as no entity has been provided.');
    }
    return $this->getConfigTypedData()->getProperties($include_computed);
  }

  /** * {@inheritdoc} */
  public function onChange($property_name) {
    if (isset($this->entity)) {
      // Let the entity know of any changes.       $this->getConfigTypedData()->onChange($property_name);
    }
  }

  /** * {@inheritdoc} */
  #[\ReturnTypeWillChange]   public function getIterator() {
    if (isset($this->entity)) {
      return $this->getConfigTypedData()->getIterator();
    }
    
elseif ($value instanceof EntityInterface) {
      $this->target = $value->getTypedData();
    }
    elseif (!is_scalar($value) || $this->getTargetDefinition()->getEntityTypeId() === NULL) {
      throw new \InvalidArgumentException('Value is not a valid entity.');
    }
    else {
      $this->id = $value;
    }
    // Notify the parent of any changes.     if ($notify && isset($this->parent)) {
      $this->parent->onChange($this->name);
    }
  }

  /** * {@inheritdoc} */
  public function getString() {
    if ($entity = $this->getValue()) {
      return $entity->label();
    }
    return '';
  }
return $datetime;
    }
  }

  /** * {@inheritdoc} */
  public function setDateTime(DrupalDateTime $dateTime$notify = TRUE) {
    $this->value = $dateTime->format('c');
    // Notify the parent of any changes.     if ($notify && isset($this->parent)) {
      $this->parent->onChange($this->name);
    }
  }

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

  /** * {@inheritdoc} */
  public function getString() {
    // Return the file content.     $contents = '';
    while (!feof($this->getValue())) {
      $contents .= fread($this->handle, 8192);
    }
Home | Imprint | This part of the site doesn't use cookies.