Skip to content

Commit

Permalink
Segment membership as a new filter for dynamic web content (#13526)
Browse files Browse the repository at this point in the history
* MAUT-3602 / Operator list

* Merge pull request #1037 from mautic-inc/MAUT-3809-2

MAUT 3809 - Use segment membership as a filter for dynamic content for web

* Merge pull request #1339 from acquia/MAUT-5498

MAUT-5498 EAB - Segment Membership Filter in Dynamic Content Breaks Landing Pages

* Changes needed after rebase to M5

* CS fixes

* Allow the segment membership filter to be used by DWC

* Test fixes

* Fixing DWC select type filters

---------

Co-authored-by: Lukas Sykora <lukassykora@seznam.cz>
Co-authored-by: Lukáš Drahý <lukas@drahy.net>
Co-authored-by: Rohit Pavaskar <66303837+rohitp19@users.noreply.github.com>
Co-authored-by: Ruth Cheesley <ruth@ruthcheesley.co.uk>
  • Loading branch information
5 people committed Apr 26, 2024
1 parent 5a7cd96 commit ba7529c
Show file tree
Hide file tree
Showing 26 changed files with 716 additions and 277 deletions.
51 changes: 0 additions & 51 deletions app/bundles/CoreBundle/Form/Type/DynamicContentTrait.php

This file was deleted.

This file was deleted.

8 changes: 4 additions & 4 deletions app/bundles/DynamicContentBundle/Assets/js/dynamicContent.js
Expand Up @@ -201,13 +201,13 @@ Mautic.addDwcFilter = function (elId, elObj) {

//activate fields
if (isSpecial) {
if (fieldType == 'select' || fieldType == 'multiselect' || fieldType == 'boolean') {
if (fieldType == 'select' || fieldType == 'multiselect' || fieldType == 'boolean' || fieldType == 'leadlist') {
// Generate the options
var fieldOptions = filterOption.data("field-list");
mQuery.each(fieldOptions, function(index, val) {
if (mQuery.isPlainObject(val)) {
mQuery.each(fieldOptions, function(val, index) {
if (mQuery.isPlainObject(index)) {
var optGroup = index;
mQuery.each(val, function(index, value) {
mQuery.each(optGroup, function(value, index) {
mQuery('<option class="' + optGroup + '">').val(index).text(value).appendTo(filterEl);
});
mQuery('.' + index).wrapAll("<optgroup label='"+index+"' />");
Expand Down
1 change: 1 addition & 0 deletions app/bundles/DynamicContentBundle/Config/config.php
Expand Up @@ -49,6 +49,7 @@
'class' => Mautic\DynamicContentBundle\Form\Type\DwcEntryFiltersType::class,
'arguments' => [
'translator',
'mautic.lead.model.list',
],
'methodCalls' => [
'setConnection' => [
Expand Down
Expand Up @@ -173,9 +173,10 @@ public function decodeTokens(PageDisplayEvent $event): void
$dom->loadHTML(mb_encode_numericentity($content, [0x80, 0x10FFFF, 0, 0xFFFFF], 'UTF-8'), LIBXML_NOERROR);
$xpath = new \DOMXPath($dom);

$divContent = $xpath->query('//*[@data-slot="dwc"]');
for ($i = 0; $i < $divContent->length; ++$i) {
$slot = $divContent->item($i);
$contentSlots = $xpath->query('//*[@data-slot="dwc"]');

for ($i = 0; $i < $contentSlots->length; ++$i) {
$slot = $contentSlots->item($i);
if (!$slotName = $slot->getAttribute('data-param-slot-name')) {
continue;
}
Expand Down
Expand Up @@ -3,6 +3,7 @@
namespace Mautic\DynamicContentBundle\Form\Type;

use Mautic\LeadBundle\Form\Type\FilterTrait;
use Mautic\LeadBundle\Model\ListModel;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
Expand All @@ -11,6 +12,7 @@
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\Exception\AccessException;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;

Expand All @@ -22,7 +24,8 @@ class DwcEntryFiltersType extends AbstractType
use FilterTrait;

public function __construct(
private TranslatorInterface $translator
private TranslatorInterface $translator,
private ListModel $listModel
) {
}

Expand Down Expand Up @@ -68,7 +71,7 @@ function (FormEvent $event) use ($formModifier): void {
}

/**
* @throws \Symfony\Component\OptionsResolver\Exception\AccessException
* @throws AccessException
*/
public function configureOptions(OptionsResolver $resolver): void
{
Expand All @@ -83,13 +86,16 @@ public function configureOptions(OptionsResolver $resolver): void
'deviceBrands',
'deviceOs',
'tags',
'lists',
]
);

$resolver->setDefaults(
[
'label' => false,
'error_bubbling' => false,
// @see \Mautic\LeadBundle\Controller\AjaxController::loadSegmentFilterFormAction()
'lists' => $this->listModel->getChoiceFields()['lead']['leadlist']['properties']['list'],
]
);
}
Expand Down
17 changes: 15 additions & 2 deletions app/bundles/DynamicContentBundle/Form/Type/DynamicContentType.php
Expand Up @@ -324,8 +324,21 @@ public function buildView(FormView $view, FormInterface $form, array $options):
private function filterFieldChoices(): void
{
unset($this->fieldChoices['company']);
$customFields = $this->leadModel->getRepository()->getCustomFieldList('lead');
$this->fieldChoices['lead'] = array_filter($this->fieldChoices['lead'], fn ($key): bool => in_array($key, array_merge(array_keys($customFields[0]), ['date_added', 'date_modified', 'device_brand', 'device_model', 'device_os', 'device_type', 'tags']), true), ARRAY_FILTER_USE_KEY);

$customFields = $this->leadModel->getRepository()->getCustomFieldList('lead');

$this->fieldChoices['lead'] = array_filter(
$this->fieldChoices['lead'],
fn ($key): bool => in_array(
$key,
array_merge(
array_keys($customFields[0]),
['date_added', 'date_modified', 'device_brand', 'device_model', 'device_os', 'device_type', 'tags', 'leadlist']
),
true
),
ARRAY_FILTER_USE_KEY
);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions app/bundles/DynamicContentBundle/Helper/DynamicContentHelper.php
Expand Up @@ -18,6 +18,16 @@ class DynamicContentHelper
{
use MatchFilterForLeadTrait;

/**
* @const DYNAMIC_CONTENT_REGEX
*/
public const DYNAMIC_CONTENT_REGEX = '/{(dynamiccontent)=(\w+)(?:\/}|}(?:([^{]*(?:{(?!\/\1})[^{]*)*){\/\1})?)/is';

/**
* @const DYNAMIC_WEB_CONTENT_REGEX
*/
public const DYNAMIC_WEB_CONTENT_REGEX = '/{dwc=(.*?)}/';

public function __construct(
protected DynamicContentModel $dynamicContentModel,
protected RealTimeExecutioner $realTimeExecutioner,
Expand Down
Expand Up @@ -175,10 +175,15 @@
name="dwc[filters][__name__][filter]"
id="dwc_filters___name___filter">
{% if form.vars[dataKey] is defined %}
{% for value, label in form.vars[dataKey] %}
{% if label is iterable %}
<optgroup label="{{ value }}">
{% for optionValue, optionLabel in label %}
{% set index = 0 %}
{% for label, value in form.vars[dataKey] %}
{% if value is iterable %}
<optgroup label="{{ label }}">
{% for optionLabel, optionValue in value %}
{% if (dataKey == 'regions') %}
{% set optionValue = index %}
{% set index = index + 1 %}
{% endif %}
<option value="{{ optionValue }}">{{ optionLabel }}</option>
{% endfor %}
</optgroup>
Expand Down
Expand Up @@ -14,7 +14,6 @@
use Mautic\LeadBundle\Entity\CompanyLeadRepository;
use Mautic\LeadBundle\Entity\Lead;
use Mautic\LeadBundle\Model\CompanyModel;
use Mautic\LeadBundle\Model\LeadModel;
use Mautic\LeadBundle\Tracker\ContactTracker;
use Mautic\PageBundle\Event\PageDisplayEvent;
use Mautic\PageBundle\Helper\TokenHelper as PageTokenHelper;
Expand Down Expand Up @@ -54,11 +53,6 @@ class DynamicContentSubscriberTest extends \PHPUnit\Framework\TestCase
*/
private MockObject $auditLogModel;

/**
* @var MockObject|LeadModel
*/
private MockObject $leadModel;

/**
* @var MockObject|DynamicContentHelper
*/
Expand Down Expand Up @@ -96,7 +90,7 @@ protected function setUp(): void
$this->formTokenHelper = $this->createMock(FormTokenHelper::class);
$this->focusTokenHelper = $this->createMock(FocusTokenHelper::class);
$this->auditLogModel = $this->createMock(AuditLogModel::class);
$this->leadModel = $this->createMock(LeadModel::class);
$this->contactTracker = $this->createMock(ContactTracker::class);
$this->dynamicContentHelper = $this->createMock(DynamicContentHelper::class);
$this->dynamicContentModel = $this->createMock(DynamicContentModel::class);
$this->security = $this->createMock(CorePermissions::class);
Expand Down

0 comments on commit ba7529c

Please sign in to comment.