By megachriz on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x-3.x
Introduced in version:
8.x-3.0-rc1
Issue links:
Description:
A factory for creating instances of \Drupal\feeds\State or \Drupal\feeds\Feeds\State\CleanState is added. Both State and CleanState got dependency injection added. This means that instances of these classes can no longer be created directly, they now have to be created using the service.
Code example
Before
use Drupal\feeds\State;
use Drupal\feeds\Feeds\State\CleanState;
$state = new State();
/** @var \Drupal\feeds\FeedInterface $feed */
$clean_state = new CleanState($feed->id());
After
use Drupal\feeds\StateInterface;
/** @var \Drupal\feeds\FeedInterface $feed */
/** @var string $stage */
/** @var \Drupal\feeds\State $state */
$state = \Drupal::service('feeds.state_factory')->createInstance($feed, $stage);
/** @var \Drupal\feeds\FeedInterface $feed */
/** @var \Drupal\feeds\Feeds\State\CleanState $clean_state */
$clean_state = \Drupal::service('feeds.state_factory')->createInstance($feed, StateInterface::CLEAN);
Unit testing
If you are extending Feeds test classes and create State or CleanState objects in there, there are now two new methods added to \Drupal\Tests\feeds\Traits\FeedsMockingTrait to create instances of these classes with their dependencies mocked:
/** @var \Drupal\feeds\State $state */
$state = $this->createFeedsState();
/** @var \Drupal\feeds\Feeds\State\CleanState $clean_state */
$clean_state = $this->createFeedsCleanState();
Impacts:
Module developers