Skip to content

Commit

Permalink
Merge pull request #8706 from mohit-rocks/allow-html-custom-field
Browse files Browse the repository at this point in the history
  • Loading branch information
npracht committed May 14, 2021
2 parents 8e6d71d + bdba6a5 commit 367d2bd
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Mautic\ApiBundle\Controller\CommonApiController;
use Mautic\LeadBundle\Controller\LeadAccessTrait;
use Mautic\LeadBundle\Entity\Company;
use Mautic\LeadBundle\Entity\Lead;
use Mautic\LeadBundle\Helper\IdentifyCompanyHelper;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
Expand All @@ -33,7 +34,7 @@ public function initialize(FilterControllerEvent $event)
$this->entityNameOne = 'company';
$this->entityNameMulti = 'companies';
$this->serializerGroups[] = 'companyDetails';

$this->setCleaningRules('company');
parent::initialize($event);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,17 @@ function ($value) {

$this->model->setFieldValues($entity, $parameters, $overwriteWithBlank);
}

/**
* @param string $object
*/
protected function setCleaningRules($object = 'lead')
{
$fields = $this->getModel('lead.field')->getFieldListWithProperties($object);
foreach ($fields as $field) {
if (!empty($field['properties']['allowHtml'])) {
$this->dataInputMasks[$field['alias']] = 'html';
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function initialize(FilterControllerEvent $event)
$this->entityNameOne = 'contact';
$this->entityNameMulti = 'contacts';
$this->serializerGroups = ['leadDetails', 'frequencyRulesList', 'doNotContactList', 'userList', 'stageList', 'publishDetails', 'ipAddress', 'tagList', 'utmtagsList'];

$this->setCleaningRules();
parent::initialize($event);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TimeType;
use Symfony\Component\Form\FormBuilderInterface;
Expand Down Expand Up @@ -274,6 +275,12 @@ function (FormEvent $event) use ($alias, $type) {
case MultiselectType::class:
$constraints[] = new Length(['max' => 65535]);
break;

case TextareaType::class:
if (!empty($properties['allowHtml'])) {
$cleaningRules[$field['alias']] = 'html';
}
break;
}

$builder->add(
Expand Down
13 changes: 13 additions & 0 deletions app/bundles/LeadBundle/Form/Type/FieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ public function buildForm(FormBuilderInterface $builder, array $options)
]
);

$builder->add(
'properties_textarea_template',
YesNoButtonGroupType::class,
[
'label' => 'mautic.lead.field.form.properties.allowhtml',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
'required' => false,
'mapped' => false,
'data' => isset($options['data']->getProperties()['allowHtml']) ? $options['data']->getProperties()['allowHtml'] : false,
]
);

$listChoices = [
'country' => FormFieldHelper::getCountryChoices(),
'region' => FormFieldHelper::getRegionChoices(),
Expand Down
4 changes: 3 additions & 1 deletion app/bundles/LeadBundle/Helper/FormFieldHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class FormFieldHelper extends AbstractFormFieldHelper
'properties' => [],
],
'textarea' => [
'properties' => [],
'properties' => [
'allowHtml' => [],
],
],
'multiselect' => [
'properties' => [
Expand Down
1 change: 1 addition & 0 deletions app/bundles/LeadBundle/Translations/en_US/messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ mautic.lead.field.form.properties.lookup="Lookup values"
mautic.lead.field.form.properties.numberprecision="Precision"
mautic.lead.field.form.properties.numberrounding="Rounding mode"
mautic.lead.field.form.properties.select="Options"
mautic.lead.field.form.properties.allowhtml="Allow HTML"
mautic.lead.lead.update.action.help="Update the contact fields with values from this event."
mautic.lead.company.update.action.help="Update the company fields with values from this event."
mautic.lead.field.group="Group"
Expand Down
11 changes: 11 additions & 0 deletions app/bundles/LeadBundle/Views/Field/form.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
$view['slots']->set('headerTitle', $header);

// Render the templates so they don't get rendered automatically
$textareaTemplate = $view['form']->row($form['properties_textarea_template']);
$selectTemplate = $view['form']->row($form['properties_select_template']);
$lookupTemplate = $view['form']->row($form['properties_lookup_template']);
$defaultTextTemplate = $view['form']->widget($form['default_template_text']);
Expand Down Expand Up @@ -100,6 +101,13 @@
'selectTemplate' => $lookupTemplate,
'isLookup' => 'lookup',
]);
break;
case 'textarea':
echo $view->render('MauticLeadBundle:Field:properties_textarea.html.php', [
'form' => $form['properties'],
'textareaTemplate' => $textareaTemplate,
]);
break;
endswitch;
?>
</div>
Expand Down Expand Up @@ -194,6 +202,9 @@
'selectTemplate' => $lookupTemplate,
'isLookup' => 'lookup',
]);
echo $view->render('MauticLeadBundle:Field:properties_textarea.html.php', [
'textareaTemplate' => $textareaTemplate,
]);
?>
</div>
<?php endif; ?>
19 changes: 19 additions & 0 deletions app/bundles/LeadBundle/Views/Field/properties_textarea.html.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* @copyright 2019 Mautic Contributors. All rights reserved
* @author Mautic
*
* @link http://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

$type = 'textarea';
$value = (isset($value)) ? $value : '';
$html = str_replace(['properties_'.$type.'_template', 'leadfield_properties', 'leadfield[properties]'], ['properties', 'leadfield_properties_template', 'leadfield[properties][allowHtml]'], $textareaTemplate);
?>

<div class="<?php echo $type; ?>">
<?php echo $html; ?>
</div>

0 comments on commit 367d2bd

Please sign in to comment.