Remove new form editor feature flag

[MAILPOET-2549]
This commit is contained in:
Rostislav Wolny
2020-01-21 09:54:46 +01:00
committed by Jack Kitterhing
parent 139b3691bf
commit 447e01b0aa
13 changed files with 31 additions and 108 deletions

View File

@ -5,7 +5,6 @@ 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;
@ -21,9 +20,6 @@ class Forms extends APIEndpoint {
/** @var Listing\Handler */ /** @var Listing\Handler */
private $listingHandler; private $listingHandler;
/** @var FeaturesController */
private $featuresController;
/** @var Util\Styles */ /** @var Util\Styles */
private $formStylesUtils; private $formStylesUtils;
@ -34,12 +30,10 @@ class Forms extends APIEndpoint {
public function __construct( public function __construct(
Listing\BulkActionController $bulkAction, Listing\BulkActionController $bulkAction,
Listing\Handler $listingHandler, Listing\Handler $listingHandler,
FeaturesController $featuresController,
Util\Styles $formStylesUtils Util\Styles $formStylesUtils
) { ) {
$this->bulkAction = $bulkAction; $this->bulkAction = $bulkAction;
$this->listingHandler = $listingHandler; $this->listingHandler = $listingHandler;
$this->featuresController = $featuresController;
$this->formStylesUtils = $formStylesUtils; $this->formStylesUtils = $formStylesUtils;
} }
@ -80,13 +74,9 @@ class Forms extends APIEndpoint {
} }
public function create() { public function create() {
$formName = WPFunctions::get()->__('New form', 'mailpoet');
if ($this->featuresController->isSupported(FeaturesController::NEW_FORM_EDITOR)) {
$formName = '';
}
// create new form // create new form
$formData = [ $formData = [
'name' => $formName, 'name' => '',
'body' => [ 'body' => [
[ [
'id' => 'email', 'id' => 'email',
@ -96,6 +86,7 @@ class Forms extends APIEndpoint {
'params' => [ 'params' => [
'label' => WPFunctions::get()->__('Email', 'mailpoet'), 'label' => WPFunctions::get()->__('Email', 'mailpoet'),
'required' => true, 'required' => true,
'label_within' => true,
], ],
], ],
[ [
@ -115,11 +106,6 @@ class Forms extends APIEndpoint {
'segments_selected_by' => 'admin', 'segments_selected_by' => 'admin',
], ],
]; ];
if ($this->featuresController->isSupported(FeaturesController::NEW_FORM_EDITOR)) {
$formData['body'][0]['params']['label_within'] = true;
}
return $this->save($formData); return $this->save($formData);
} }

View File

@ -5,11 +5,9 @@ namespace MailPoet\AdminPages\Pages;
use MailPoet\AdminPages\PageRenderer; use MailPoet\AdminPages\PageRenderer;
use MailPoet\API\JSON\ResponseBuilders\CustomFieldsResponseBuilder; use MailPoet\API\JSON\ResponseBuilders\CustomFieldsResponseBuilder;
use MailPoet\CustomFields\CustomFieldsRepository; use MailPoet\CustomFields\CustomFieldsRepository;
use MailPoet\Features\FeaturesController;
use MailPoet\Form\Block; use MailPoet\Form\Block;
use MailPoet\Form\Renderer as FormRenderer; use MailPoet\Form\Renderer as FormRenderer;
use MailPoet\Form\Util\Export; use MailPoet\Form\Util\Export;
use MailPoet\Models\CustomField;
use MailPoet\Models\Form; use MailPoet\Models\Form;
use MailPoet\Models\Segment; use MailPoet\Models\Segment;
use MailPoet\Settings\Pages; use MailPoet\Settings\Pages;
@ -18,9 +16,6 @@ class FormEditor {
/** @var PageRenderer */ /** @var PageRenderer */
private $pageRenderer; private $pageRenderer;
/** @var FeaturesController */
private $featuresController;
/** @var CustomFieldsRepository */ /** @var CustomFieldsRepository */
private $customFieldsRepository; private $customFieldsRepository;
@ -29,12 +24,10 @@ class FormEditor {
public function __construct( public function __construct(
PageRenderer $pageRenderer, PageRenderer $pageRenderer,
FeaturesController $featuresController,
CustomFieldsRepository $customFieldsRepository, CustomFieldsRepository $customFieldsRepository,
CustomFieldsResponseBuilder $customFieldsResponseBuilder CustomFieldsResponseBuilder $customFieldsResponseBuilder
) { ) {
$this->pageRenderer = $pageRenderer; $this->pageRenderer = $pageRenderer;
$this->featuresController = $featuresController;
$this->customFieldsRepository = $customFieldsRepository; $this->customFieldsRepository = $customFieldsRepository;
$this->customFieldsResponseBuilder = $customFieldsResponseBuilder; $this->customFieldsResponseBuilder = $customFieldsResponseBuilder;
} }
@ -45,7 +38,9 @@ class FormEditor {
if ($form instanceof Form) { if ($form instanceof Form) {
$form = $form->asArray(); $form = $form->asArray();
} }
$form['styles'] = FormRenderer::getStyles($form);
$customFields = $this->customFieldsRepository->findAll();
$dateTypes = Block\Date::getDateTypes();
$data = [ $data = [
'form' => $form, 'form' => $form,
'form_exports' => [ 'form_exports' => [
@ -56,25 +51,24 @@ class FormEditor {
'pages' => Pages::getAll(), 'pages' => Pages::getAll(),
'segments' => Segment::getSegmentsWithSubscriberCount(), 'segments' => Segment::getSegmentsWithSubscriberCount(),
'styles' => FormRenderer::getStyles($form), 'styles' => FormRenderer::getStyles($form),
'date_types' => Block\Date::getDateTypes(), 'date_types' => array_map(function ($label, $value) {
'date_formats' => Block\Date::getDateFormats(),
'month_names' => Block\Date::getMonthNames(),
'sub_menu' => 'mailpoet-forms',
];
if ($this->featuresController->isSupported(FeaturesController::NEW_FORM_EDITOR)) {
$data['form']['styles'] = FormRenderer::getStyles($form);
$customFields = $this->customFieldsRepository->findAll();
$data['custom_fields'] = $this->customFieldsResponseBuilder->buildBatch($customFields);
$data['date_types'] = array_map(function ($label, $value) {
return [ return [
'label' => $label, 'label' => $label,
'value' => $value, 'value' => $value,
]; ];
}, $data['date_types'], array_keys($data['date_types'])); }, $dateTypes, array_keys($dateTypes)),
$this->pageRenderer->displayPage('form/editor.html', $data); 'date_formats' => Block\Date::getDateFormats(),
} else { 'month_names' => Block\Date::getMonthNames(),
'sub_menu' => 'mailpoet-forms',
'custom_fields' => $this->customFieldsResponseBuilder->buildBatch($customFields),
];
if (isset($_GET['legacy']) && (int)$_GET['legacy']) {
$data['date_types'] = $dateTypes;
$this->pageRenderer->displayPage('form/editor_legacy.html', $data); $this->pageRenderer->displayPage('form/editor_legacy.html', $data);
} else {
$this->pageRenderer->displayPage('form/editor.html', $data);
} }
} }
} }

View File

@ -22,7 +22,6 @@ use MailPoet\AdminPages\Pages\Update;
use MailPoet\AdminPages\Pages\WelcomeWizard; use MailPoet\AdminPages\Pages\WelcomeWizard;
use MailPoet\AdminPages\Pages\WooCommerceListImport; use MailPoet\AdminPages\Pages\WooCommerceListImport;
use MailPoet\DI\ContainerWrapper; use MailPoet\DI\ContainerWrapper;
use MailPoet\Features\FeaturesController;
use MailPoet\Util\License\License; use MailPoet\Util\License\License;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
@ -44,20 +43,15 @@ class Menu {
/** @var ContainerWrapper */ /** @var ContainerWrapper */
private $container; private $container;
/** @var FeaturesController */
private $featuresController;
public function __construct( public function __construct(
AccessControl $accessControl, AccessControl $accessControl,
WPFunctions $wp, WPFunctions $wp,
ServicesChecker $servicesChecker, ServicesChecker $servicesChecker,
FeaturesController $featuresController,
ContainerWrapper $container ContainerWrapper $container
) { ) {
$this->accessControl = $accessControl; $this->accessControl = $accessControl;
$this->wp = $wp; $this->wp = $wp;
$this->servicesChecker = $servicesChecker; $this->servicesChecker = $servicesChecker;
$this->featuresController = $featuresController;
$this->container = $container; $this->container = $container;
} }
@ -191,13 +185,12 @@ class Menu {
); );
// add body class for form editor page // add body class for form editor page
if ($this->featuresController->isSupported(FeaturesController::NEW_FORM_EDITOR)) { $this->wp->addAction('load-' . $formEditorPage, function() {
$this->wp->addAction('load-' . $formEditorPage, function() { $this->wp->addAction('admin_body_class', function ($classes) {
$this->wp->addAction('admin_body_class', function ($classes) { return ltrim($classes . ' block-editor-page');
return ltrim($classes . ' block-editor-page');
});
}); });
} });
// Subscribers page // Subscribers page
$subscribersPage = $this->wp->addSubmenuPage( $subscribersPage = $this->wp->addSubmenuPage(

View File

@ -355,7 +355,7 @@ class Populator {
private function createDefaultForm($defaultSegment) { private function createDefaultForm($defaultSegment) {
if (Form::count() === 0) { if (Form::count() === 0) {
$factory = new DefaultForm(new Styles($this->flagsController)); $factory = new DefaultForm(new Styles());
if (!$defaultSegment) { if (!$defaultSegment) {
$defaultSegment = Segment::where('type', 'default')->orderByAsc('id')->limit(1)->findOne(); $defaultSegment = Segment::where('type', 'default')->orderByAsc('id')->limit(1)->findOne();
} }

View File

@ -9,13 +9,11 @@ class FeaturesController {
// Define features below in the following form: // Define features below in the following form:
// const FEATURE_NAME_OF_FEATURE = 'name-of-feature'; // const FEATURE_NAME_OF_FEATURE = 'name-of-feature';
const NEW_DEFAULT_LIST_NAME = 'new-default-list-name'; const NEW_DEFAULT_LIST_NAME = 'new-default-list-name';
const NEW_FORM_EDITOR = 'new-form-editor';
// Define feature defaults in the array below in the following form: // Define feature defaults in the array below in the following form:
// self::FEATURE_NAME_OF_FEATURE => true, // self::FEATURE_NAME_OF_FEATURE => true,
private $defaults = [ private $defaults = [
self::NEW_DEFAULT_LIST_NAME => false, self::NEW_DEFAULT_LIST_NAME => false,
self::NEW_FORM_EDITOR => false,
]; ];
/** @var array */ /** @var array */

View File

@ -2,8 +2,6 @@
namespace MailPoet\Form\Util; namespace MailPoet\Form\Util;
use MailPoet\DI\ContainerWrapper;
use MailPoet\Features\FeaturesController;
use MailPoetVendor\Sabberworm\CSS\Parser as CSSParser; use MailPoetVendor\Sabberworm\CSS\Parser as CSSParser;
class Styles { class Styles {
@ -28,7 +26,7 @@ class Styles {
.mailpoet_list_label, .mailpoet_list_label,
.mailpoet_date_label { .mailpoet_date_label {
display:block; display:block;
[LABELS_FONT_WEIGHT_RULE] font-weight: normal;
} }
/* inputs */ /* inputs */
@ -44,7 +42,7 @@ class Styles {
.mailpoet_text, .mailpoet_text,
.mailpoet_textarea { .mailpoet_textarea {
[TEXT_INPUTS_WIDTH_RULE] width: 100%;
} }
.mailpoet_checkbox { .mailpoet_checkbox {
@ -81,32 +79,8 @@ class Styles {
} }
EOL; EOL;
/** @var FeaturesController */
private $featuresController;
/**
* @param FeaturesController $featuresController
*/
public function __construct(
FeaturesController $featuresController = null
) {
if ($featuresController === null) {
$featuresController = ContainerWrapper::getInstance()->get(FeaturesController::class);
}
$this->featuresController = $featuresController;
}
public function getDefaultStyles() { public function getDefaultStyles() {
if ($this->featuresController->isSupported(FeaturesController::NEW_FORM_EDITOR)) { return $this->defaultStyles;
$textInputWidth = 'width: 100%;';
$labelFontWeight = 'font-weight: normal;';
} else {
$textInputWidth = 'width: 200px;';
$labelFontWeight = 'font-weight: bold;';
}
$styles = str_replace('[TEXT_INPUTS_WIDTH_RULE]', $textInputWidth, $this->defaultStyles);
$styles = str_replace('[LABELS_FONT_WEIGHT_RULE]', $labelFontWeight, $styles);
return $styles;
} }
public function render($stylesheet, $prefix = '') { public function render($stylesheet, $prefix = '') {

View File

@ -16,8 +16,6 @@ class FormEditorAddNamesCest {
$formName = 'My fancy form'; $formName = 'My fancy form';
$form = new Form(); $form = new Form();
$form->withName($formName)->withSegments([$segment])->create(); $form->withName($formName)->withSegments([$segment])->create();
$features = new Features();
$features->withFeatureEnabled(FeaturesController::NEW_FORM_EDITOR);
$i->wantTo('Add first and last name to the editor'); $i->wantTo('Add first and last name to the editor');
$i->login(); $i->login();
$i->amOnMailPoetPage('Forms'); $i->amOnMailPoetPage('Forms');

View File

@ -16,8 +16,6 @@ class FormEditorCreateCustomFieldCest {
$formName = 'My fancy form'; $formName = 'My fancy form';
$form = new Form(); $form = new Form();
$form->withName($formName)->withSegments([$segment])->create(); $form->withName($formName)->withSegments([$segment])->create();
$features = new Features();
$features->withFeatureEnabled(FeaturesController::NEW_FORM_EDITOR);
$i->wantTo('Add first and last name to the editor'); $i->wantTo('Add first and last name to the editor');
$i->login(); $i->login();
$i->amOnMailPoetPage('Forms'); $i->amOnMailPoetPage('Forms');

View File

@ -9,8 +9,6 @@ use MailPoet\Test\DataFactories\Segment;
class FormEditorUpdateMandatoryFieldsCest { class FormEditorUpdateMandatoryFieldsCest {
public function updateEmailAndSubmit(\AcceptanceTester $i) { public function updateEmailAndSubmit(\AcceptanceTester $i) {
$features = new Features();
$features->withFeatureEnabled(FeaturesController::NEW_FORM_EDITOR);
$segmentFactory = new Segment(); $segmentFactory = new Segment();
$formName = 'Mandatory fields test'; $formName = 'Mandatory fields test';
$formFactory = new Form(); $formFactory = new Form();

View File

@ -11,8 +11,6 @@ class FormEditorUpdateNewFormCest {
$segmentFactory = new Segment(); $segmentFactory = new Segment();
$segmentName = 'Fancy List'; $segmentName = 'Fancy List';
$segmentFactory->withName($segmentName)->create(); $segmentFactory->withName($segmentName)->create();
$features = new Features();
$features->withFeatureEnabled(FeaturesController::NEW_FORM_EDITOR);
$i->wantTo('Create and update form'); $i->wantTo('Create and update form');
$i->login(); $i->login();
$i->amOnMailPoetPage('Forms'); $i->amOnMailPoetPage('Forms');

View File

@ -63,7 +63,7 @@ class FormsTest extends \MailPoetTest {
expect($response->data)->equals( expect($response->data)->equals(
Form::findOne($response->data['id'])->asArray() Form::findOne($response->data['id'])->asArray()
); );
expect($response->data['name'])->equals('New form'); expect($response->data['name'])->equals('');
} }
public function testItCanSaveAForm() { public function testItCanSaveAForm() {
@ -82,7 +82,7 @@ class FormsTest extends \MailPoetTest {
$response = $this->endpoint->create(); $response = $this->endpoint->create();
expect($response->status)->equals(APIResponse::STATUS_OK); expect($response->status)->equals(APIResponse::STATUS_OK);
expect($response->data)->equals( expect($response->data)->equals(
Form::where('name', 'New form')->findOne()->asArray() Form::where('id', $response->data['id'])->findOne()->asArray()
); );
$response = $this->endpoint->previewEditor($response->data); $response = $this->endpoint->previewEditor($response->data);

View File

@ -90,7 +90,6 @@ class MenuTest extends \MailPoetTest {
new AccessControl(), new AccessControl(),
$wp, $wp,
new ServicesChecker, new ServicesChecker,
new FeaturesController(new FeatureFlagsRepository(ContainerWrapper::getInstance()->get(EntityManager::class))),
ContainerWrapper::getInstance() ContainerWrapper::getInstance()
); );
} }

View File

@ -2,25 +2,12 @@
namespace MailPoet\Test\Form\Util; namespace MailPoet\Test\Form\Util;
use MailPoet\Features\FeaturesController;
use MailPoet\Form\Util\Styles; use MailPoet\Form\Util\Styles;
class StylesTest extends \MailPoetUnitTest { class StylesTest extends \MailPoetUnitTest {
/** @var FeaturesController&\PHPUnit_Framework_MockObject_MockObject */
private $featuresController;
public function _before() {
parent::_before();
$this->featuresController = $this->createMock(FeaturesController::class);
$this->featuresController
->expects($this->any())
->method('isSupported')
->willReturn(false);
}
public function testItSetsDefaultCSSStyles() { public function testItSetsDefaultCSSStyles() {
$styles = new Styles($this->featuresController); $styles = new Styles();
expect($styles->getDefaultStyles())->notEmpty(); expect($styles->getDefaultStyles())->notEmpty();
} }
@ -29,7 +16,7 @@ class StylesTest extends \MailPoetUnitTest {
/* some comment */ /* some comment */
input[name=first_name] , input.some_class, .some_class { color: red ; background: blue; } .another_style { fonT-siZe: 20px } input[name=first_name] , input.some_class, .some_class { color: red ; background: blue; } .another_style { fonT-siZe: 20px }
'; ';
$styleProcesser = new Styles($this->featuresController); $styleProcesser = new Styles();
$extractedAndPrefixedStyles = $styleProcesser->render($stylesheet, $prefix = 'mailpoet'); $extractedAndPrefixedStyles = $styleProcesser->render($stylesheet, $prefix = 'mailpoet');
// 1. comments should be stripped // 1. comments should be stripped
// 2. each selector should be refixed // 2. each selector should be refixed