GroupDeleteForm.php in Entity Share 8.2
File
modules/entity_share_server/src/Form/GroupDeleteForm.php
View source
<?php
declare (strict_types=1);
namespace Drupal\entity_share_server\Form;
use Drupal\Core\Form\FormStateInterface;
class GroupDeleteForm extends GroupBaseForm {
protected $groupId;
public function form(array $form, FormStateInterface $form_state) {
$group_id = $this
->getgroupId();
if (!$this
->groupIdExists()) {
$this
->messenger()
->addError($this
->t('There is no group with the ID @id in this channel', [
'@id' => $group_id,
]));
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_groups = $channel
->get('channel_groups');
unset($channel_groups[$this
->getgroupId()]);
$channel
->set('channel_groups', $channel_groups);
$channel
->save();
$form_state
->setRedirectUrl($channel
->toUrl('edit-form'));
}
protected function actions(array $form, FormStateInterface $form_state) {
if (!$this
->groupIdExists()) {
return [];
}
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = $this
->t('Delete group');
$channel = $this->entity;
$actions['cancel'] = [
'#type' => 'link',
'#title' => $this
->t('Cancel'),
'#url' => $channel
->toUrl('edit-form'),
'#attributes' => [
'class' => [
'button',
],
],
];
return $actions;
}
}