Beispiel #1
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->translator = $factory->getTranslator();
     /** @var \Mautic\LeadBundle\Model\ListModel $listModel */
     $listModel = $factory->getModel('lead.list');
     $this->fieldChoices = $listModel->getChoiceFields();
     // Locales
     $this->timezoneChoices = FormFieldHelper::getTimezonesChoices();
     $this->countryChoices = FormFieldHelper::getCountryChoices();
     $this->regionChoices = FormFieldHelper::getRegionChoices();
     // Segments
     $lists = $listModel->getUserLists();
     foreach ($lists as $list) {
         $this->listChoices[$list['id']] = $list['name'];
     }
     // Emails
     /** @var \Mautic\EmailBundle\Model\EmailModel $emailModel */
     $emailModel = $factory->getModel('email');
     $viewOther = $factory->getSecurity()->isGranted('email:emails:viewother');
     $emails = $emailModel->getRepository()->getEmailList('', 0, 0, $viewOther, true);
     foreach ($emails as $email) {
         $this->emailChoices[$email['language']][$email['id']] = $email['name'];
     }
     ksort($this->emailChoices);
     // Tags
     $leadModel = $factory->getModel('lead');
     $tags = $leadModel->getTagList();
     foreach ($tags as $tag) {
         $this->tagChoices[$tag['value']] = $tag['label'];
     }
 }
 /**
  * DynamicContentFilterEntryType constructor.
  *
  * @param ListModel  $listModel
  * @param StageModel $stageModel
  */
 public function __construct(ListModel $listModel, StageModel $stageModel)
 {
     $this->fieldChoices = $listModel->getChoiceFields();
     $this->filterFieldChoices();
     $this->countryChoices = FormFieldHelper::getCountryChoices();
     $this->regionChoices = FormFieldHelper::getRegionChoices();
     $this->timezoneChoices = FormFieldHelper::getTimezonesChoices();
     $this->localeChoices = FormFieldHelper::getLocaleChoices();
     $stages = $stageModel->getRepository()->getSimpleList();
     foreach ($stages as $stage) {
         $this->stageChoices[$stage['value']] = $stage['label'];
     }
 }
Beispiel #3
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->translator = $factory->getTranslator();
     $this->defaultTheme = $factory->getParameter('theme');
     $this->em = $factory->getEntityManager();
     $this->request = $factory->getRequest();
     $this->countryChoices = FormFieldHelper::getCountryChoices();
     $this->regionChoices = FormFieldHelper::getRegionChoices();
     $this->timezoneChoices = FormFieldHelper::getTimezonesChoices();
     $this->localeChoices = FormFieldHelper::getLocaleChoices();
     $stages = $factory->getModel('stage')->getRepository()->getSimpleList();
     foreach ($stages as $stage) {
         $this->stageChoices[$stage['value']] = $stage['label'];
     }
 }
Beispiel #4
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->translator = $factory->getTranslator();
     /** @var \Mautic\LeadBundle\Model\ListModel $listModel */
     $listModel = $factory->getModel('lead.list');
     $this->fieldChoices = $listModel->getChoiceFields();
     $this->timezoneChoices = FormFieldHelper::getTimezonesChoices();
     $this->countryChoices = FormFieldHelper::getCountryChoices();
     $this->regionChoices = FormFieldHelper::getRegionChoices();
     $lists = $listModel->getUserLists();
     $this->listChoices = array();
     foreach ($lists as $list) {
         $this->listChoices[$list['id']] = $list['name'];
     }
     $leadModel = $factory->getModel('lead');
     $tags = $leadModel->getTagList();
     foreach ($tags as $tag) {
         $this->tagChoices[$tag['value']] = $tag['label'];
     }
 }
 private function getFormFields(FormBuilderInterface $builder, array $options, $object = 'lead')
 {
     $fieldValues = [];
     $isObject = false;
     if (!empty($options['data'])) {
         $isObject = is_object($options['data']);
         $fieldValues = $isObject ? $options['data']->getFields() : $options['data'];
     }
     $mapped = !$isObject;
     foreach ($options['fields'] as $field) {
         if ($field['isPublished'] === false || $field['object'] !== $object) {
             continue;
         }
         $attr = ['class' => 'form-control'];
         $properties = $field['properties'];
         $type = $field['type'];
         $required = $isObject ? $field['isRequired'] : false;
         $alias = $field['alias'];
         $group = $field['group'];
         if ($field['isUniqueIdentifer']) {
             $attr['data-unique-identifier'] = $field['alias'];
         }
         if ($isObject) {
             $value = isset($fieldValues[$group][$alias]['value']) ? $fieldValues[$group][$alias]['value'] : $field['defaultValue'];
         } else {
             $value = isset($fieldValues[$alias]) ? $fieldValues[$alias] : '';
         }
         $constraints = [];
         if ($required && empty($options['ignore_required_constraints'])) {
             $constraints[] = new NotBlank(['message' => 'mautic.lead.customfield.notblank']);
         }
         switch ($type) {
             case 'number':
                 if (empty($properties['precision'])) {
                     $properties['precision'] = null;
                 } else {
                     $properties['precision'] = (int) $properties['precision'];
                 }
                 if ('' === $value) {
                     // Prevent transform errors
                     $value = null;
                 }
                 $builder->add($alias, $type, ['required' => $required, 'label' => $field['label'], 'label_attr' => ['class' => 'control-label'], 'attr' => $attr, 'data' => null !== $value ? (double) $value : $value, 'mapped' => $mapped, 'constraints' => $constraints, 'precision' => $properties['precision'], 'rounding_mode' => isset($properties['roundmode']) ? (int) $properties['roundmode'] : 0]);
                 break;
             case 'date':
             case 'datetime':
             case 'time':
                 $attr['data-toggle'] = $type;
                 $opts = ['required' => $required, 'label' => $field['label'], 'label_attr' => ['class' => 'control-label'], 'widget' => 'single_text', 'attr' => $attr, 'mapped' => $mapped, 'input' => 'string', 'html5' => false, 'constraints' => $constraints];
                 if ($value) {
                     try {
                         $dtHelper = new DateTimeHelper($value, null, 'local');
                     } catch (\Exception $e) {
                         // Rather return empty value than break the page
                         $value = null;
                     }
                 }
                 if ($type == 'datetime') {
                     $opts['model_timezone'] = 'UTC';
                     $opts['view_timezone'] = date_default_timezone_get();
                     $opts['format'] = 'yyyy-MM-dd HH:mm';
                     $opts['with_seconds'] = false;
                     $opts['data'] = !empty($value) ? $dtHelper->toLocalString('Y-m-d H:i:s') : null;
                 } elseif ($type == 'date') {
                     $opts['data'] = !empty($value) ? $dtHelper->toLocalString('Y-m-d') : null;
                 } else {
                     $opts['data'] = !empty($value) ? $dtHelper->toLocalString('H:i:s') : null;
                 }
                 $builder->add($alias, $type, $opts);
                 break;
             case 'select':
             case 'multiselect':
             case 'boolean':
                 $typeProperties = ['required' => $required, 'label' => $field['label'], 'label_attr' => ['class' => 'control-label'], 'attr' => $attr, 'mapped' => $mapped, 'multiple' => false, 'constraints' => $constraints];
                 $choiceType = 'choice';
                 $emptyValue = '';
                 if (in_array($type, ['select', 'multiselect']) && !empty($properties['list'])) {
                     $typeProperties['choices'] = FormFieldHelper::parseList($properties['list']);
                     $typeProperties['expanded'] = false;
                     $typeProperties['multiple'] = 'multiselect' === $type;
                 }
                 if ($type == 'boolean' && !empty($properties['yes']) && !empty($properties['no'])) {
                     $choiceType = 'yesno_button_group';
                     $typeProperties['expanded'] = true;
                     $typeProperties['yes_label'] = $properties['yes'];
                     $typeProperties['no_label'] = $properties['no'];
                     $typeProperties['attr'] = [];
                     $emptyValue = ' x ';
                     if ($value !== '' && $value !== null) {
                         $value = (int) $value;
                     }
                 }
                 $typeProperties['data'] = $type === 'multiselect' ? FormFieldHelper::parseList($value) : $value;
                 $typeProperties['empty_value'] = $emptyValue;
                 $builder->add($alias, $choiceType, $typeProperties);
                 break;
             case 'country':
             case 'region':
             case 'timezone':
             case 'locale':
                 switch ($type) {
                     case 'country':
                         $choices = FormFieldHelper::getCountryChoices();
                         break;
                     case 'region':
                         $choices = FormFieldHelper::getRegionChoices();
                         break;
                     case 'timezone':
                         $choices = FormFieldHelper::getTimezonesChoices();
                         break;
                     case 'locale':
                         $choices = FormFieldHelper::getLocaleChoices();
                         break;
                 }
                 $builder->add($alias, 'choice', ['choices' => $choices, 'required' => $required, 'label' => $field['label'], 'label_attr' => ['class' => 'control-label'], 'data' => $value, 'attr' => ['class' => 'form-control', 'data-placeholder' => $field['label']], 'mapped' => $mapped, 'multiple' => false, 'expanded' => false, 'constraints' => $constraints]);
                 break;
             default:
                 if ($type == 'lookup') {
                     $type = 'text';
                     $attr['data-toggle'] = 'field-lookup';
                     $attr['data-action'] = 'lead:fieldList';
                     $attr['data-target'] = $alias;
                     if (!empty($properties['list'])) {
                         $attr['data-options'] = $properties['list'];
                     }
                 }
                 $builder->add($alias, $type, ['required' => $field['isRequired'], 'label' => $field['label'], 'label_attr' => ['class' => 'control-label'], 'attr' => $attr, 'data' => $value, 'mapped' => $mapped, 'constraints' => $constraints]);
                 break;
         }
     }
 }
Beispiel #6
0
 /**
  * @param FormBuilderInterface $builder
  * @param array                $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addEventSubscriber(new CleanFormSubscriber());
     $builder->addEventSubscriber(new FormExitSubscriber('lead.lead', $options));
     if (!$options['isShortForm']) {
         $transformer = new IdToEntityModelTransformer($this->factory->getEntityManager(), 'MauticUserBundle:User');
         $builder->add($builder->create('owner', 'user_list', array('label' => 'mautic.lead.lead.field.owner', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control'), 'required' => false, 'multiple' => false))->addModelTransformer($transformer));
         $imageChoices = array('gravatar' => 'Gravatar', 'custom' => 'mautic.lead.lead.field.custom_avatar');
         $cache = $options['data']->getSocialCache();
         if (count($cache)) {
             foreach ($cache as $key => $data) {
                 $imageChoices[$key] = $key;
             }
         }
         $builder->add('preferred_profile_image', 'choice', array('choices' => $imageChoices, 'label' => 'mautic.lead.lead.field.preferred_profile', 'label_attr' => array('class' => 'control-label'), 'required' => true, 'multiple' => false, 'attr' => array('class' => 'form-control')));
         $builder->add('custom_avatar', 'file', array('label' => false, 'label_attr' => array('class' => 'control-label'), 'required' => false, 'attr' => array('class' => 'form-control'), 'mapped' => false, 'constraints' => array(new File(array('mimeTypes' => array('image/gif', 'image/jpeg', 'image/png'), 'mimeTypesMessage' => 'mautic.lead.avatar.types_invalid')))));
     }
     $fieldValues = !empty($options['data']) ? $options['data']->getFields() : array('filter' => array('isVisible' => true));
     foreach ($options['fields'] as $field) {
         $attr = array('class' => 'form-control');
         $properties = $field['properties'];
         $type = $field['type'];
         $required = $field['isRequired'];
         $alias = $field['alias'];
         $group = $field['group'];
         $value = isset($fieldValues[$group][$alias]['value']) ? $fieldValues[$group][$alias]['value'] : $field['defaultValue'];
         $constraints = array();
         if ($required) {
             $constraints[] = new NotBlank(array('message' => 'mautic.lead.customfield.notblank'));
         }
         if ($type == 'number') {
             if (empty($properties['precision'])) {
                 $properties['precision'] = null;
             } else {
                 $properties['precision'] = (int) $properties['precision'];
             }
             $builder->add($alias, $type, array('required' => $required, 'label' => $field['label'], 'label_attr' => array('class' => 'control-label'), 'attr' => $attr, 'data' => isset($fieldValues[$group][$alias]['value']) ? (double) $fieldValues[$group][$alias]['value'] : (double) $field['defaultValue'], 'mapped' => false, 'constraints' => $constraints, 'precision' => $properties['precision'], 'rounding_mode' => (int) $properties['roundmode']));
         } elseif (in_array($type, array('date', 'datetime', 'time'))) {
             $attr['data-toggle'] = $type;
             $opts = array('required' => $required, 'label' => $field['label'], 'label_attr' => array('class' => 'control-label'), 'widget' => 'single_text', 'attr' => $attr, 'mapped' => false, 'input' => 'string', 'html5' => false, 'constraints' => $constraints);
             $dtHelper = new DateTimeHelper($value, null, 'local');
             if ($type == 'datetime') {
                 $opts['model_timezone'] = 'UTC';
                 $opts['view_timezone'] = date_default_timezone_get();
                 $opts['format'] = 'yyyy-MM-dd HH:mm';
                 $opts['with_seconds'] = false;
                 $opts['data'] = !empty($value) ? $dtHelper->toLocalString('Y-m-d H:i:s') : null;
             } elseif ($type == 'date') {
                 $opts['data'] = !empty($value) ? $dtHelper->toLocalString('Y-m-d') : null;
             } else {
                 $opts['data'] = !empty($value) ? $dtHelper->toLocalString('H:i:s') : null;
             }
             $builder->add($alias, $type, $opts);
         } elseif ($type == 'select' || $type == 'boolean') {
             $choices = array();
             if ($type == 'select' && !empty($properties['list'])) {
                 $list = explode('|', $properties['list']);
                 foreach ($list as $l) {
                     $l = trim($l);
                     $choices[$l] = $l;
                 }
                 $expanded = false;
             }
             if ($type == 'boolean' && !empty($properties['yes']) && !empty($properties['no'])) {
                 $expanded = true;
                 $choices = array(1 => $properties['yes'], 0 => $properties['no']);
                 $attr = array();
             }
             if (!empty($choices)) {
                 $builder->add($alias, 'choice', array('choices' => $choices, 'required' => $required, 'label' => $field['label'], 'label_attr' => array('class' => 'control-label'), 'data' => $type == 'boolean' ? (int) $value : $value, 'attr' => $attr, 'mapped' => false, 'multiple' => false, 'empty_value' => false, 'expanded' => $expanded, 'constraints' => $constraints));
             }
         } elseif ($type == 'country' || $type == 'region' || $type == 'timezone') {
             if ($type == 'country') {
                 $choices = FormFieldHelper::getCountryChoices();
             } elseif ($type == 'region') {
                 $choices = FormFieldHelper::getRegionChoices();
             } else {
                 $choices = FormFieldHelper::getTimezonesChoices();
             }
             $builder->add($alias, 'choice', array('choices' => $choices, 'required' => $required, 'label' => $field['label'], 'label_attr' => array('class' => 'control-label'), 'data' => $value, 'attr' => array('class' => 'form-control', 'data-placeholder' => $field['label']), 'mapped' => false, 'multiple' => false, 'expanded' => false, 'constraints' => $constraints));
         } else {
             if ($type == 'lookup') {
                 $type = "text";
                 $attr['data-toggle'] = 'field-lookup';
                 $attr['data-target'] = $alias;
                 if (!empty($properties['list'])) {
                     $attr['data-options'] = $properties['list'];
                 }
             }
             $builder->add($alias, $type, array('required' => $field['isRequired'], 'label' => $field['label'], 'label_attr' => array('class' => 'control-label'), 'attr' => $attr, 'data' => $value, 'mapped' => false, 'constraints' => $constraints));
         }
     }
     $builder->add('tags', 'lead_tag', array('by_reference' => false, 'attr' => array('data-placeholder' => $this->factory->getTranslator()->trans('mautic.lead.tags.select_or_create'), 'data-no-results-text' => $this->factory->getTranslator()->trans('mautic.lead.tags.enter_to_create'), 'data-allow-add' => 'true', 'onchange' => 'Mautic.createLeadTag(this)')));
     if (!$options['isShortForm']) {
         $builder->add('buttons', 'form_buttons');
     } else {
         $builder->add('buttons', 'form_buttons', array('apply_text' => false, 'save_text' => 'mautic.core.form.save'));
     }
     if (!empty($options["action"])) {
         $builder->setAction($options["action"]);
     }
 }
Beispiel #7
0
 /**
  * @param FormBuilderInterface $builder
  * @param array                $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addEventSubscriber(new CleanFormSubscriber());
     $builder->addEventSubscriber(new FormExitSubscriber('lead.field', $options));
     $builder->add('label', 'text', ['label' => 'mautic.lead.field.label', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control', 'length' => 50]]);
     $disabled = !empty($options['data']) ? $options['data']->isFixed() : false;
     $builder->add('group', 'choice', ['choices' => ['core' => 'mautic.lead.field.group.core', 'social' => 'mautic.lead.field.group.social', 'personal' => 'mautic.lead.field.group.personal', 'professional' => 'mautic.lead.field.group.professional'], 'attr' => ['class' => 'form-control', 'tooltip' => 'mautic.lead.field.form.group.help'], 'expanded' => false, 'multiple' => false, 'label' => 'mautic.lead.field.group', 'empty_value' => false, 'required' => false, 'disabled' => $disabled]);
     $new = !empty($options['data']) && $options['data']->getAlias() ? false : true;
     $type = $options['data']->getType();
     $default = empty($type) ? 'text' : $type;
     $fieldHelper = new FormFieldHelper();
     $fieldHelper->setTranslator($this->translator);
     $builder->add('type', 'choice', ['choices' => $fieldHelper->getChoiceList(), 'expanded' => false, 'multiple' => false, 'label' => 'mautic.lead.field.type', 'empty_value' => false, 'disabled' => $disabled || !$new, 'attr' => ['class' => 'form-control', 'onchange' => 'Mautic.updateLeadFieldProperties(this.value);'], 'data' => $default, 'required' => false]);
     $builder->add('properties_select_template', 'sortablelist', ['mapped' => false, 'label' => 'mautic.lead.field.form.properties.select', 'option_required' => false, 'with_labels' => true]);
     $builder->add('default_template', 'text', ['label' => 'mautic.core.defaultvalue', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control'], 'required' => false, 'mapped' => false]);
     $builder->add('default_bool_template', 'yesno_button_group', ['label' => 'mautic.core.defaultvalue', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control'], 'required' => false, 'mapped' => false, 'data' => '', 'empty_value' => ' x ']);
     $builder->add('properties', 'collection', ['required' => false, 'allow_add' => true, 'error_bubbling' => false]);
     $builder->add('defaultValue', 'text', ['label' => 'mautic.core.defaultvalue', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control'], 'required' => false]);
     $formModifier = function (FormEvent $event, $eventName) {
         $form = $event->getForm();
         $data = $event->getData();
         $type = is_array($data) ? isset($data['type']) ? $data['type'] : null : $data->getType();
         switch ($type) {
             case 'multiselect':
             case 'select':
             case 'lookup':
                 if (is_array($data) && isset($data['properties'])) {
                     $properties = $data['properties'];
                 } else {
                     $properties = $data->getProperties();
                 }
                 $form->add('properties', 'sortablelist', ['required' => false, 'label' => 'mautic.lead.field.form.properties.select', 'data' => $properties, 'with_labels' => true]);
                 break;
             case 'country':
             case 'locale':
             case 'timezone':
             case 'region':
                 switch ($type) {
                     case 'country':
                         $choices = FormFieldHelper::getCountryChoices();
                         break;
                     case 'region':
                         $choices = FormFieldHelper::getRegionChoices();
                         break;
                     case 'timezone':
                         $choices = FormFieldHelper::getTimezonesChoices();
                         break;
                     case 'locale':
                         $choices = FormFieldHelper::getLocaleChoices();
                         break;
                 }
                 $form->add('defaultValue', 'choice', ['choices' => $choices, 'label' => 'mautic.core.defaultvalue', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control'], 'required' => false, 'data' => !empty($value)]);
                 break;
             case 'boolean':
                 if (is_array($data)) {
                     $value = isset($data['defaultValue']) ? $data['defaultValue'] : false;
                     $yesLabel = !empty($data['properties']['yes']) ? $data['properties']['yes'] : 'matuic.core.form.yes';
                     $noLabel = !empty($data['properties']['no']) ? $data['properties']['no'] : 'matuic.core.form.no';
                 } else {
                     $value = $data->getDefaultValue();
                     $props = $data->getProperties();
                     $yesLabel = !empty($props['yes']) ? $props['yes'] : 'matuic.core.form.yes';
                     $noLabel = !empty($props['no']) ? $props['no'] : 'matuic.core.form.no';
                 }
                 if ($value !== '' && $value !== null) {
                     $value = (int) $value;
                 }
                 $form->add('defaultValue', 'yesno_button_group', ['label' => 'mautic.core.defaultvalue', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control'], 'required' => false, 'data' => $value, 'no_label' => $noLabel, 'yes_label' => $yesLabel, 'empty_value' => ' x ']);
                 break;
             case 'datetime':
             case 'date':
             case 'time':
                 $constraints = [];
                 switch ($type) {
                     case 'datetime':
                         $constraints = [new Assert\Callback(function ($object, ExecutionContextInterface $context) {
                             if (!empty($object) && \DateTime::createFromFormat('Y-m-d H:i', $object) === false) {
                                 $context->buildViolation('mautic.lead.datetime.invalid')->addViolation();
                             }
                         })];
                         break;
                     case 'date':
                         $constraints = [new Assert\Callback(function ($object, ExecutionContextInterface $context) {
                             if (!empty($object)) {
                                 $validator = $context->getValidator();
                                 $violations = $validator->validateValue($object, new Assert\Date());
                                 if (count($violations) > 0) {
                                     $context->buildViolation('mautic.lead.date.invalid')->addViolation();
                                 }
                             }
                         })];
                         break;
                     case 'time':
                         $constraints = [new Assert\Callback(function ($object, ExecutionContextInterface $context) {
                             if (!empty($object)) {
                                 $validator = $context->getValidator();
                                 $violations = $validator->validateValue($object, new Assert\Regex(['pattern' => '/(2[0-3]|[01][0-9]):([0-5][0-9])/']));
                                 if (count($violations) > 0) {
                                     $context->buildViolation('mautic.lead.time.invalid')->addViolation();
                                 }
                             }
                         })];
                         break;
                 }
                 $form->add('defaultValue', 'text', ['label' => 'mautic.core.defaultvalue', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control'], 'required' => false, 'constraints' => $constraints]);
                 break;
         }
     };
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($formModifier) {
         $formModifier($event, FormEvents::PRE_SET_DATA);
     });
     $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use($formModifier) {
         $formModifier($event, FormEvents::PRE_SUBMIT);
     });
     //get order list
     $transformer = new FieldToOrderTransformer($this->em);
     $builder->add($builder->create('order', 'entity', ['label' => 'mautic.core.order', 'class' => 'MauticLeadBundle:LeadField', 'property' => 'label', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control'], 'query_builder' => function (EntityRepository $er) {
         return $er->createQueryBuilder('f')->orderBy('f.order', 'ASC');
     }, 'required' => false])->addModelTransformer($transformer));
     $builder->add('alias', 'text', ['label' => 'mautic.core.alias', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control', 'length' => 25, 'tooltip' => 'mautic.lead.field.help.alias'], 'required' => false, 'disabled' => $disabled || !$new]);
     $builder->add('isPublished', 'yesno_button_group', ['disabled' => $options['data']->getAlias() == 'email', 'data' => $options['data']->getAlias() == 'email' ? true : $options['data']->getIsPublished()]);
     $builder->add('isRequired', 'yesno_button_group', ['label' => 'mautic.core.required']);
     $builder->add('isVisible', 'yesno_button_group', ['label' => 'mautic.lead.field.form.isvisible']);
     $builder->add('isShortVisible', 'yesno_button_group', ['label' => 'mautic.lead.field.form.isshortvisible', 'attr' => ['tooltip' => 'mautic.lead.field.form.isshortvisible.tooltip']]);
     $builder->add('isListable', 'yesno_button_group', ['label' => 'mautic.lead.field.form.islistable']);
     $data = $options['data']->isUniqueIdentifier();
     $builder->add('isUniqueIdentifer', 'yesno_button_group', ['label' => 'mautic.lead.field.form.isuniqueidentifer', 'attr' => ['tooltip' => 'mautic.lead.field.form.isuniqueidentifer.tooltip', 'onchange' => 'Mautic.displayUniqueIdentifierWarning(this)'], 'data' => !empty($data)]);
     $builder->add('isPubliclyUpdatable', 'yesno_button_group', ['label' => 'mautic.lead.field.form.ispubliclyupdatable', 'attr' => ['tooltip' => 'mautic.lead.field.form.ispubliclyupdatable.tooltip']]);
     $builder->add('object', 'choice', ['choices' => ['lead' => 'mautic.lead.contact', 'company' => 'mautic.company.company'], 'expanded' => false, 'multiple' => false, 'label' => 'mautic.lead.field.object', 'empty_value' => false, 'attr' => ['class' => 'form-control'], 'required' => true, 'disabled' => $disabled || !$new]);
     $builder->add('buttons', 'form_buttons');
     if (!empty($options['action'])) {
         $builder->setAction($options['action']);
     }
 }
Beispiel #8
0
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
$view->extend('MauticCoreBundle:Default:content.html.php');
$view['slots']->set('mauticContent', 'leadlist');
$id = $form->vars['data']->getId();
if (!empty($id)) {
    $name = $form->vars['data']->getName();
    $header = $view['translator']->trans('mautic.lead.list.header.edit', array("%name%" => $name));
} else {
    $header = $view['translator']->trans('mautic.lead.list.header.new');
}
$view['slots']->set("headerTitle", $header);
$glueOptions = array('and' => 'mautic.lead.list.form.glue.and', 'or' => 'mautic.lead.list.form.glue.or');
//Generate lists for select boxes
$countries = \Mautic\LeadBundle\Helper\FormFieldHelper::getCountryChoices();
$regions = \Mautic\LeadBundle\Helper\FormFieldHelper::getRegionChoices();
$timezones = \Mautic\LeadBundle\Helper\FormFieldHelper::getTimezonesChoices();
$filterForm = $form['filters'];
$filterValues = $filterForm->vars['data'] ?: array();
$form['filters']->setRendered();
?>

<?php 
echo $view['form']->start($form);
?>
    <div class="box-layout">
        <div class="col-md-9 bg-white height-auto">
            <div class="row">
                <div class="col-xs-12">
                    <ul class="bg-auto nav nav-tabs pr-md pl-md">
                        <li class="active">
Beispiel #9
0
 /**
  * @param FormBuilderInterface $builder
  * @param array                $options
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addEventSubscriber(new CleanFormSubscriber());
     $builder->addEventSubscriber(new FormExitSubscriber('lead.lead', $options));
     if (!$options['isShortForm']) {
         $transformer = new \Mautic\CoreBundle\Form\DataTransformer\IdToEntityModelTransformer($this->factory->getEntityManager(), 'MauticUserBundle:User');
         $builder->add($builder->create('owner', 'user_list', array('label' => 'mautic.lead.lead.field.owner', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control'), 'required' => false, 'multiple' => false))->addModelTransformer($transformer));
         $imageChoices = array('gravatar' => 'Gravatar');
         foreach ($options['data']->getSocialCache() as $key => $data) {
             $imageChoices[$key] = $key;
         }
         $builder->add('preferred_profile_image', 'choice', array('choices' => $imageChoices, 'label' => 'mautic.lead.lead.field.preferred_profile', 'label_attr' => array('class' => 'control-label'), 'required' => true, 'multiple' => false, 'attr' => array('class' => 'form-control')));
     }
     $fieldValues = !empty($options['data']) ? $options['data']->getFields() : array('filter' => array('isVisible' => true));
     foreach ($options['fields'] as $field) {
         $attr = array('class' => 'form-control');
         $properties = $field['properties'];
         $type = $field['type'];
         $required = $field['isRequired'];
         $alias = $field['alias'];
         $group = $field['group'];
         $value = isset($fieldValues[$group][$alias]['value']) ? $fieldValues[$group][$alias]['value'] : $field['defaultValue'];
         $constraints = array();
         if ($required) {
             $constraints[] = new \Symfony\Component\Validator\Constraints\NotBlank(array('message' => 'mautic.lead.customfield.notblank'));
         }
         if ($type == 'number') {
             if (empty($properties['precision'])) {
                 $properties['precision'] = null;
             } else {
                 $properties['precision'] = (int) $properties['precision'];
             }
             $builder->add($alias, $type, array('required' => $required, 'label' => $field['label'], 'label_attr' => array('class' => 'control-label'), 'attr' => $attr, 'data' => isset($fieldValues[$group][$alias]['value']) ? (double) $fieldValues[$group][$alias]['value'] : (double) $field['defaultValue'], 'mapped' => false, 'constraints' => $constraints, 'precision' => $properties['precision'], 'rounding_mode' => (int) $properties['roundmode']));
         } elseif (in_array($type, array('date', 'datetime', 'time'))) {
             $attr['data-toggle'] = $type;
             $opts = array('required' => $required, 'label' => $field['label'], 'label_attr' => array('class' => 'control-label'), 'widget' => 'single_text', 'attr' => $attr, 'data' => $value, 'mapped' => false, 'constraints' => $constraints, 'input' => 'string');
             if ($type == 'date' || $type == 'time') {
                 $opts['input'] = 'string';
                 $builder->add($alias, $type, $opts);
             } else {
                 $opts['model_timezone'] = 'UTC';
                 $opts['view_timezone'] = date_default_timezone_get();
                 $opts['format'] = 'yyyy-MM-dd HH:mm';
             }
             $builder->add($alias, $type, $opts);
         } elseif ($type == 'select' || $type == 'boolean') {
             $choices = array();
             if ($type == 'select' && !empty($properties['list'])) {
                 $list = explode('|', $properties['list']);
                 foreach ($list as $l) {
                     $l = trim($l);
                     $choices[$l] = $l;
                 }
                 $expanded = false;
             }
             if ($type == 'boolean' && !empty($properties['yes']) && !empty($properties['no'])) {
                 $expanded = true;
                 $choices = array(1 => $properties['yes'], 0 => $properties['no']);
                 $attr = array();
             }
             if (!empty($choices)) {
                 $builder->add($alias, 'choice', array('choices' => $choices, 'required' => $required, 'label' => $field['label'], 'label_attr' => array('class' => 'control-label'), 'data' => $value, 'attr' => $attr, 'mapped' => false, 'multiple' => false, 'empty_value' => false, 'expanded' => $expanded, 'constraints' => $constraints));
             }
         } elseif ($type == 'country' || $type == 'region' || $type == 'timezone') {
             if ($type == 'country') {
                 $choices = FormFieldHelper::getCountryChoices();
             } elseif ($type == 'region') {
                 $choices = FormFieldHelper::getRegionChoices();
             } else {
                 $choices = FormFieldHelper::getTimezonesChoices();
             }
             $builder->add($alias, 'choice', array('choices' => $choices, 'required' => $required, 'label' => $field['label'], 'label_attr' => array('class' => 'control-label'), 'data' => $value, 'attr' => array('class' => 'form-control', 'data-placeholder' => $field['label']), 'mapped' => false, 'multiple' => false, 'expanded' => false, 'constraints' => $constraints));
         } else {
             if ($type == 'lookup') {
                 $type = "text";
                 $attr['data-toggle'] = 'field-lookup';
                 $attr['data-target'] = $alias;
                 if (!empty($properties['list'])) {
                     $attr['data-options'] = $properties['list'];
                 }
             }
             $builder->add($alias, $type, array('required' => $field['isRequired'], 'label' => $field['label'], 'label_attr' => array('class' => 'control-label'), 'attr' => $attr, 'data' => $value, 'mapped' => false, 'constraints' => $constraints));
         }
     }
     if (!$options['isShortForm']) {
         $builder->add('buttons', 'form_buttons');
     } else {
         $builder->add('buttons', 'form_buttons', array('apply_text' => false, 'save_text' => 'mautic.core.form.save'));
     }
     if (!empty($options["action"])) {
         $builder->setAction($options["action"]);
     }
 }
Beispiel #10
0
 /**
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 protected function updateLeadFieldValuesAction(Request $request)
 {
     $alias = InputHelper::clean($request->request->get('alias'));
     $dataArray = ['success' => 0, 'options' => null];
     $leadField = $this->getModel('lead.field')->getRepository()->findOneBy(['alias' => $alias]);
     $choiceTypes = ['boolean', 'locale', 'country', 'region', 'lookup', 'timezone', 'select', 'radio'];
     if ($leadField && in_array($leadField->getType(), $choiceTypes)) {
         $properties = $leadField->getProperties();
         $leadFieldType = $leadField->getType();
         if (!empty($properties['list'])) {
             // Lookup/Select options
             $options = explode('|', $properties['list']);
             $options = array_combine($options, $options);
         } elseif (!empty($properties) && $leadFieldType == 'boolean') {
             // Boolean options
             $options = [0 => $properties['no'], 1 => $properties['yes']];
         } else {
             switch ($leadFieldType) {
                 case 'country':
                     $options = FormFieldHelper::getCountryChoices();
                     break;
                 case 'region':
                     $options = FormFieldHelper::getRegionChoices();
                     break;
                 case 'timezone':
                     $options = FormFieldHelper::getTimezonesChoices();
                     break;
                 case 'locale':
                     $options = FormFieldHelper::getLocaleChoices();
                     break;
                 default:
                     $options = !empty($properties) ? $properties : [];
             }
         }
         $dataArray['options'] = $options;
     }
     $dataArray['success'] = 1;
     return $this->sendJsonResponse($dataArray);
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('field', 'leadfields_choices', ['label' => 'mautic.lead.campaign.event.field', 'label_attr' => ['class' => 'control-label'], 'multiple' => false, 'empty_value' => 'mautic.core.select', 'attr' => ['class' => 'form-control', 'tooltip' => 'mautic.lead.campaign.event.field_descr', 'onchange' => 'Mautic.updateLeadFieldValues(this)'], 'required' => true, 'constraints' => [new NotBlank(['message' => 'mautic.core.value.required'])]]);
     $leadModel = $this->factory->getModel('lead.lead');
     $fieldModel = $this->factory->getModel('lead.field');
     $operators = $leadModel->getFilterExpressionFunctions();
     $choices = [];
     foreach ($operators as $key => $operator) {
         $choices[$key] = $operator['label'];
     }
     $builder->add('operator', 'choice', ['choices' => $choices]);
     $ff = $builder->getFormFactory();
     // function to add 'template' choice field dynamically
     $func = function (FormEvent $e) use($ff, $fieldModel) {
         $data = $e->getData();
         $form = $e->getForm();
         $fieldValues = null;
         $fieldType = null;
         $choiceTypes = ['boolean', 'locale', 'country', 'region', 'lookup', 'timezone', 'select', 'radio'];
         if (isset($data['field'])) {
             $field = $fieldModel->getRepository()->findOneBy(['alias' => $data['field']]);
             if ($field) {
                 $properties = $field->getProperties();
                 $fieldType = $field->getType();
                 if (!empty($properties['list'])) {
                     // Lookup/Select options
                     $fieldValues = explode('|', $properties['list']);
                     $fieldValues = array_combine($fieldValues, $fieldValues);
                 } elseif (!empty($properties) && $fieldType == 'boolean') {
                     // Boolean options
                     $fieldValues = [0 => $properties['no'], 1 => $properties['yes']];
                 } else {
                     switch ($fieldType) {
                         case 'country':
                             $fieldValues = FormFieldHelper::getCountryChoices();
                             break;
                         case 'region':
                             $fieldValues = FormFieldHelper::getRegionChoices();
                             break;
                         case 'timezone':
                             $fieldValues = FormFieldHelper::getTimezonesChoices();
                             break;
                         case 'locale':
                             $fieldValues = FormFieldHelper::getLocaleChoices();
                             break;
                         default:
                             if (!empty($properties)) {
                                 $fieldValues = $properties;
                             }
                     }
                 }
             }
         }
         // Display selectbox for a field with choices, textbox for others
         if (!empty($fieldValues) && in_array($fieldType, $choiceTypes)) {
             $form->add('value', 'choice', ['choices' => $fieldValues, 'label' => 'mautic.form.field.form.value', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control'], 'required' => true, 'constraints' => [new NotBlank(['message' => 'mautic.core.value.required'])]]);
         } else {
             $form->add('value', 'text', ['label' => 'mautic.form.field.form.value', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control'], 'required' => true, 'constraints' => [new NotBlank(['message' => 'mautic.core.value.required'])]]);
         }
     };
     // Register the function above as EventListener on PreSet and PreBind
     $builder->addEventListener(FormEvents::PRE_SET_DATA, $func);
     $builder->addEventListener(FormEvents::PRE_SUBMIT, $func);
 }