FeedImporterFormBase.php in Feed Import 8
File
src/Form/FeedImporterFormBase.php
View source
<?php
namespace Drupal\feed_import\Form;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class FeedImporterFormBase extends EntityForm {
protected $feedImporterStorage;
public function __construct(EntityStorageInterface $feed_importer_storage) {
$this->feedImporterStorage = $feed_importer_storage;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity.manager')
->getStorage('feed_importer'));
}
public function form(array $form, FormStateInterface $form_state) {
$form['label'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Feed Importer name'),
'#default_value' => $this->entity
->label(),
'#required' => TRUE,
);
$form['id'] = array(
'#type' => 'machine_name',
'#machine_name' => array(
'exists' => array(
$this->feedImporterStorage,
'load',
),
),
'#default_value' => $this->entity
->id(),
'#required' => TRUE,
);
return parent::form($form, $form_state);
}
public function save(array $form, FormStateInterface $form_state) {
parent::save($form, $form_state);
$form_state
->setRedirectUrl($this->entity
->urlInfo('edit-form'));
}
}