You are here

DeleteFeedForm.php in Feed Import 8

File

src/Form/DeleteFeedForm.php
View source
<?php

/**
 * @file
 * Contains \Drupal\feed_import\Form\DeleteFeedForm
 */
namespace Drupal\feed_import\Form;

use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\feed_import_base\FeedImport;

/**
 * Builds the form to delete a feed.
 */
class DeleteFeedForm extends ConfirmFormBase {

  /**
   * The feed being deleted.
   *
   * @var object containing feed settings.
   */
  protected $feed;

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'feed_import_delete';
  }

  /**
   * {@inheritdoc}
   */
  public function getQuestion() {
    return $this
      ->t('Are you sure you want to delete %feed?', array(
      '%feed' => $this->feed->name,
    ));
  }

  /**
   * {@inheritdoc}
   */
  public function getCancelUrl() {
    return new Url('feed_import.admin');
  }

  /**
   * {@inheritdoc}
   */
  public function getConfirmText() {
    return $this
      ->t('Delete');
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, $fid = NULL) {
    $this->feed = FeedImport::loadFeed($fid);
    $form['hashes'] = array(
      '#type' => 'checkbox',
      '#title' => t('Also delete hashes'),
    );
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    if (!$this->feed) {
      return;
    }
    FeedImport::deleteFeed($this->feed, (bool) $form_state
      ->getValue('hashes'));
    drupal_set_message(t('Feed deleted'));
    $form_state
      ->setRedirect('feed_import.admin');
  }

}

Classes

Namesort descending Description
DeleteFeedForm Builds the form to delete a feed.