SubgroupFormStep2.php in Subgroup (Graph) 1.0.x
File
src/Form/SubgroupFormStep2.php
View source
<?php
namespace Drupal\ggroup\Form;
use Drupal\group\Entity\Form\GroupContentForm;
use Drupal\user\PrivateTempStoreFactory;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SubgroupFormStep2 extends GroupContentForm {
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$form['entity_id']['#access'] = FALSE;
return $form;
}
protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = $this
->t('Create subgroup');
$actions['back'] = [
'#type' => 'submit',
'#value' => $this
->t('Back'),
'#submit' => [
'::submitForm',
'::back',
],
'#limit_validation_errors' => [],
];
return $actions;
}
public function save(array $form, FormStateInterface $form_state) {
$storage_id = $form_state
->get('storage_id');
$store = $this->privateTempStoreFactory
->get('ggroup_add_temp');
$group = $store
->get("{$storage_id}:group");
$group
->save();
$this->entity
->set('entity_id', $group
->id());
$store
->delete("{$storage_id}:step");
$store
->delete("{$storage_id}:group");
return parent::save($form, $form_state);
}
public function back(array &$form, FormStateInterface $form_state) {
$storage_id = $form_state
->get('storage_id');
$store = $this->privateTempStoreFactory
->get('ggroup_add_temp');
$store
->set("{$storage_id}:step", 1);
$request = $this
->getRequest();
$form_state
->setRedirectUrl(Url::fromRoute('<current>', [], [
'query' => $request->query
->all(),
]));
$request->query
->remove('destination');
}
}