class FeedClearHandler in Feeds 8.3
Deletes the items of a feed.
Hierarchy
- class \Drupal\feeds\FeedHandlerBase implements EntityHandlerInterface uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait, EventDispatcherTrait
- class \Drupal\feeds\FeedClearHandler
Expanded class hierarchy of FeedClearHandler
1 file declares its use of FeedClearHandler
- FeedClearHandlerTest.php in tests/
src/ Unit/ FeedClearHandlerTest.php
File
- src/
FeedClearHandler.php, line 12
Namespace
Drupal\feedsView source
class FeedClearHandler extends FeedHandlerBase {
/**
* {@inheritdoc}
*/
public function startBatchClear(FeedInterface $feed) {
$feed
->lock();
$feed
->clearStates();
$batch = [
'title' => $this
->t('Deleting items from: %title', [
'%title' => $feed
->label(),
]),
'init_message' => $this
->t('Deleting items from: %title', [
'%title' => $feed
->label(),
]),
'operations' => [
[
[
$this,
'clear',
],
[
$feed,
],
],
],
'progress_message' => $this
->t('Deleting items from: %title', [
'%title' => $feed
->label(),
]),
'error_message' => $this
->t('An error occored while clearing %title.', [
'%title' => $feed
->label(),
]),
];
$this
->batchSet($batch);
}
/**
* Deletes all items from a feed.
*
* @param \Drupal\feeds\FeedInterface $feed
* The feed entity from which to delete all items.
* @param array $context
* Status of the batch.
*/
public function clear(FeedInterface $feed, array &$context) {
try {
$this
->dispatchEvent(FeedsEvents::INIT_CLEAR, new InitEvent($feed));
$this
->dispatchEvent(FeedsEvents::CLEAR, new ClearEvent($feed));
} catch (\Exception $exception) {
// Do nothing yet.
}
// Clean up.
$context['finished'] = $feed
->progressClearing();
if (isset($exception)) {
$context['finished'] = StateInterface::BATCH_COMPLETE;
}
if ($context['finished'] === StateInterface::BATCH_COMPLETE) {
$feed
->finishClear();
$feed
->save();
$feed
->unlock();
}
else {
$feed
->saveStates();
}
if (isset($exception)) {
throw $exception;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EventDispatcherTrait:: |
private | property | The event dispatcher service. | |
EventDispatcherTrait:: |
protected | function | Dispatches an event. | |
EventDispatcherTrait:: |
protected | function | Returns the event dispatcher service. | |
EventDispatcherTrait:: |
public | function | Sets the event dispatcher service to use. | |
FeedClearHandler:: |
public | function | Deletes all items from a feed. | |
FeedClearHandler:: |
public | function | ||
FeedHandlerBase:: |
protected | function | Adds a new batch. | |
FeedHandlerBase:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface:: |
|
FeedHandlerBase:: |
public | function | Constructs a new FeedHandlerBase object. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |