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

View File

@ -5,11 +5,9 @@ namespace MailPoet\AdminPages\Pages;
use MailPoet\AdminPages\PageRenderer;
use MailPoet\API\JSON\ResponseBuilders\CustomFieldsResponseBuilder;
use MailPoet\CustomFields\CustomFieldsRepository;
use MailPoet\Features\FeaturesController;
use MailPoet\Form\Block;
use MailPoet\Form\Renderer as FormRenderer;
use MailPoet\Form\Util\Export;
use MailPoet\Models\CustomField;
use MailPoet\Models\Form;
use MailPoet\Models\Segment;
use MailPoet\Settings\Pages;
@ -18,9 +16,6 @@ class FormEditor {
/** @var PageRenderer */
private $pageRenderer;
/** @var FeaturesController */
private $featuresController;
/** @var CustomFieldsRepository */
private $customFieldsRepository;
@ -29,12 +24,10 @@ class FormEditor {
public function __construct(
PageRenderer $pageRenderer,
FeaturesController $featuresController,
CustomFieldsRepository $customFieldsRepository,
CustomFieldsResponseBuilder $customFieldsResponseBuilder
) {
$this->pageRenderer = $pageRenderer;
$this->featuresController = $featuresController;
$this->customFieldsRepository = $customFieldsRepository;
$this->customFieldsResponseBuilder = $customFieldsResponseBuilder;
}
@ -45,7 +38,9 @@ class FormEditor {
if ($form instanceof Form) {
$form = $form->asArray();
}
$form['styles'] = FormRenderer::getStyles($form);
$customFields = $this->customFieldsRepository->findAll();
$dateTypes = Block\Date::getDateTypes();
$data = [
'form' => $form,
'form_exports' => [
@ -56,25 +51,24 @@ class FormEditor {
'pages' => Pages::getAll(),
'segments' => Segment::getSegmentsWithSubscriberCount(),
'styles' => FormRenderer::getStyles($form),
'date_types' => Block\Date::getDateTypes(),
'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) {
'date_types' => array_map(function ($label, $value) {
return [
'label' => $label,
'value' => $value,
];
}, $data['date_types'], array_keys($data['date_types']));
$this->pageRenderer->displayPage('form/editor.html', $data);
} else {
}, $dateTypes, array_keys($dateTypes)),
'date_formats' => Block\Date::getDateFormats(),
'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);
} 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\WooCommerceListImport;
use MailPoet\DI\ContainerWrapper;
use MailPoet\Features\FeaturesController;
use MailPoet\Util\License\License;
use MailPoet\WP\Functions as WPFunctions;
@ -44,20 +43,15 @@ class Menu {
/** @var ContainerWrapper */
private $container;
/** @var FeaturesController */
private $featuresController;
public function __construct(
AccessControl $accessControl,
WPFunctions $wp,
ServicesChecker $servicesChecker,
FeaturesController $featuresController,
ContainerWrapper $container
) {
$this->accessControl = $accessControl;
$this->wp = $wp;
$this->servicesChecker = $servicesChecker;
$this->featuresController = $featuresController;
$this->container = $container;
}
@ -191,13 +185,12 @@ class Menu {
);
// add body class for form editor page
if ($this->featuresController->isSupported(FeaturesController::NEW_FORM_EDITOR)) {
$this->wp->addAction('load-' . $formEditorPage, function() {
$this->wp->addAction('admin_body_class', function ($classes) {
return ltrim($classes . ' block-editor-page');
});
});
}
// Subscribers page
$subscribersPage = $this->wp->addSubmenuPage(

View File

@ -355,7 +355,7 @@ class Populator {
private function createDefaultForm($defaultSegment) {
if (Form::count() === 0) {
$factory = new DefaultForm(new Styles($this->flagsController));
$factory = new DefaultForm(new Styles());
if (!$defaultSegment) {
$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:
// const FEATURE_NAME_OF_FEATURE = 'name-of-feature';
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:
// self::FEATURE_NAME_OF_FEATURE => true,
private $defaults = [
self::NEW_DEFAULT_LIST_NAME => false,
self::NEW_FORM_EDITOR => false,
];
/** @var array */

View File

@ -2,8 +2,6 @@
namespace MailPoet\Form\Util;
use MailPoet\DI\ContainerWrapper;
use MailPoet\Features\FeaturesController;
use MailPoetVendor\Sabberworm\CSS\Parser as CSSParser;
class Styles {
@ -28,7 +26,7 @@ class Styles {
.mailpoet_list_label,
.mailpoet_date_label {
display:block;
[LABELS_FONT_WEIGHT_RULE]
font-weight: normal;
}
/* inputs */
@ -44,7 +42,7 @@ class Styles {
.mailpoet_text,
.mailpoet_textarea {
[TEXT_INPUTS_WIDTH_RULE]
width: 100%;
}
.mailpoet_checkbox {
@ -81,32 +79,8 @@ class Styles {
}
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() {
if ($this->featuresController->isSupported(FeaturesController::NEW_FORM_EDITOR)) {
$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;
return $this->defaultStyles;
}
public function render($stylesheet, $prefix = '') {

View File

@ -16,8 +16,6 @@ class FormEditorAddNamesCest {
$formName = 'My fancy form';
$form = new Form();
$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->login();
$i->amOnMailPoetPage('Forms');

View File

@ -16,8 +16,6 @@ class FormEditorCreateCustomFieldCest {
$formName = 'My fancy form';
$form = new Form();
$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->login();
$i->amOnMailPoetPage('Forms');

View File

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

View File

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

View File

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

View File

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

View File

@ -2,25 +2,12 @@
namespace MailPoet\Test\Form\Util;
use MailPoet\Features\FeaturesController;
use MailPoet\Form\Util\Styles;
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() {
$styles = new Styles($this->featuresController);
$styles = new Styles();
expect($styles->getDefaultStyles())->notEmpty();
}
@ -29,7 +16,7 @@ class StylesTest extends \MailPoetUnitTest {
/* some comment */
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');
// 1. comments should be stripped
// 2. each selector should be refixed