Skip to content

Commit d3e67d0

Browse files
Add 'Redirect URL' to CMS Form [release/2.2] (#12)
* Add 'Redirect URL' to CMS Form
1 parent 4c69c35 commit d3e67d0

File tree

10 files changed

+83
-7
lines changed

10 files changed

+83
-7
lines changed

src/B2bCode/Bundle/CmsFormBundle/Controller/Frontend/AjaxFormController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ public function respondAction(
6969
// @todo extract
7070
$notification->process($formResponse);
7171

72-
return new JsonResponse(['success' => true, 'message' => '@todo']);
72+
return new JsonResponse([
73+
'success' => true,
74+
'message' => '@todo',
75+
'redirectUrl' => $cmsForm->getRedirectUrl()
76+
]);
7377
}
7478

7579
$errors = [];

src/B2bCode/Bundle/CmsFormBundle/Entity/CmsForm.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ class CmsForm extends ExtendCmsForm implements DatesAwareInterface
136136
*/
137137
protected $notifications;
138138

139+
/**
140+
* @var string|null
141+
*
142+
* @ORM\Column(name="redirect_url", type="string", length=1024, nullable=true)
143+
*/
144+
protected $redirectUrl;
145+
139146
public function __construct()
140147
{
141148
$this->fields = new ArrayCollection();
@@ -343,6 +350,22 @@ public function removeNotification(CmsFormNotification $notification)
343350
return $this;
344351
}
345352

353+
/**
354+
* @return string|null
355+
*/
356+
public function getRedirectUrl(): ?string
357+
{
358+
return $this->redirectUrl;
359+
}
360+
361+
/**
362+
* @param string|null $redirectUrl
363+
*/
364+
public function setRedirectUrl(?string $redirectUrl): void
365+
{
366+
$this->redirectUrl = $redirectUrl;
367+
}
368+
346369
/**
347370
* Pre persist event handler.
348371
*

src/B2bCode/Bundle/CmsFormBundle/Form/Type/FormType.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
1818
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
1919
use Symfony\Component\Form\Extension\Core\Type\TextType;
20+
use Symfony\Component\Form\Extension\Core\Type\UrlType;
2021
use Symfony\Component\Form\FormBuilderInterface;
2122
use Symfony\Component\OptionsResolver\OptionsResolver;
2223

@@ -81,7 +82,17 @@ public function buildForm(FormBuilderInterface $builder, array $options)
8182
'entry_type' => NotificationType::class,
8283
'by_reference' => false,
8384
]
84-
);
85+
)
86+
->add(
87+
'redirectUrl',
88+
UrlType::class,
89+
[
90+
'label' => 'b2bcode.cmsform.redirect_url.label',
91+
'tooltip' => 'b2bcode.cmsform.redirect_url.tooltip',
92+
'required' => false
93+
]
94+
)
95+
;
8596
}
8697

8798
/**

src/B2bCode/Bundle/CmsFormBundle/Migrations/Schema/B2bCodeCmsFormBundleInstaller.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class B2bCodeCmsFormBundleInstaller implements Installation
2727
*/
2828
public function getMigrationVersion()
2929
{
30-
return 'v1_1';
30+
return 'v1_2';
3131
}
3232

3333
/**
@@ -140,6 +140,7 @@ protected function createB2BCodeCmsFormTable(Schema $schema)
140140
$table->addColumn('uuid', 'string', ['length' => 255]);
141141
$table->addColumn('preview_enabled', 'boolean', ['notnull' => false]);
142142
$table->addColumn('notifications_enabled', 'boolean', ['notnull' => false]);
143+
$table->addColumn('redirect_url', 'string', ['length' => 1024, 'notnull' => false]);
143144
$table->setPrimaryKey(['id']);
144145
$table->addUniqueIndex(['alias'], 'uniq_e042b376e16c6b94');
145146
$table->addUniqueIndex(['uuid'], 'uniq_e042b376d17f50a6');
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace B2bCode\Bundle\CmsFormBundle\Migrations\v1_2;
4+
5+
use Doctrine\DBAL\Schema\Schema;
6+
use Oro\Bundle\MigrationBundle\Migration\Migration;
7+
use Oro\Bundle\MigrationBundle\Migration\QueryBag;
8+
9+
class AddRedirectUrlField implements Migration
10+
{
11+
/**
12+
* {@inheritdoc}
13+
*/
14+
public function up(Schema $schema, QueryBag $queries)
15+
{
16+
$this->addRedirectUrlField($schema);
17+
}
18+
19+
/**
20+
* @param Schema $schema
21+
*/
22+
protected function addRedirectUrlField(Schema $schema)
23+
{
24+
$table = $schema->getTable('b2b_code_cms_form');
25+
$table->addColumn('redirect_url', 'string', ['length' => 1024, 'notnull' => false]);
26+
}
27+
}

src/B2bCode/Bundle/CmsFormBundle/Resources/config/validation.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ B2bCode\Bundle\CmsFormBundle\Entity\CmsForm:
2727
- NotBlank: ~
2828
# Slugs are used for simplicity
2929
- Oro\Bundle\ValidationBundle\Validator\Constraints\UrlSafe: ~
30+
redirectUrl:
31+
- Oro\Bundle\ValidationBundle\Validator\Constraints\Url: ~
3032

3133
B2bCode\Bundle\CmsFormBundle\Entity\CmsFormNotification:
3234
properties:

src/B2bCode/Bundle/CmsFormBundle/Resources/public/js/app/components/form-component.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,12 @@ define(function(require) {
7070
__('b2bcode.cmsform.ajax.form_respond.success'),
7171
{flash: true}
7272
);
73-
// to reset form
74-
mediator.execute('refreshPage');
73+
if (response.redirectUrl) {
74+
window.location.href = response.redirectUrl;
75+
} else {
76+
// to reset form
77+
mediator.execute('refreshPage');
78+
}
7579
},
7680

7781
onErrorHandler: function(response) {

src/B2bCode/Bundle/CmsFormBundle/Resources/translations/messages.en.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ b2bcode:
3535
label: Template
3636
email:
3737
label: Email
38-
38+
redirect_url:
39+
label: Redirect URL
40+
tooltip: URL to be redirected to after form is submitted successfully
3941

4042
cmsformfield:
4143
entity_label: Cms Form Field

src/B2bCode/Bundle/CmsFormBundle/Resources/views/Form/update.html.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
'data': [
4242
form_row(form.name),
4343
form_row(form.alias),
44-
form_row(form.previewEnabled)
44+
form_row(form.previewEnabled),
45+
form_row(form.redirectUrl)
4546
]
4647
}
4748
]

src/B2bCode/Bundle/CmsFormBundle/Resources/views/Form/view.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
{{ UI.renderProperty('b2bcode.cmsform.name.label'|trans, entity.name) }}
6767
{{ UI.renderProperty('b2bcode.cmsform.alias.label'|trans, entity.alias) }}
6868
{{ UI.renderHtmlProperty('b2bcode.cmsform.sections.preview'|trans, preview) }}
69+
{{ UI.renderProperty('b2bcode.cmsform.redirect_url.label'|trans, entity.redirectUrl) }}
6970
{{ UI.renderProperty('b2bcode.cmsform.notifications_enabled.label'|trans, entity.notificationsEnabled ? 'Yes'|trans : 'No'|trans) }}
7071
{{ UI.renderHtmlProperty('b2bcode.cmsform.sections.notifications.label'|trans, notifications) }}
7172
{{ UI.renderHtmlProperty('b2bcode.cmsform.sections.code_markup'|trans, codeMarkup) }}

0 commit comments

Comments
 (0)