From 5fec8a89bc59b457e9741e074f06af4f971c2815 Mon Sep 17 00:00:00 2001 From: s j <sj@1729.be> Date: Mon, 9 May 2022 15:59:12 +0200 Subject: [PATCH] imp: add save-and-edit on PlanEventForm --- .gitlab-ci/build.php | 6 +++ .../src/Form/PlanEventForm.php | 51 ++++++++++++++++++- .../tests/src/Functional/LoadTest.php | 7 +++ tests/src/Functional/LoadTest.php | 9 +++- 4 files changed, 71 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci/build.php b/.gitlab-ci/build.php index 976537e..bced101 100644 --- a/.gitlab-ci/build.php +++ b/.gitlab-ci/build.php @@ -50,6 +50,12 @@ $this->taskComposerConfig() ->repository("1", "https://packages.drupal.org/8", "composer") ->run(); +$this->taskComposerConfig() + ->noInteraction() + ->noAnsi() + ->workingDir($this->docRoot) + ->args(["minimum-stability", "dev"]) + ->run(); $this->composerRequire() ->dependency('drupal/inline_entity_form', '^1.0') diff --git a/modules/resource_planning_template/src/Form/PlanEventForm.php b/modules/resource_planning_template/src/Form/PlanEventForm.php index a9edb59..2f9748c 100644 --- a/modules/resource_planning_template/src/Form/PlanEventForm.php +++ b/modules/resource_planning_template/src/Form/PlanEventForm.php @@ -5,6 +5,10 @@ namespace Drupal\resource_planning_template\Form; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; +use Drupal\Core\Ajax\AjaxResponse; +use Drupal\Core\Ajax\RedirectCommand; +use Drupal\Core\Url; + use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Form\FormBase; @@ -120,15 +124,51 @@ class PlanEventForm extends FormBase { '#target_type' => 'rp_event_template', '#required' => TRUE, ]; - $form['submit'] = [ + + $form['actions'] = [ + '#type' => 'actions', + ]; + $form['actions']['submit'] = [ '#type' => 'submit', '#value' => $this->t('Submit'), '#weight' => '100', + '#name' => 'save', + ]; + $form['actions']['submit_and_edit'] = [ + '#type' => 'submit', + '#value' => $this->t('Submit & Edit'), + '#weight' => '110', + '#name' => 'save_and_edit', + '#ajax' => [ + 'callback' => '::submitFormAjax', + 'effect' => 'fade', + 'event' => 'click', + 'progress' => [ + 'type' => 'throbber', + 'message' => $this->t('Processing ...'), + ], + ], ]; return $form; } + /** + * {@inheritdoc} + */ + public function submitFormAjax(array &$form, FormStateInterface $form_state) { + $this->submitForm($form, $form_state); + $url = Url::fromRoute( + 'entity.rp_event.edit_form', + [ + 'rp_event' => $this->event->id(), + ] + ); + $response = new AjaxResponse(); + $response->addCommand(new RedirectCommand($url->toString())); + return $response; + } + /** * {@inheritdoc} */ @@ -151,6 +191,15 @@ class PlanEventForm extends FormBase { ] ) ); + + if ($form_state->getTriggeringElement()['#name'] == 'save_and_edit') { + $form_state->setRedirect( + 'entity.rp_event.edit_form', + [ + 'rp_event' => $this->event->id(), + ] + ); + } } } diff --git a/modules/resource_planning_template/tests/src/Functional/LoadTest.php b/modules/resource_planning_template/tests/src/Functional/LoadTest.php index b18cca3..d0f779c 100644 --- a/modules/resource_planning_template/tests/src/Functional/LoadTest.php +++ b/modules/resource_planning_template/tests/src/Functional/LoadTest.php @@ -12,6 +12,13 @@ use Drupal\Tests\BrowserTestBase; */ class LoadTest extends BrowserTestBase { + /** + * Theme to use. + * + * @var string + */ + protected $defaultTheme = 'stark'; + /** * Modules to enable. * diff --git a/tests/src/Functional/LoadTest.php b/tests/src/Functional/LoadTest.php index 37aa598..28a1a0f 100644 --- a/tests/src/Functional/LoadTest.php +++ b/tests/src/Functional/LoadTest.php @@ -12,12 +12,19 @@ use Drupal\Tests\BrowserTestBase; */ class LoadTest extends BrowserTestBase { + /** + * Theme to use. + * + * @var string + */ + protected $defaultTheme = 'stark'; + /** * Modules to enable. * * @var array */ - public static $modules = ['resource_planning']; + protected static $modules = ['resource_planning']; /** * A user with permission to administer site configuration. -- GitLab