You are here

public function Feed::getState in Feeds 8.3

Returns a state object for a given stage.

Lazily instantiates new states.

Parameters

string $stage: One of StateInterface::FETCH, StateInterface::PARSE, StateInterface::PROCESS or StateInterface::CLEAR.

Return value

\Drupal\feeds\StateInterface The State object for the given stage.

Overrides FeedInterface::getState

3 calls to Feed::getState()
Feed::finishClear in src/Entity/Feed.php
Cleans up after an import.
Feed::finishImport in src/Entity/Feed.php
Cleans up after an import.
Feed::progressImporting in src/Entity/Feed.php
Reports the progress of the import process.

File

src/Entity/Feed.php, line 366

Class

Feed
Defines the feed entity class.

Namespace

Drupal\feeds\Entity

Code

public function getState($stage) {
  if (!isset($this->states[$stage])) {
    $state = \Drupal::keyValue('feeds_feed.' . $this
      ->id())
      ->get($stage);
    if (empty($state)) {

      // @todo move this logic to a factory or alike.
      switch ($stage) {
        case StateInterface::CLEAN:
          $state = new CleanState($this
            ->id());
          break;
        default:
          $state = new State();
          break;
      }
    }
    $this->states[$stage] = $state;
  }
  return $this->states[$stage];
}