Newer
Older
<?php
/**
* @file
* Contains \Drupal\path\Form\EditForm.
*/
namespace Drupal\path\Form;
use Drupal\Component\Utility\String;
Dries Buytaert
committed
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Provides the path edit form.
*/
class EditForm extends PathFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'path_admin_edit';
}
/**
* {@inheritdoc}
*/
protected function buildPath($pid) {
return $this->aliasStorage->load(array('pid' => $pid));
}
/**
* {@inheritdoc}
*/
Dries Buytaert
committed
public function buildForm(array $form, FormStateInterface $form_state, $pid = NULL) {
$form = parent::buildForm($form, $form_state, $pid);
$form['#title'] = String::checkPlain($this->path['alias']);
$form['pid'] = array(
'#type' => 'hidden',
'#value' => $this->path['pid'],
);
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => $this->t('Delete'),
'#submit' => array(array($this, 'deleteSubmit')),
);
return $form;
}
/**
* Submits the delete form.
*/
Dries Buytaert
committed
public function deleteSubmit(array &$form, FormStateInterface $form_state) {
Alex Pott
committed
$url = new Url('path.delete', array(
Alex Pott
committed
'pid' => $form_state->getValue('pid'),
));
if ($this->getRequest()->query->has('destination')) {
Alex Pott
committed
$url->setOption('query', drupal_get_destination());
$this->getRequest()->query->remove('destination');
}
Alex Pott
committed
$form_state->setRedirectUrl($url);