diff --git a/assets/js/src/forms/list.jsx b/assets/js/src/forms/list.jsx index fb335262fe..985de9cde8 100644 --- a/assets/js/src/forms/list.jsx +++ b/assets/js/src/forms/list.jsx @@ -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')})`} { actions } diff --git a/lib/API/JSON/v1/Forms.php b/lib/API/JSON/v1/Forms.php index 4ab708460e..5549b4a4df 100644 --- a/lib/API/JSON/v1/Forms.php +++ b/lib/API/JSON/v1/Forms.php @@ -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(); diff --git a/lib/Config/Migrator.php b/lib/Config/Migrator.php index 94698dc66c..8037b47612 100644 --- a/lib/Config/Migrator.php +++ b/lib/Config/Migrator.php @@ -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,', diff --git a/lib/Form/Widget.php b/lib/Form/Widget.php index e93aecd4d0..3555858e6f 100644 --- a/lib/Form/Widget.php +++ b/lib/Form/Widget.php @@ -130,8 +130,9 @@ class Widget extends \WP_Widget { wp->escHtml($form['name']) : "({$this->wp->_x('no name', 'fallback for forms without a name in a form list')})" ?> - +

diff --git a/lib/Models/Form.php b/lib/Models/Form.php index 2e47978faa..b0e162e8d9 100644 --- a/lib/Models/Form.php +++ b/lib/Models/Form.php @@ -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; } diff --git a/tests/integration/API/JSON/v1/FormsTest.php b/tests/integration/API/JSON/v1/FormsTest.php index 5cc2186432..9fb529b997 100644 --- a/tests/integration/API/JSON/v1/FormsTest.php +++ b/tests/integration/API/JSON/v1/FormsTest.php @@ -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( diff --git a/tests/integration/Models/FormTest.php b/tests/integration/Models/FormTest.php index 4a6f6648a4..e4f5bf73a6 100644 --- a/tests/integration/Models/FormTest.php +++ b/tests/integration/Models/FormTest.php @@ -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); diff --git a/views/forms.html b/views/forms.html index b801f77cb8..2f54ddeb95 100644 --- a/views/forms.html +++ b/views/forms.html @@ -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'),