postLoad example


  public static function postDelete(EntityStorageInterface $storage, array $entities) {
    parent::postDelete($storage$entities);
    self::$postDeleteCount++;
  }

  /** * {@inheritdoc} */
  public static function postLoad(EntityStorageInterface $storage, array &$entities) {
    parent::postLoad($storage$entities);
    self::$postLoadCount++;
    self::$postLoadEntitiesCount[] = count($entities);
  }

}

  public function setIsAdmin($is_admin) {
    $this->is_admin = $is_admin;
    return $this;
  }

  /** * {@inheritdoc} */
  public static function postLoad(EntityStorageInterface $storage, array &$entities) {
    parent::postLoad($storage$entities);
    // Sort the queried roles by their weight.     // See \Drupal\Core\Config\Entity\ConfigEntityBase::sort().     uasort($entities[static::class, 'sort']);
  }

  /** * {@inheritdoc} */
  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);

    
$this->entity->postDelete($storage$entities);
  }

  /** * @covers ::postLoad */
  public function testPostLoad() {
    // This method is internal, so check for errors on calling it only.     $storage = $this->createMock('\Drupal\Core\Entity\EntityStorageInterface');
    $entities = [$this->entity];
    // Our mocked entity->postLoad() returns NULL, so assert that.     $this->assertNull($this->entity->postLoad($storage$entities));
  }

  /** * @covers ::referencedEntities */
  public function testReferencedEntities() {
    $this->assertSame([]$this->entity->referencedEntities());
  }

  /** * @covers ::getCacheTags * @covers ::getCacheTagsToInvalidate * @covers ::addCacheTags */
$entity_group_mapping = [];
    foreach ($revisions as $revision) {
      $entity_id = $revision->id();
      $entity_group_key = isset($entity_group_mapping[$entity_id]) ? $entity_group_mapping[$entity_id] + 1 : 0;
      $entity_group_mapping[$entity_id] = $entity_group_key;
      $entity_groups[$entity_group_key][$entity_id] = $revision;
    }

    // Invoke the entity hooks for each group.     foreach ($entity_groups as $entities) {
      $this->invokeStorageLoadHook($entities);
      $this->postLoad($entities);
    }

    // Ensure that the returned array is ordered the same as the original     // $ids array if this was passed in and remove any invalid IDs.     if ($revision_ids) {
      $flipped_ids = array_intersect_key(array_flip($revision_ids)$revisions);
      $revisions = array_replace($flipped_ids$revisions);
    }

    return $revisions;
  }

  
// Rebuild the router if this is a new view, or its status changed.     if (!isset($this->original) || ($this->status() != $this->original->status())) {
      \Drupal::service('router.builder')->setRebuildNeeded();
    }
  }

  /** * {@inheritdoc} */
  public static function postLoad(EntityStorageInterface $storage, array &$entities) {
    parent::postLoad($storage$entities);
    foreach ($entities as $entity) {
      $entity->mergeDefaultDisplaysOptions();
    }
  }

  /** * {@inheritdoc} */
  public static function preCreate(EntityStorageInterface $storage, array &$values) {
    parent::preCreate($storage$values);

    
// Load any remaining entities from the database. This is the case if $ids     // is set to NULL (so we load all entities) or if there are any IDs left to     // load.     if ($ids === NULL || $ids) {
      $queried_entities = $this->doLoadMultiple($ids);
    }

    // Pass all entities loaded from the database through $this->postLoad(),     // which attaches fields (if supported by the entity type) and calls the     // entity type specific load callback, for example hook_node_load().     if (!empty($queried_entities)) {
      $this->postLoad($queried_entities);
      $entities += $queried_entities;

      // Add queried entities to the cache.       $this->setStaticCache($queried_entities);
    }

    // Ensure that the returned array is ordered the same as the original     // $ids array if this was passed in and remove any invalid IDs.     if ($flipped_ids) {
      // Remove any invalid IDs from the array and preserve the order passed in.       $flipped_ids = array_intersect_key($flipped_ids$entities);
      
Home | Imprint | This part of the site doesn't use cookies.