SortDeleteForm.php in Entity Share 8
File
modules/entity_share_server/src/Form/SortDeleteForm.php
View source
<?php
namespace Drupal\entity_share_server\Form;
use Drupal\Core\Form\FormStateInterface;
class SortDeleteForm extends SortBaseForm {
protected $sortId;
public function form(array $form, FormStateInterface $form_state) {
$sort_id = $this
->getsortId();
if (!$this
->sortIdExists()) {
drupal_set_message($this
->t('There is no sort with the ID @id in this channel', [
'@id' => $sort_id,
]), 'error');
return [];
}
$form = parent::form($form, $form_state);
$form['description'] = [
'#markup' => $this
->t('This action cannot be undone.'),
];
return $form;
}
public function save(array $form, FormStateInterface $form_state) {
$channel = $this->entity;
$channel_sorts = $channel
->get('channel_sorts');
unset($channel_sorts[$this
->getsortId()]);
$channel
->set('channel_sorts', $channel_sorts);
$channel
->save();
$form_state
->setRedirectUrl($channel
->toUrl('edit-form'));
}
protected function actions(array $form, FormStateInterface $form_state) {
if (!$this
->sortIdExists()) {
return [];
}
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = $this
->t('Delete sort');
$channel = $this->entity;
$actions['cancel'] = [
'#type' => 'link',
'#title' => $this
->t('Cancel'),
'#url' => $channel
->toUrl('edit-form'),
'#attributes' => [
'class' => [
'button',
],
],
];
return $actions;
}
}