collection = $collectionFactory->create(); $this->request = $request; } /** * {@inheritdoc} */ public function getCollection() { /** @var Collection $collection */ $collection = parent::getCollection(); if (!$this->getPost()) { return $collection; } $collection->addFieldToFilter( $collection->getIdFieldName(), ['nin' => [$this->getPost()->getId()]] ); return $this->addCollectionFilters($collection); } /** * Retrieve post * * @return PostInterface|null */ protected function getPost() { if (null !== $this->post) { return $this->post; } if (!($id = $this->request->getParam('current_post_id'))) { return null; } return $this->post = $this->postRepository->getById($id); } }