SubgroupFormStep1.php in Subgroup (Graph) 1.0.x
File
src/Form/SubgroupFormStep1.php
View source
<?php
namespace Drupal\ggroup\Form;
use Drupal\group\Entity\Form\GroupForm;
use Drupal\user\PrivateTempStoreFactory;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SubgroupFormStep1 extends GroupForm {
protected function actions(array $form, FormStateInterface $form_state) {
$actions['submit'] = [
'#type' => 'submit',
'#value' => $form_state
->get('wizard') ? $this
->t('Continue to final step') : $this
->t('Create subgroup'),
'#submit' => [
'::submitForm',
'::saveTemporary',
],
];
$actions['cancel'] = [
'#type' => 'submit',
'#value' => $this
->t('Cancel'),
'#submit' => [
'::cancel',
],
'#limit_validation_errors' => [],
];
return $actions;
}
public function saveTemporary(array &$form, FormStateInterface $form_state) {
$storage_id = $form_state
->get('storage_id');
$store = $this->privateTempStoreFactory
->get('ggroup_add_temp');
$store
->set("{$storage_id}:group", $this->entity);
$store
->set("{$storage_id}:step", 2);
$request = $this
->getRequest();
$form_state
->setRedirectUrl(Url::fromRoute('<current>', [], [
'query' => $request->query
->all(),
]));
$request->query
->remove('destination');
}
public function cancel(array &$form, FormStateInterface $form_state) {
$group = $form_state
->get('group');
$storage_id = $form_state
->get('storage_id');
$store = $this->privateTempStoreFactory
->get('ggroup_add_temp');
$store
->delete("{$storage_id}:group");
$form_state
->setRedirect('entity.group.canonical', [
'group' => $group
->id(),
]);
}
}