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,
|
||||
},
|
||||
}).done((response) => {
|
||||
const formName = response.data.name ? response.data.name : MailPoet.I18n.t('noName');
|
||||
MailPoet.Notice.success(
|
||||
(MailPoet.I18n.t('formDuplicated')).replace('%$1s', response.data.name)
|
||||
(MailPoet.I18n.t('formDuplicated')).replace('%$1s', formName)
|
||||
);
|
||||
refresh();
|
||||
}).fail((response) => {
|
||||
@ -165,7 +166,7 @@ class FormList extends React.Component {
|
||||
className="row-title"
|
||||
href={`admin.php?page=mailpoet-form-editor&id=${form.id}`}
|
||||
>
|
||||
{ form.name }
|
||||
{ form.name ? form.name : `(${MailPoet.I18n.t('noName')})`}
|
||||
</a>
|
||||
</strong>
|
||||
{ actions }
|
||||
|
@ -5,6 +5,7 @@ namespace MailPoet\API\JSON\v1;
|
||||
use MailPoet\API\JSON\Endpoint as APIEndpoint;
|
||||
use MailPoet\API\JSON\Error as APIError;
|
||||
use MailPoet\Config\AccessControl;
|
||||
use MailPoet\Features\FeaturesController;
|
||||
use MailPoet\Form\Renderer as FormRenderer;
|
||||
use MailPoet\Form\Util;
|
||||
use MailPoet\Listing;
|
||||
@ -20,16 +21,21 @@ class Forms extends APIEndpoint {
|
||||
/** @var Listing\Handler */
|
||||
private $listing_handler;
|
||||
|
||||
/** @var FeaturesController */
|
||||
private $features_controller;
|
||||
|
||||
public $permissions = [
|
||||
'global' => AccessControl::PERMISSION_MANAGE_FORMS,
|
||||
];
|
||||
|
||||
function __construct(
|
||||
Listing\BulkActionController $bulk_action,
|
||||
Listing\Handler $listing_handler
|
||||
Listing\Handler $listing_handler,
|
||||
FeaturesController $features_controller
|
||||
) {
|
||||
$this->bulk_action = $bulk_action;
|
||||
$this->listing_handler = $listing_handler;
|
||||
$this->features_controller = $features_controller;
|
||||
}
|
||||
|
||||
function get($data = []) {
|
||||
@ -69,9 +75,13 @@ class Forms extends APIEndpoint {
|
||||
}
|
||||
|
||||
function create() {
|
||||
$form_name = WPFunctions::get()->__('New form', 'mailpoet');
|
||||
if ($this->features_controller->isSupported(FeaturesController::NEW_FORM_EDITOR)) {
|
||||
$form_name = '';
|
||||
}
|
||||
// create new form
|
||||
$form_data = [
|
||||
'name' => WPFunctions::get()->__('New form', 'mailpoet'),
|
||||
'name' => $form_name,
|
||||
'body' => [
|
||||
[
|
||||
'id' => 'email',
|
||||
@ -268,8 +278,9 @@ class Forms extends APIEndpoint {
|
||||
$form = Form::findOne($id);
|
||||
|
||||
if ($form instanceof Form) {
|
||||
$form_name = $form->name ? sprintf(__('Copy of %s', 'mailpoet'), $form->name) : '';
|
||||
$data = [
|
||||
'name' => sprintf(__('Copy of %s', 'mailpoet'), $form->name),
|
||||
'name' => $form_name,
|
||||
];
|
||||
$duplicate = $form->duplicate($data);
|
||||
$errors = $duplicate->getErrors();
|
||||
|
@ -380,7 +380,7 @@ class Migrator {
|
||||
function forms() {
|
||||
$attributes = [
|
||||
'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,',
|
||||
'settings longtext,',
|
||||
'styles longtext,',
|
||||
|
@ -130,8 +130,9 @@ class Widget extends \WP_Widget {
|
||||
<?php
|
||||
foreach ($forms as $form) {
|
||||
$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 } ?>
|
||||
</select>
|
||||
</p>
|
||||
|
@ -14,14 +14,6 @@ use MailPoet\WP\Functions as WPFunctions;
|
||||
class Form extends Model {
|
||||
public static $_table = MP_FORMS_TABLE;
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->addValidations('name', [
|
||||
'required' => __('Please specify a name.', 'mailpoet'),
|
||||
]);
|
||||
}
|
||||
|
||||
function getSettings() {
|
||||
return WPFunctions::get()->isSerialized($this->settings) ? unserialize($this->settings) : $this->settings;
|
||||
}
|
||||
|
@ -68,10 +68,6 @@ class FormsTest extends \MailPoetTest {
|
||||
'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);
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->data)->equals(
|
||||
|
@ -22,15 +22,6 @@ class FormTest extends \MailPoetTest {
|
||||
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() {
|
||||
$forms = Form::filter('groupBy', 'all')->findArray();
|
||||
expect($forms)->count(1);
|
||||
|
@ -61,6 +61,7 @@
|
||||
'numberOfItemsMultiple': __('%$1d items'),
|
||||
|
||||
'formName': __('Name'),
|
||||
'noName': _x('no name', 'fallback for forms without a name in a form list'),
|
||||
'segments': __('Lists'),
|
||||
'userChoice': __('User choice:'),
|
||||
'signups': __('Sign-ups'),
|
||||
|
Reference in New Issue
Block a user