@param PersistentCollectionInterface $collection

@return void
14457
private function loadEmbedManyCollection(PersistentCollectionInterface $collection)
    {
        $rawData = $collection->getRawData();

        if ($rawData) {
            $mapping = $collection->getMapping();
            $owner   = $collection->getOwner();

            foreach ($rawData as $key => $data) {
                if ($mapping->type === Type::MAP) {
                    $key = (string)$key;
                } else {
                    $key = (int)$key;
                }

                $embeddedDocument = $this->uow->getAssociationPersister()->loadEmbed($mapping, $data, $owner, $key, $collection->isReadOnly());

                if ($mapping->type === Type::MAP) {
                    $collection->set($key, $embeddedDocument);
                } else {
                    $collection->add($embeddedDocument);
                }
            }
        }
    }
4008
protected function getDeleteRowSQL(PersistentCollection $collection)
    {
        $mapping     = $collection->getMapping();
        $class       = $this->em->getClassMetadata($mapping['sourceEntity']);
        $targetClass = $this->em->getClassMetadata($mapping['targetEntity']);
        $columns     = array();
        $types       = array();

        foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) {
            $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform);
            $types[]   = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $class, $this->em);
        }

        foreach ($mapping['joinTable']['inverseJoinColumns'] as $joinColumn) {
            $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $targetClass, $this->platform);
            $types[]   = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em);
        }

        return array(
            'DELETE FROM ' . $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform)
            . ' WHERE ' . implode(' = ? AND ', $columns) . ' = ?',
            $types,
        );
    }
287625
public function postCollectionLoad(PersistentCollectionInterface $coll)
    {
        $eventArgs = new PostCollectionLoadEventArgs($coll, $this->dm);
        $this->evm->dispatchEvent(Event::postCollectionLoad, $eventArgs);
    }
1180573
public function decorate(Collection $collection)
    {
        if ($this->storeManager->isSingleStoreMode()) {
            return;
        }

        $this->addLinkedWebsiteIds($collection);
        $this->ensureWebsiteLinkedSet($collection);
    }
974889
public function update(PersistentCollectionInterface $coll)
    {
        $mapping = $coll->getMapping();

        if ($mapping->isInverseSide) {
            return; // ignore inverse side
        }

        switch ($mapping->strategy) {
            case PropertyMetadata::STORAGE_STRATEGY_ATOMIC_SET:
                throw new \UnexpectedValueException(sprintf('%s update collection strategy should have been handled by DocumentPersister. Please report a bug in issue tracker', $mapping->strategy));

            case PropertyMetadata::STORAGE_STRATEGY_SET:
                $this->setCollection($coll);
                break;

            case PropertyMetadata::STORAGE_STRATEGY_ADD_TO_SET:
            case PropertyMetadata::STORAGE_STRATEGY_LIST_APPEND:
                $coll->initialize();
                $this->deleteElements($coll);
                $this->insertElements($coll);
                break;

            default:
                throw new \UnexpectedValueException(sprintf('Unsupported collection strategy: %s', $mapping->strategy));
        }
    }
778985
final public function persistMany(array $collection, array $fillable = array())
    {
        foreach ($collection as $item) {
            $this->persist($item, $fillable);
        }

        return true;
    }
192156
private function setCollection(PersistentCollectionInterface $coll)
    {
        list($qb, $path, $parent) = $this->getQueryPathAndParent($coll);

        $coll->initialize();

        $path->set($coll);
        $this->executeQuery($qb, $parent);
    }
427615
public function setPersistent($persists)
    {
        if (is_string($persists)) {
            $persists = $persists === 'true' ? true : false;
        }
        $this->persistent = $persists;
    }
1106069
public function merge(ObjectCollectionInterface $collection)
    {
        $this->items = array_merge(
            $this->getItems(),
            $collection->getItems()
        );

        return $this;
    }
793182
public function loadCollection(PersistentCollectionInterface $collection)
    {
        $mapping = $collection->getMapping();
        switch ($mapping->association) {
            case PropertyMetadata::ASSOCIATION_TYPE_EMBED_MANY:
                $this->loadEmbedManyCollection($collection);
                break;

            case PropertyMetadata::ASSOCIATION_TYPE_REFERENCE_MANY:
                if ($mapping->repositoryMethod !== null) {
                    $this->loadReferenceManyWithRepositoryMethod($collection);
                } else {
                    if ($mapping->isOwningSide) {
                        $this->loadReferenceManyCollectionOwningSide($collection);
                    } else {
                        $this->loadReferenceManyCollectionInverseSide($collection);
                    }
                }
                break;
        }
    }
15213
private function fillFromCollection(
        ParameterDefinitionCollectionInterface $definitionCollection,
        ParameterCollectionInterface $parameters
    ): void {
        foreach ($definitionCollection->getParameterDefinitions() as $name => $definition) {
            $value = null;

            if ($parameters->hasParameter($name)) {
                $parameter = $parameters->getParameter($name);
                if ($parameter->getParameterDefinition()->getType()::getIdentifier() === $definition->getType()::getIdentifier()) {
                    $value = $parameter->getValue();
                    $value = is_object($value) ? clone $value : $value;
                }
            }

            $this->setParameterValue($name, $value);

            if ($definition instanceof CompoundParameterDefinition) {
                $this->fillFromCollection($definition, $parameters);
            }
        }
    }
1092024
public function republishCommand(string $collection = 'persistent'): void
    {
        $collectionName = $collection;
        $collection = $this->resourceManager->getCollection($collectionName);
        if (!$collection) {
            $this->outputLine('<error>The collection %s does not exist.</error>', [$collectionName]);
            exit(1);
        }

        $target = $collection->getTarget();
        if (!$target instanceof GcsTarget) {
            $this->outputLine('<error>The target defined in collection %s is not a Google Cloud Storage target.</error>', [$collectionName]);
            exit(1);
        }

        $this->outputLine('Republishing collection ...');
        $this->output->progressStart();
        try {
            foreach ($collection->getObjects() as $object) {
                /** @var StorageObject $object */
                $resource = $this->resourceManager->getResourceBySha1($object->getSha1());
                if ($resource) {
                    $target->publishResource($resource, $collection);
                }
                $this->output->progressAdvance();
            }
        } catch (\Exception $e) {
            $this->outputLine('<error>Publishing failed</error>');
            $this->outputLine($e->getMessage());
            $this->outputLine(get_class($e));
            exit(2);
        }
        $this->output->progressFinish();
        $this->outputLine();
    }
1289396
private function deleteElements(PersistentCollectionInterface $coll)
    {
        $deleteDiff = $coll->getDeleteDiff();

        if (empty($deleteDiff)) {
            return;
        }

        $mapping = $coll->getMapping();

        /** @var RootPath $collPath */
        list($qb, $collPath, $parent) = $this->getQueryPathAndParent($coll);

        foreach ($deleteDiff as $key => $document) {
            switch ($mapping->strategy) {
                case PropertyMetadata::STORAGE_STRATEGY_LIST_APPEND:
                    $path = $mapping->type === Type::LIST_ ? $collPath->i($key) : $collPath->map($key);
                    $path->remove();
                    break;
                case PropertyMetadata::STORAGE_STRATEGY_ADD_TO_SET:
                    //mapping drivers / classmetadatafactory ensure this strategy is
                    //only assigned to top-level documents

                    /** @var RootAttribute $collPath */
                    $collPath->delete($document);
                    break;
                default:
                    throw new \LogicException(sprintf('Invalid strategy %s given for insertElements', $mapping->strategy));
            }
        }

        $this->executeQuery($qb, $parent);
    }
166227
public function loadCollection(PersistentCollection $collection)
    {
        $association = $collection->getMapping();
        $persister   = $this->getEntityPersister($association->getTargetEntity());

        if ($association instanceof OneToManyAssociationMetadata) {
            $persister->loadOneToManyCollection($association, $collection->getOwner(), $collection);
        } else {
            $persister->loadManyToManyCollection($association, $collection->getOwner(), $collection);
        }

        $collection->setInitialized(true);
    }
812254
private function handleEditAllButton(CollectionInterface $collection, EnvironmentInterface $environment)
    {
        if (0 < $collection->count()) {
            return;
        }

        $dataDefinition = $environment->getDataDefinition();
        $backendView    = $dataDefinition->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
        $globalCommands = $backendView->getGlobalCommands();

        if (!$globalCommands->hasCommandNamed('all')) {
            return;
        }

        $allCommand = $globalCommands->getCommandNamed('all');
        $allCommand->setDisabled(true);
    }
148649
public function addCollection(Collection $collection)
    {
        $metadata = $collection->getDocumentMetadata();
        $this->collectionMapping[$metadata->getName()] = $collection;
    }
500720
public function setTranslations(Collection $collection)
    {
        $this->translations = new ArrayCollection();

        foreach ($collection as $translation) {
            $this->addTranslation($translation);
        }
    }