You are here

public function FileLinkItem::postSave in File Link 2.0.x

Defines custom post-save behavior for field values.

This method is called during the process of saving an entity, just after values are written into storage. This is useful mostly when the business logic to be implemented always requires the entity identifier, even when storing a new entity. For instance, when implementing circular entity references, the referenced entity will be created on pre-save with a dummy value for the referring entity identifier, which will be updated with the actual one on post-save.

In the rare cases where item properties depend on the entity identifier, massaging logic will have to be implemented on post-save and returning TRUE will allow them to be rewritten to the storage with the updated values.

Parameters

bool $update: Specifies whether the entity is being updated or created.

Return value

bool Whether field items should be rewritten to the storage as a consequence of the logic implemented by the custom behavior.

Overrides FieldItemBase::postSave

File

src/Plugin/Field/FieldType/FileLinkItem.php, line 276

Class

FileLinkItem
Implements a 'file_link' plugin field type.

Namespace

Drupal\file_link\Plugin\Field\FieldType

Code

public function postSave($update) {
  if ($this->needsParsing && $this
    ->needsQueue()) {

    // We need to queue the entity update in postSave because we need to
    // know the entity id so that we can load it in cron and re-save it.
    $entity = $this
      ->getEntity();
    $rev = $entity instanceof RevisionableInterface ? $entity
      ->getRevisionId() : NULL;
    $item = new FileLinkQueueItem($entity
      ->getEntityTypeId(), $entity
      ->id(), $entity
      ->language()
      ->getId(), $rev);
    if (!in_array($item
      ->getKey(), static::$queued)) {
      $this
        ->getQueue()
        ->createItem($item);

      // Save the queued entity in a static cache so that we don't queue it
      // more than once when using a multi-value field.
      static::$queued[] = $item
        ->getKey();
    }
  }
  return parent::postSave($update);
}