Skip to content

Commit

Permalink
Add 'Redirect URL' to CMS Form [release/2.2] (#12)
Browse files Browse the repository at this point in the history
* Add 'Redirect URL' to CMS Form
  • Loading branch information
alexandrzhulev authored Apr 4, 2022
1 parent 4c69c35 commit d3e67d0
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ public function respondAction(
// @todo extract
$notification->process($formResponse);

return new JsonResponse(['success' => true, 'message' => '@todo']);
return new JsonResponse([
'success' => true,
'message' => '@todo',
'redirectUrl' => $cmsForm->getRedirectUrl()
]);
}

$errors = [];
Expand Down
23 changes: 23 additions & 0 deletions src/B2bCode/Bundle/CmsFormBundle/Entity/CmsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ class CmsForm extends ExtendCmsForm implements DatesAwareInterface
*/
protected $notifications;

/**
* @var string|null
*
* @ORM\Column(name="redirect_url", type="string", length=1024, nullable=true)
*/
protected $redirectUrl;

public function __construct()
{
$this->fields = new ArrayCollection();
Expand Down Expand Up @@ -343,6 +350,22 @@ public function removeNotification(CmsFormNotification $notification)
return $this;
}

/**
* @return string|null
*/
public function getRedirectUrl(): ?string
{
return $this->redirectUrl;
}

/**
* @param string|null $redirectUrl
*/
public function setRedirectUrl(?string $redirectUrl): void
{
$this->redirectUrl = $redirectUrl;
}

/**
* Pre persist event handler.
*
Expand Down
13 changes: 12 additions & 1 deletion src/B2bCode/Bundle/CmsFormBundle/Form/Type/FormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

Expand Down Expand Up @@ -81,7 +82,17 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'entry_type' => NotificationType::class,
'by_reference' => false,
]
);
)
->add(
'redirectUrl',
UrlType::class,
[
'label' => 'b2bcode.cmsform.redirect_url.label',
'tooltip' => 'b2bcode.cmsform.redirect_url.tooltip',
'required' => false
]
)
;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class B2bCodeCmsFormBundleInstaller implements Installation
*/
public function getMigrationVersion()
{
return 'v1_1';
return 'v1_2';
}

/**
Expand Down Expand Up @@ -140,6 +140,7 @@ protected function createB2BCodeCmsFormTable(Schema $schema)
$table->addColumn('uuid', 'string', ['length' => 255]);
$table->addColumn('preview_enabled', 'boolean', ['notnull' => false]);
$table->addColumn('notifications_enabled', 'boolean', ['notnull' => false]);
$table->addColumn('redirect_url', 'string', ['length' => 1024, 'notnull' => false]);
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['alias'], 'uniq_e042b376e16c6b94');
$table->addUniqueIndex(['uuid'], 'uniq_e042b376d17f50a6');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace B2bCode\Bundle\CmsFormBundle\Migrations\v1_2;

use Doctrine\DBAL\Schema\Schema;
use Oro\Bundle\MigrationBundle\Migration\Migration;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;

class AddRedirectUrlField implements Migration
{
/**
* {@inheritdoc}
*/
public function up(Schema $schema, QueryBag $queries)
{
$this->addRedirectUrlField($schema);
}

/**
* @param Schema $schema
*/
protected function addRedirectUrlField(Schema $schema)
{
$table = $schema->getTable('b2b_code_cms_form');
$table->addColumn('redirect_url', 'string', ['length' => 1024, 'notnull' => false]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ B2bCode\Bundle\CmsFormBundle\Entity\CmsForm:
- NotBlank: ~
# Slugs are used for simplicity
- Oro\Bundle\ValidationBundle\Validator\Constraints\UrlSafe: ~
redirectUrl:
- Oro\Bundle\ValidationBundle\Validator\Constraints\Url: ~

B2bCode\Bundle\CmsFormBundle\Entity\CmsFormNotification:
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ define(function(require) {
__('b2bcode.cmsform.ajax.form_respond.success'),
{flash: true}
);
// to reset form
mediator.execute('refreshPage');
if (response.redirectUrl) {
window.location.href = response.redirectUrl;
} else {
// to reset form
mediator.execute('refreshPage');
}
},

onErrorHandler: function(response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ b2bcode:
label: Template
email:
label: Email

redirect_url:
label: Redirect URL
tooltip: URL to be redirected to after form is submitted successfully

cmsformfield:
entity_label: Cms Form Field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
'data': [
form_row(form.name),
form_row(form.alias),
form_row(form.previewEnabled)
form_row(form.previewEnabled),
form_row(form.redirectUrl)
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
{{ UI.renderProperty('b2bcode.cmsform.name.label'|trans, entity.name) }}
{{ UI.renderProperty('b2bcode.cmsform.alias.label'|trans, entity.alias) }}
{{ UI.renderHtmlProperty('b2bcode.cmsform.sections.preview'|trans, preview) }}
{{ UI.renderProperty('b2bcode.cmsform.redirect_url.label'|trans, entity.redirectUrl) }}
{{ UI.renderProperty('b2bcode.cmsform.notifications_enabled.label'|trans, entity.notificationsEnabled ? 'Yes'|trans : 'No'|trans) }}
{{ UI.renderHtmlProperty('b2bcode.cmsform.sections.notifications.label'|trans, notifications) }}
{{ UI.renderHtmlProperty('b2bcode.cmsform.sections.code_markup'|trans, codeMarkup) }}
Expand Down

0 comments on commit d3e67d0

Please sign in to comment.