You are here

public function OpignoScormPackageItemList::postSave in Opigno SCORM 3.x

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldType/OpignoScormPackageItemList.php \Drupal\opigno_scorm\Plugin\Field\FieldType\OpignoScormPackageItemList::postSave()

Defines custom post-save behavior for field values.

This method is called during the process of saving an entity, just after item values are written into storage.

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 FileFieldItemList::postSave

See also

\Drupal\Core\Field\FieldItemInterface::postSave()

File

src/Plugin/Field/FieldType/OpignoScormPackageItemList.php, line 15

Class

OpignoScormPackageItemList
Represents a configurable entity file field.

Namespace

Drupal\opigno_scorm\Plugin\Field\FieldType

Code

public function postSave($update) {
  parent::postSave($update);
  $scorm_controller = \Drupal::service('opigno_scorm.scorm');
  if (!$update) {

    // Extract scorm per each archive.
    foreach ($this
      ->referencedEntities() as $file) {
      $scorm_controller
        ->scormExtract($file);
    }
  }
  else {
    foreach ($this
      ->referencedEntities() as $file) {
      $scorm = $scorm_controller
        ->scormLoadByFileEntity($file);
      if (empty($scorm->id)) {
        $scorm_controller
          ->scormExtract($file);
      }
    }
  }
}