I'm newbie at Magento 2, and trying to study and research code to use all business logic for my future work.

I found method getList at BlockRepository.php at https://github.com/magento/magento2/blob/2.2/app/code/Magento/Cms/Model/BlockRepository.php

Which doing something strange, as I think.

Here is the code (without docBlock):

public function getList(\Magento\Framework\Api\SearchCriteriaInterface $criteria)
    /** @var \Magento\Cms\Model\ResourceModel\Block\Collection $collection */
    $collection = $this->blockCollectionFactory->create();

    $this->collectionProcessor->process($criteria, $collection);

    /** @var Data\BlockSearchResultsInterface $searchResults */
    $searchResults = $this->searchResultsFactory->create();
    return $searchResults;

As you can see, we creating collection instance and processing it, getting the ready-to-use collection in "pager" or smth else. Why then we need to create a new instance of SearchResults and returning it instead of returning collection? I have checked, the processed collection has the same items that the searchResults instance.

Maybe I'm new at Magento and forgot something?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.