FeedDeleteForm.php in Feeds 8.3
File
src/Form/FeedDeleteForm.php
View source
<?php
namespace Drupal\feeds\Form;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Form\FormStateInterface;
class FeedDeleteForm extends ContentEntityConfirmFormBase {
public function getQuestion() {
return $this
->t('Are you sure you want to delete the feed %feed?', [
'%feed' => $this->entity
->label(),
]);
}
public function getDescription() {
$item_count = $this->entity
->getItemCount();
if (!$item_count) {
$message = $this
->t('This feed has no imported items.');
}
else {
$message = $this
->formatPlural($item_count, 'This feed has 1 imported item that will remain on the site.', 'This feed has @count imported items that will remain on the site.');
}
return $message . ' ' . parent::getDescription();
}
public function getCancelUrl() {
return $this->entity
->toUrl();
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity
->delete();
try {
$args = [
'@type' => $this->entity
->getType()
->label(),
'%title' => $this->entity
->label(),
];
$this
->logger('feeds')
->notice('@type: deleted %title.', $args);
} catch (EntityStorageException $e) {
$args = [
'@type' => $this->entity
->bundle(),
'%title' => $this->entity
->label(),
];
$this
->logger('feeds')
->notice('Deleted %title of unknown feed type @type.', $args);
}
$this
->messenger()
->addMessage($this
->t('%title has been deleted.', $args));
$form_state
->setRedirect('feeds.admin');
}
}