Skip to content

Commit

Permalink
Merge branch '4.x' into feature/change-css-class-of-email-buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzmany committed Feb 10, 2022
2 parents 7cc5cc7 + 1ef4462 commit 8eb375c
Show file tree
Hide file tree
Showing 107 changed files with 6,942 additions and 1,792 deletions.
1 change: 1 addition & 0 deletions .gitmodules
@@ -0,0 +1 @@

6 changes: 3 additions & 3 deletions app/bundles/ApiBundle/Controller/CommonApiController.php
Expand Up @@ -975,9 +975,9 @@ protected function prepareEntityResultsToArray($results, $callback = null)
/**
* Convert posted parameters into what the form needs in order to successfully bind.
*
* @param $parameters
* @param $entity
* @param $action
* @param mixed[] $parameters
* @param object $entity
* @param string $action
*
* @return mixed
*/
Expand Down
43 changes: 29 additions & 14 deletions app/bundles/CoreBundle/Assets/js/1a.content.js
Expand Up @@ -1043,12 +1043,15 @@ Mautic.destroyChosen = function(el) {

/**
* Activate a typeahead lookup
*
* @param field
* @param target
* @param options
*/
Mautic.activateFieldTypeahead = function (field, target, options, action) {
var fieldId = '#' + field;
var fieldEl = mQuery('#' + field);

if (fieldEl.length && fieldEl.parent('.twitter-typeahead').length) {
return; // If the parent exist then the typeahead was already initialized. Abort.
}

if (options && typeof options === 'String') {
var keys = values = [];

Expand All @@ -1060,7 +1063,7 @@ Mautic.activateFieldTypeahead = function (field, target, options, action) {
values = options[0].split('|');
}

var fieldTypeahead = Mautic.activateTypeahead('#' + field, {
var fieldTypeahead = Mautic.activateTypeahead(fieldId, {
dataOptions: values,
dataOptionKeys: keys,
minLength: 0
Expand All @@ -1076,14 +1079,18 @@ Mautic.activateFieldTypeahead = function (field, target, options, action) {
typeAheadOptions.limit = options.limit;
}

var fieldTypeahead = Mautic.activateTypeahead('#' + field, typeAheadOptions);
if (('undefined' !== typeof options) && ('undefined' !== typeof options.noRrecordMessage)) {
typeAheadOptions.noRrecordMessage = options.noRrecordMessage;
}

var fieldTypeahead = Mautic.activateTypeahead(fieldId, typeAheadOptions);
}

var callback = function (event, datum) {
if (mQuery("#" + field).length && datum["value"]) {
mQuery("#" + field).val(datum["value"]);
if (fieldEl.length && datum["value"]) {
fieldEl.val(datum["value"]);

var lookupCallback = mQuery('#' + field).data("lookup-callback");
var lookupCallback = mQuery(fieldId).data('lookup-callback');
if (lookupCallback && typeof Mautic[lookupCallback] == 'function') {
Mautic[lookupCallback](field, datum);
}
Expand Down Expand Up @@ -1667,7 +1674,19 @@ Mautic.activateTypeahead = function (el, options) {
}
}

var noRrecordMessage = (options.noRrecordMessage) ? options.noRrecordMessage : mQuery(el).data('no-record-message');
var theName = el.replace(/[^a-z0-9\s]/gi, '').replace(/[-\s]/g, '_');
var dataset = {
name: theName,
displayKey: options.displayKey,
source: (typeof theBloodhound != 'undefined') ? theBloodhound.ttAdapter() : substringMatcher(lookupOptions, lookupKeys)
};

if (noRrecordMessage) {
dataset.templates = {
empty: "<p>" + noRrecordMessage + "<p>"
}
}

var theTypeahead = mQuery(el).typeahead(
{
Expand All @@ -1676,11 +1695,7 @@ Mautic.activateTypeahead = function (el, options) {
minLength: options.minLength,
multiple: options.multiple
},
{
name: theName,
displayKey: options.displayKey,
source: (typeof theBloodhound != 'undefined') ? theBloodhound.ttAdapter() : substringMatcher(lookupOptions, lookupKeys)
}
dataset
).on('keypress', function (event) {
if ((event.keyCode || event.which) == 13) {
mQuery(el).typeahead('close');
Expand Down
8 changes: 5 additions & 3 deletions app/bundles/CoreBundle/Controller/FormThemeTrait.php
Expand Up @@ -13,18 +13,20 @@

use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormInterface;

trait FormThemeTrait
{
/**
* Sets a specific theme for the form.
*
* @param string $template
* @param mixed $themes
* @param FormInterface<FormInterface> $form
* @param string $template
* @param mixed $themes
*
* @return \Symfony\Component\Form\FormView
*/
protected function setFormTheme(Form $form, $template, $themes = null)
protected function setFormTheme(FormInterface $form, $template, $themes = null)
{
$formView = $form->createView();

Expand Down
13 changes: 10 additions & 3 deletions app/bundles/CoreBundle/Form/Type/DynamicContentTrait.php
Expand Up @@ -11,7 +11,7 @@

namespace Mautic\CoreBundle\Form\Type;

use Mautic\CoreBundle\Entity\DynamicContentEntityTrait;
use Mautic\EmailBundle\Entity\Email;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
Expand Down Expand Up @@ -39,14 +39,21 @@ protected function addDynamicContentField(FormBuilderInterface $builder)
FormEvents::PRE_SUBMIT,
function (FormEvent $event) {
$data = $event->getData();
/** @var DynamicContentEntityTrait $entity */
/** @var Email $entity */
$entity = $event->getForm()->getData();

if (empty($data['dynamicContent'])) {
$data['dynamicContent'] = $entity->getDefaultDynamicContent();
unset($data['dynamicContent'][0]['filters']['filter']);
$event->setData($data);
}

foreach ($data['dynamicContent'] as $key => $dc) {
if (empty($dc['filters'])) {
$data['dynamicContent'][$key]['filters'] = $entity->getDefaultDynamicContent()[0]['filters'];
}
}

$event->setData($data);
}
);
}
Expand Down
21 changes: 2 additions & 19 deletions app/bundles/CoreBundle/Form/Type/DynamicListType.php
Expand Up @@ -23,21 +23,16 @@
use Symfony\Component\Validator\Constraints\Count;
use Symfony\Component\Validator\Constraints\NotBlank;

/**
* Class DynamicListType.
*/
class DynamicListType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addEventListener(
FormEvents::PRE_SUBMIT,
function (FormEvent $event) {
//reorder list in case keys were dynamically removed
$data = $event->getData();

// Reorder list in case keys were dynamically removed.
if (is_array($data)) {
$data = array_values($data);
$event->setData($data);
Expand All @@ -46,17 +41,11 @@ function (FormEvent $event) {
);
}

/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['isSortable'] = (!empty($options['sortable']));
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
Expand Down Expand Up @@ -122,17 +111,11 @@ public function configureOptions(OptionsResolver $resolver)
);
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'dynamiclist';
}

/**
* @return string
*/
public function getParent()
{
return CollectionType::class;
Expand Down
Expand Up @@ -11,6 +11,7 @@
namespace Mautic\CoreBundle\Form\Validator\Constraints;

use Mautic\LeadBundle\Model\ListModel;
use Mautic\LeadBundle\Segment\OperatorOptions;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
Expand Down Expand Up @@ -79,11 +80,16 @@ private function getSegmentIdFromRequest()
*/
private function reduceToSegmentIds(array $filters)
{
$segmentFilters = array_filter($filters, function ($v) {
return 'leadlist' == $v['type'];
$segmentFilters = array_filter($filters, function (array $filter) {
return 'leadlist' === $filter['type']
&& in_array($filter['operator'], [OperatorOptions::IN, OperatorOptions::NOT_IN]);
});

$segentIdsInFilter = array_column($segmentFilters, 'filter');
$segentIdsInFilter = array_map(function (array $filter) {
$bcValue = $filter['filter'] ?? [];

return $filter['properties']['filter'] ?? $bcValue;
}, $segmentFilters);

return $this->flatten($segentIdsInFilter);
}
Expand Down

0 comments on commit 8eb375c

Please sign in to comment.