@param Collection $keywordCollection
@param array      $params

@return FacadeInterface
199917
public function transform($keywordCollection, array $params = array())
    {
        $facade = $this->newFacade();

        foreach ($keywordCollection as $keyword) {
            $facade->addKeyword($this->getContext()->transform('keyword', $keyword));
        }

        return $facade;
    }
1030223
public function generateItems(ItemInterface $templateItem, array $collections)
    {
        $result = [];
        $taxonomyCollection = [];
        $termCollection = [];
        $templateAttributes = $templateItem->getAttributes();
        $options = $this->buildAttributesResolver($templateItem);
        $taxonomyAttribute = $options['taxonomy_attribute'];
        $permalink = $options['permalink'];

        $templateAttributes['permalink'] = $options['pagination_permalink'];
        $templatePath = dirname($templateItem->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE));

        $items = (new ArrayWrapper($collections))->flatten();

        foreach ($items as $item) {
            $attributes = $item->getAttributes();

            if (isset($attributes[$taxonomyAttribute]) === false) {
                continue;
            }

            $terms = (array) $attributes[$taxonomyAttribute];

            foreach ($terms as $term) {
                if (empty(trim($term)) === true) {
                    continue;
                }

                $term = $this->normalizeTerm($term);
                $slugedTerm = (new StringWrapper($term))->slug();

                if (isset($taxonomyCollection[$slugedTerm]) === false) {
                    $taxonomyCollection[$slugedTerm] = [];
                }

                if (isset($termCollection[$slugedTerm]) === false) {
                    $termCollection[$slugedTerm] = [];
                }

                if (in_array($item, $taxonomyCollection[$slugedTerm]) === false) {
                    $taxonomyCollection[$slugedTerm][] = $item;
                }

                if (in_array($term, $termCollection[$slugedTerm]) === false) {
                    $termCollection[$slugedTerm][] = $term;
                }
            }
        }

        ksort($taxonomyCollection);

        foreach ($taxonomyCollection as $slugedTerm => $items) {
            $templateAttributes['provider'] = 'site.'.$slugedTerm;
            $templateAttributes['term'] = $termCollection[$slugedTerm][0];
            $templateItem->setAttributes($templateAttributes);
            $slugedTermPath = $this->getTermRelativePath($templatePath, $permalink, $slugedTerm);
            $templateItem->setPath($slugedTermPath, ItemInterface::SNAPSHOT_PATH_RELATIVE);

            $paginationGenerator = new PaginationGenerator();
            $itemsGenerated = $paginationGenerator->generateItems($templateItem, [$slugedTerm => $items]);

            $this->setTermsPermalink($items, $taxonomyAttribute, $termCollection[$slugedTerm], $slugedTermPath);

            $result = array_merge($result, $itemsGenerated);
        }

        return $result;
    }
1147816
private function createCollection($title, $key, $locale, $userId, $parent = null, $id = null)
    {
        $data = [
            'title' => $title,
            'key' => $key,
            'type' => ['id' => 2],
            'locale' => $locale,
        ];

        if (null !== $parent) {
            $data['parent'] = $parent;
        }

        if (null !== $id) {
            $data['id'] = $id;
        }

        return $this->collectionManager->save($data, $userId);
    }
438916
public function updateCollection(Collection $collection): void
    {
        $query = $this->connection->createQueryBuilder();
        $query
            ->update('ngbm_collection')
            ->set('start', ':start')
            ->set('length', ':length')
            ->set('translatable', ':translatable')
            ->set('main_locale', ':main_locale')
            ->set('always_available', ':always_available')
            ->where(
                $query->expr()->eq('id', ':id')
            )
            ->setParameter('id', $collection->id, Type::INTEGER)
            ->setParameter('start', $collection->offset, Type::INTEGER)
            ->setParameter('length', $collection->limit, Type::INTEGER)
            ->setParameter('translatable', $collection->isTranslatable, Type::BOOLEAN)
            ->setParameter('main_locale', $collection->mainLocale, Type::STRING)
            ->setParameter('always_available', $collection->alwaysAvailable, Type::BOOLEAN);

        $this->applyStatusCondition($query, $collection->status);

        $query->execute();
    }
585769
public function renderFormCollection($params, $content, \Smarty_Internal_Template $template, &$repeat)
    {
        /**
         * Get parameters
         */
        $form = $this->getInstanceFromParams($params);
        $row = $this->getSymfonyFormFromParams($params, "row");
        $collection = $this->resolveCollection($this->getParam($params, "collection"), $form);

        $hash = $this->initializeCollection($form, $collection, $row);

        $limit = $this->getParam($params, "limit", -1);

        /**
         * Check if it has a limit
         */
        if (!preg_match("#^\-?\d+$#", $limit)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'limit' parameter in 'form_collection'. '%s' given, integer expected",
                    $limit
                )
            );
        }

        /**
         * Then load stack and create the stack count
         */
        $limit = (int)$limit;
        $hasLimit = $limit >= 0;

        /**
         * If we have reached the limit, stop
         */
        $collectionLimit = $this->formCollectionCount[$hash]["limit"];

        if (($hasLimit && $limit === $collectionLimit) ||
            null === $row = array_shift($this->formCollectionStack[$hash])
        ) {
            $repeat = false;

            /**
             * Reload stack limit
             */
            $this->formCollectionCount[$hash]["limit"] = 0;

            return $content;
        }

        /**
         * Assign variables into the template
         */
        $template->assign("row", $row);
        $template->assign("collection_current", $this->formCollectionCount[$hash]["count"]++);
        $template->assign("collection_count", $this->formCollectionCount[$hash]["total_count"]);

        /**
         * Increment the current limit state
         * Force the repeat
         */
        $this->formCollectionCount[$hash]["limit"]++;
        $repeat = true;

        /**
         * ANd return the content
         */

        return $content;
    }
845420
protected function configureRoutes(RouteCollection $collection)
    {
        parent::configureRoutes($collection);
        $collection->add('duplicate', $this->getRouterIdParameter() . '/duplicate');
        $collection->add('generateEntityCode');

        /* Needed or not needed ...
         * in sonata-project/admin-bundle/Controller/CRUDController.php
         * the batchAction method
         * throw exception if the http method is not POST
        */
        if ($collection->get('batch')) {
            $collection->get('batch')->setMethods(['POST']);
        }
    }
1106362
public function searchCollection($query, array $parameters = [], array $headers = [])
    {
        return $this->get('search/collection', array_merge($parameters, [
            'query' => $query
        ], $headers));
    }
1027820
public function getCollection($collectionId, $fields = ['*'])
    {
        $apiUrl = $this->getEndpoint('collections');
        $apiUrl .= $collectionId;

        $params = array(
            'fields' => implode(',', $fields)
        );

        $apiData = $this->apiGet($apiUrl, $params);

        return $this->decodeSingle($apiData);
    }
829314
protected function setBreadcrumbToCollection(Collection $collection, $locale, $breadcrumbEntities)
    {
        $breadcrumbApiEntities = [];
        foreach ($breadcrumbEntities as $entity) {
            $breadcrumbApiEntities[] = $this->getApiEntity($entity, $locale);
        }
        $collection->setBreadcrumb($breadcrumbApiEntities);

        return $collection;
    }
53317
protected function collection_query( &$collection ) 
	{
		$local_keys = array();
		
		foreach( $collection as $item )
		{
			$local_keys[] = $item->raw( $this->local_key );
		}
		
		// set the correct collection where
		$this->query->wheres = array();
		$this->query->where( $this->foreign_key, 'in', $local_keys );
		$this->query->group_result( $this->foreign_key );
		
		$this->query->limit( null );
	}
454670
public function formCollectionCount($params, \Smarty_Internal_Template $template)
    {
        /**
         * Get parameters
         */
        $form = $this->getInstanceFromParams($params);
        $row = $this->getSymfonyFormFromParams($params, "row");
        $collection = $this->resolveCollection($this->getParam($params, "collection"), $form);

        $hash = $this->initializeCollection($form, $collection, $row);

        return $this->formCollectionCount[$hash]["total_count"];
    }
959612
public function addCollector($collector, $name = null, array $params = null) {
		// Collector instance
		if ($collector instanceof CollectorInterface) {
			if ($name === null) {
				$class = get_class($collector);
				$name  = substr($class, strrpos($class, '\\') + 1);
			}
		}
		// String definition
		else if (is_string($collector)) {
			if ($name === null) {
				$name = $collector;
			}

			$collector = $this->loadCollector($collector, $params);
		}
		// Array definition
		else if (is_array($collector)) {
			$type = isset($collector['type']) ? $collector['type'] : $collector[0];

			// Define a name
			switch (true) {
				case $name !== null:
					break;

				case isset($collector['name']):
					$name = $collector['name'];
					break;

				case count($collector) > 2:
					$name = $collector[1];
					break;

				default:
					$name = $type;
			}

			// Define a params
			switch (true) {
				case isset($collector['params']):
					$collectorParams = $collector['params'];
					break;

				case count($collector) > 2:
					$collectorParams = $collector[2];
					break;

				default:
					$collectorParams = $collector[1];
			}

			if ($params !== null) {
				$collectorParams += $params;
			}

			$collector = $this->loadCollector($type, $collectorParams);
		}
		
		// Name collision handling
		while (isset($this->collectors[$name])) {
			if (preg_match('/[0-9]+$/', $name, $matches)) {
				$name = preg_replace_callback('/([0-9]+)$/', function($match) {
					return ((int) $match[1]) + 1;
				}, $name);
			} else {
				$name .= 2;
			}
		}
		
		if ($collector !== null) {
			$this->collectors[$name] = $collector;
		}
		
		return $collector;
	}
838407
public function keys(): CollectionInterface
    {
        return $this->wrap(function (Iterator $data) {
            foreach ($data as $key => $value) {
                yield $key;
            }
        });
    }
1297093
public function createCollectionTranslation(Collection $collection, string $locale): void
    {
        $query = $this->connection->createQueryBuilder()
            ->insert('ngbm_collection_translation')
            ->values(
                [
                    'collection_id' => ':collection_id',
                    'status' => ':status',
                    'locale' => ':locale',
                ]
            )
            ->setParameter('collection_id', $collection->id, Type::INTEGER)
            ->setParameter('status', $collection->status, Type::INTEGER)
            ->setParameter('locale', $locale, Type::STRING);

        $query->execute();
    }
991226
protected function _getCollection(KModelEntityInterface $collection)
    {
        $result = array();

        foreach ($collection as $entity) {
            $result[] = $this->_getEntity($entity);
        }

        return $result;
    }
734494
public function scanCollection($collection, $fields)
    {
        $fields = (array) $fields;
        foreach ($collection as $item) {
            $this->collectIdsFromItem($item, $fields);
        }

        return $this;
    }
1290645
public function transform($trashItemCollection, array $params = array())
    {
        $facade = $this->newFacade();

        foreach ($trashItemCollection as $trashItem) {
            $facade->addElement($this->getContext()->transform('trash_item', $trashItem));
        }

        return $facade;
    }