Select first form in list

[MAILPOET-3847]
This commit is contained in:
Brezo Cordero
2021-10-14 13:09:34 -05:00
committed by Veljko V
parent 51e03911b8
commit 3812d6c15e
2 changed files with 4 additions and 18 deletions

View File

@@ -27,22 +27,6 @@ class FormsRepository extends Repository {
->getResult(); ->getResult();
} }
/**
* @return FormEntity[]
*/
public function findAllActive(): array {
return $this->entityManager
->createQueryBuilder()
->select('f')
->from(FormEntity::class, 'f')
->where('f.status = (:enabled)')
->andWhere('f.deletedAt IS NULL')
->setParameter('enabled', FormEntity::STATUS_ENABLED)
->orderBy('f.name', 'asc')
->getQuery()
->getResult();
}
public function getNamesOfFormsForSegments(): array { public function getNamesOfFormsForSegments(): array {
$allNonDeletedForms = $this->findAllNotDeleted(); $allNonDeletedForms = $this->findAllNotDeleted();

View File

@@ -137,6 +137,8 @@ class Widget extends \WP_Widget {
<p> <p>
<select class="widefat" id="<?php echo $this->get_field_id('form') ?>" name="<?php echo $this->get_field_name('form'); ?>"> <select class="widefat" id="<?php echo $this->get_field_id('form') ?>" name="<?php echo $this->get_field_name('form'); ?>">
<?php <?php
// Select the first one from the list if none selected
if ($selectedForm === 0 && !empty($forms)) $selectedForm = $forms[0]->getId();
foreach ($forms as $form) { foreach ($forms as $form) {
$isSelected = ($selectedForm === $form->getId()) ? 'selected="selected"' : ''; $isSelected = ($selectedForm === $form->getId()) ? 'selected="selected"' : '';
$formName = $form->getName() ? $this->wp->escHtml($form->getName()) : "({$this->wp->_x('no name', 'fallback for forms without a name in a form list')})" $formName = $form->getName() ? $this->wp->escHtml($form->getName()) : "({$this->wp->_x('no name', 'fallback for forms without a name in a form list')})"
@@ -201,8 +203,8 @@ class Widget extends \WP_Widget {
$form = $this->formsRepository->findOneById($instance['form']); $form = $this->formsRepository->findOneById($instance['form']);
} else { } else {
// Backwards compatibility for MAILPOET-3847 // Backwards compatibility for MAILPOET-3847
// Get first active form // Get first non deleted form
$forms = $this->formsRepository->findAllActive(); $forms = $this->formsRepository->findBy(['deletedAt' => null], ['name' => 'asc']);
if (empty($forms)) return ''; if (empty($forms)) return '';
$form = $forms[0]; $form = $forms[0];
} }