Default to first active form if widget form id not present
[MAILPOET-3847]
This commit is contained in:
@@ -27,6 +27,22 @@ 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();
|
||||||
|
|
||||||
|
@@ -197,8 +197,16 @@ class Widget extends \WP_Widget {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// get form
|
// get form
|
||||||
if (empty($instance['form'])) return '';
|
if (!empty($instance['form'])) {
|
||||||
$form = $this->formsRepository->findOneById($instance['form']);
|
$form = $this->formsRepository->findOneById($instance['form']);
|
||||||
|
} else {
|
||||||
|
// Backwards compatibility for MAILPOET-3847
|
||||||
|
// Get first active form
|
||||||
|
$forms = $this->formsRepository->findAllActive();
|
||||||
|
if (empty($forms)) return '';
|
||||||
|
$form = $forms[0];
|
||||||
|
}
|
||||||
|
|
||||||
if (!$form) return '';
|
if (!$form) return '';
|
||||||
if ($form->getDeletedAt()) return '';
|
if ($form->getDeletedAt()) return '';
|
||||||
if ($form->getStatus() !== FormEntity::STATUS_ENABLED) return '';
|
if ($form->getStatus() !== FormEntity::STATUS_ENABLED) return '';
|
||||||
|
Reference in New Issue
Block a user