Allow saving forms without name
[MAILPOET-2450]
This commit is contained in:
committed by
Jack Kitterhing
parent
96f71416b4
commit
b0ef65a1eb
@ -104,8 +104,9 @@ const itemActions = [
|
|||||||
id: item.id,
|
id: item.id,
|
||||||
},
|
},
|
||||||
}).done((response) => {
|
}).done((response) => {
|
||||||
|
const formName = response.data.name ? response.data.name : MailPoet.I18n.t('noName');
|
||||||
MailPoet.Notice.success(
|
MailPoet.Notice.success(
|
||||||
(MailPoet.I18n.t('formDuplicated')).replace('%$1s', response.data.name)
|
(MailPoet.I18n.t('formDuplicated')).replace('%$1s', formName)
|
||||||
);
|
);
|
||||||
refresh();
|
refresh();
|
||||||
}).fail((response) => {
|
}).fail((response) => {
|
||||||
@ -165,7 +166,7 @@ class FormList extends React.Component {
|
|||||||
className="row-title"
|
className="row-title"
|
||||||
href={`admin.php?page=mailpoet-form-editor&id=${form.id}`}
|
href={`admin.php?page=mailpoet-form-editor&id=${form.id}`}
|
||||||
>
|
>
|
||||||
{ form.name }
|
{ form.name ? form.name : `(${MailPoet.I18n.t('noName')})`}
|
||||||
</a>
|
</a>
|
||||||
</strong>
|
</strong>
|
||||||
{ actions }
|
{ actions }
|
||||||
|
@ -5,6 +5,7 @@ namespace MailPoet\API\JSON\v1;
|
|||||||
use MailPoet\API\JSON\Endpoint as APIEndpoint;
|
use MailPoet\API\JSON\Endpoint as APIEndpoint;
|
||||||
use MailPoet\API\JSON\Error as APIError;
|
use MailPoet\API\JSON\Error as APIError;
|
||||||
use MailPoet\Config\AccessControl;
|
use MailPoet\Config\AccessControl;
|
||||||
|
use MailPoet\Features\FeaturesController;
|
||||||
use MailPoet\Form\Renderer as FormRenderer;
|
use MailPoet\Form\Renderer as FormRenderer;
|
||||||
use MailPoet\Form\Util;
|
use MailPoet\Form\Util;
|
||||||
use MailPoet\Listing;
|
use MailPoet\Listing;
|
||||||
@ -20,16 +21,21 @@ class Forms extends APIEndpoint {
|
|||||||
/** @var Listing\Handler */
|
/** @var Listing\Handler */
|
||||||
private $listing_handler;
|
private $listing_handler;
|
||||||
|
|
||||||
|
/** @var FeaturesController */
|
||||||
|
private $features_controller;
|
||||||
|
|
||||||
public $permissions = [
|
public $permissions = [
|
||||||
'global' => AccessControl::PERMISSION_MANAGE_FORMS,
|
'global' => AccessControl::PERMISSION_MANAGE_FORMS,
|
||||||
];
|
];
|
||||||
|
|
||||||
function __construct(
|
function __construct(
|
||||||
Listing\BulkActionController $bulk_action,
|
Listing\BulkActionController $bulk_action,
|
||||||
Listing\Handler $listing_handler
|
Listing\Handler $listing_handler,
|
||||||
|
FeaturesController $features_controller
|
||||||
) {
|
) {
|
||||||
$this->bulk_action = $bulk_action;
|
$this->bulk_action = $bulk_action;
|
||||||
$this->listing_handler = $listing_handler;
|
$this->listing_handler = $listing_handler;
|
||||||
|
$this->features_controller = $features_controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get($data = []) {
|
function get($data = []) {
|
||||||
@ -69,9 +75,13 @@ class Forms extends APIEndpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function create() {
|
function create() {
|
||||||
|
$form_name = WPFunctions::get()->__('New form', 'mailpoet');
|
||||||
|
if ($this->features_controller->isSupported(FeaturesController::NEW_FORM_EDITOR)) {
|
||||||
|
$form_name = '';
|
||||||
|
}
|
||||||
// create new form
|
// create new form
|
||||||
$form_data = [
|
$form_data = [
|
||||||
'name' => WPFunctions::get()->__('New form', 'mailpoet'),
|
'name' => $form_name,
|
||||||
'body' => [
|
'body' => [
|
||||||
[
|
[
|
||||||
'id' => 'email',
|
'id' => 'email',
|
||||||
@ -268,8 +278,9 @@ class Forms extends APIEndpoint {
|
|||||||
$form = Form::findOne($id);
|
$form = Form::findOne($id);
|
||||||
|
|
||||||
if ($form instanceof Form) {
|
if ($form instanceof Form) {
|
||||||
|
$form_name = $form->name ? sprintf(__('Copy of %s', 'mailpoet'), $form->name) : '';
|
||||||
$data = [
|
$data = [
|
||||||
'name' => sprintf(__('Copy of %s', 'mailpoet'), $form->name),
|
'name' => $form_name,
|
||||||
];
|
];
|
||||||
$duplicate = $form->duplicate($data);
|
$duplicate = $form->duplicate($data);
|
||||||
$errors = $duplicate->getErrors();
|
$errors = $duplicate->getErrors();
|
||||||
|
@ -380,7 +380,7 @@ class Migrator {
|
|||||||
function forms() {
|
function forms() {
|
||||||
$attributes = [
|
$attributes = [
|
||||||
'id int(11) unsigned NOT NULL AUTO_INCREMENT,',
|
'id int(11) unsigned NOT NULL AUTO_INCREMENT,',
|
||||||
'name varchar(90) NOT NULL,',
|
'name varchar(90) NOT NULL,', // should be null but db_delta can't handle this change
|
||||||
'body longtext,',
|
'body longtext,',
|
||||||
'settings longtext,',
|
'settings longtext,',
|
||||||
'styles longtext,',
|
'styles longtext,',
|
||||||
|
@ -130,8 +130,9 @@ class Widget extends \WP_Widget {
|
|||||||
<?php
|
<?php
|
||||||
foreach ($forms as $form) {
|
foreach ($forms as $form) {
|
||||||
$is_selected = ($selected_form === (int)$form['id']) ? 'selected="selected"' : '';
|
$is_selected = ($selected_form === (int)$form['id']) ? 'selected="selected"' : '';
|
||||||
|
$form_name = $form['name'] ? $this->wp->escHtml($form['name']) : "({$this->wp->_x('no name', 'fallback for forms without a name in a form list')})"
|
||||||
?>
|
?>
|
||||||
<option value="<?php echo (int)$form['id']; ?>" <?php echo $is_selected; ?>><?php echo WPFunctions::get()->escHtml($form['name']); ?></option>
|
<option value="<?php echo (int)$form['id']; ?>" <?php echo $is_selected; ?>><?php echo $form_name; ?></option>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</p>
|
||||||
|
@ -14,14 +14,6 @@ use MailPoet\WP\Functions as WPFunctions;
|
|||||||
class Form extends Model {
|
class Form extends Model {
|
||||||
public static $_table = MP_FORMS_TABLE;
|
public static $_table = MP_FORMS_TABLE;
|
||||||
|
|
||||||
function __construct() {
|
|
||||||
parent::__construct();
|
|
||||||
|
|
||||||
$this->addValidations('name', [
|
|
||||||
'required' => __('Please specify a name.', 'mailpoet'),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSettings() {
|
function getSettings() {
|
||||||
return WPFunctions::get()->isSerialized($this->settings) ? unserialize($this->settings) : $this->settings;
|
return WPFunctions::get()->isSerialized($this->settings) ? unserialize($this->settings) : $this->settings;
|
||||||
}
|
}
|
||||||
|
@ -68,10 +68,6 @@ class FormsTest extends \MailPoetTest {
|
|||||||
'name' => 'My first form',
|
'name' => 'My first form',
|
||||||
];
|
];
|
||||||
|
|
||||||
$response = $this->endpoint->save(/* missing data */);
|
|
||||||
expect($response->status)->equals(APIResponse::STATUS_BAD_REQUEST);
|
|
||||||
expect($response->errors[0]['message'])->equals('Please specify a name.');
|
|
||||||
|
|
||||||
$response = $this->endpoint->save($form_data);
|
$response = $this->endpoint->save($form_data);
|
||||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||||
expect($response->data)->equals(
|
expect($response->data)->equals(
|
||||||
|
@ -22,15 +22,6 @@ class FormTest extends \MailPoetTest {
|
|||||||
expect($this->form->getErrors())->false();
|
expect($this->form->getErrors())->false();
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItHasToBeValid() {
|
|
||||||
$invalid_form = Form::create();
|
|
||||||
$result = $invalid_form->save();
|
|
||||||
$errors = $result->getErrors();
|
|
||||||
|
|
||||||
expect(is_array($errors))->true();
|
|
||||||
expect($errors[0])->equals('Please specify a name.');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testItCanBeGrouped() {
|
function testItCanBeGrouped() {
|
||||||
$forms = Form::filter('groupBy', 'all')->findArray();
|
$forms = Form::filter('groupBy', 'all')->findArray();
|
||||||
expect($forms)->count(1);
|
expect($forms)->count(1);
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
'numberOfItemsMultiple': __('%$1d items'),
|
'numberOfItemsMultiple': __('%$1d items'),
|
||||||
|
|
||||||
'formName': __('Name'),
|
'formName': __('Name'),
|
||||||
|
'noName': _x('no name', 'fallback for forms without a name in a form list'),
|
||||||
'segments': __('Lists'),
|
'segments': __('Lists'),
|
||||||
'userChoice': __('User choice:'),
|
'userChoice': __('User choice:'),
|
||||||
'signups': __('Sign-ups'),
|
'signups': __('Sign-ups'),
|
||||||
|
Reference in New Issue
Block a user