/** * @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', array('label' => 'mautic.lead.field.label', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control', 'length' => 50))); $disabled = !empty($options['data']) ? $options['data']->isFixed() : false; $builder->add('group', 'choice', array('choices' => array('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' => array('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; $default = $new ? 'text' : $options['data']->getType(); $fieldHelper = new FormFieldHelper(); $fieldHelper->setTranslator($this->translator); $builder->add('type', 'choice', array('choices' => $fieldHelper->getChoiceList(), 'expanded' => false, 'multiple' => false, 'label' => 'mautic.lead.field.type', 'empty_value' => false, 'disabled' => $disabled || !$new, 'attr' => array('class' => 'form-control', 'onchange' => 'Mautic.updateLeadFieldProperties(this.value);'), 'data' => $default, 'required' => false)); $builder->add('properties', 'collection', array('required' => false, 'allow_add' => true, 'error_bubbling' => false)); $builder->add('defaultValue', 'text', array('label' => 'mautic.core.defaultvalue', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control'), 'required' => false)); //get order list $transformer = new FieldToOrderTransformer($this->em); $builder->add($builder->create('order', 'entity', array('label' => 'mautic.core.order', 'class' => 'MauticLeadBundle:LeadField', 'property' => 'label', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control'), 'query_builder' => function (EntityRepository $er) { return $er->createQueryBuilder('f')->orderBy('f.order', 'ASC'); }, 'required' => false))->addModelTransformer($transformer)); $builder->add('alias', 'text', array('label' => 'mautic.core.alias', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control', 'length' => 25, 'tooltip' => 'mautic.lead.field.help.alias'), 'required' => false, 'disabled' => $disabled || !$new)); $data = $disabled ? true : $options['data']->getIsPublished(); $builder->add('isPublished', 'yesno_button_group', array('disabled' => $disabled, 'data' => $data)); $builder->add('isRequired', 'yesno_button_group', array('label' => 'mautic.core.required')); $builder->add('isVisible', 'yesno_button_group', array('label' => 'mautic.lead.field.form.isvisible')); $builder->add('isShortVisible', 'yesno_button_group', array('label' => 'mautic.lead.field.form.isshortvisible')); $builder->add('isListable', 'yesno_button_group', array('label' => 'mautic.lead.field.form.islistable')); $builder->add('isUniqueIdentifer', 'yesno_button_group', array('label' => 'mautic.lead.field.form.isuniqueidentifer', 'attr' => array('tooltip' => 'mautic.lead.field.form.isuniqueidentifer.tooltip'))); $builder->add('isPubliclyUpdatable', 'yesno_button_group', array('label' => 'mautic.lead.field.form.ispubliclyupdatable', 'attr' => array('tooltip' => 'mautic.lead.field.form.ispubliclyupdatable.tooltip'))); $builder->add('buttons', 'form_buttons'); if (!empty($options["action"])) { $builder->setAction($options["action"]); } }
/** * @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']; } }
/** * @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']; } }
/** * @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']; } }
/** * Get a list of field choices for filters. * * @return array */ public function getChoiceFields() { $operators = ['text' => ['include' => ['=', '!=', 'empty', '!empty', 'like', '!like']], 'select' => ['include' => ['=', '!=', 'empty', '!empty', 'in', '!in']], 'bool' => ['include' => ['=', '!=']], 'default' => ['exclude' => ['in', '!in']], 'multiselect' => ['include' => ['in', '!in']]]; //field choices $choices['lead'] = ['date_added' => ['label' => $this->translator->trans('mautic.core.date.added'), 'properties' => ['type' => 'date'], 'operators' => 'default', 'object' => 'lead'], 'date_identified' => ['label' => $this->translator->trans('mautic.lead.list.filter.date_identified'), 'properties' => ['type' => 'date'], 'operators' => 'default', 'object' => 'lead'], 'last_active' => ['label' => $this->translator->trans('mautic.lead.list.filter.last_active'), 'properties' => ['type' => 'date'], 'operators' => 'default', 'object' => 'lead'], 'owner_id' => ['label' => $this->translator->trans('mautic.lead.list.filter.owner'), 'properties' => ['type' => 'lookup_id', 'callback' => 'activateLeadFieldTypeahead'], 'operators' => 'text', 'object' => 'lead'], 'points' => ['label' => $this->translator->trans('mautic.lead.lead.event.points'), 'properties' => ['type' => 'number'], 'operators' => 'default', 'object' => 'lead'], 'leadlist' => ['label' => $this->translator->trans('mautic.lead.list.filter.lists'), 'properties' => ['type' => 'leadlist'], 'operators' => 'multiselect', 'object' => 'lead'], 'lead_email_received' => ['label' => $this->translator->trans('mautic.lead.list.filter.lead_email_received'), 'properties' => ['type' => 'lead_email_received'], 'operators' => ['include' => ['in', '!in']], 'object' => 'lead'], 'tags' => ['label' => $this->translator->trans('mautic.lead.list.filter.tags'), 'properties' => ['type' => 'tags'], 'operators' => 'multiselect', 'object' => 'lead'], 'dnc_bounced' => ['label' => $this->translator->trans('mautic.lead.list.filter.dnc_bounced'), 'properties' => ['type' => 'boolean', 'list' => [0 => $this->translator->trans('mautic.core.form.no'), 1 => $this->translator->trans('mautic.core.form.yes')]], 'operators' => 'bool', 'object' => 'lead'], 'dnc_unsubscribed' => ['label' => $this->translator->trans('mautic.lead.list.filter.dnc_unsubscribed'), 'properties' => ['type' => 'boolean', 'list' => [0 => $this->translator->trans('mautic.core.form.no'), 1 => $this->translator->trans('mautic.core.form.yes')]], 'operators' => 'bool', 'object' => 'lead'], 'dnc_bounced_sms' => ['label' => $this->translator->trans('mautic.lead.list.filter.dnc_bounced_sms'), 'properties' => ['type' => 'boolean', 'list' => [0 => $this->translator->trans('mautic.core.form.no'), 1 => $this->translator->trans('mautic.core.form.yes')]], 'operators' => 'bool', 'object' => 'lead'], 'dnc_unsubscribed_sms' => ['label' => $this->translator->trans('mautic.lead.list.filter.dnc_unsubscribed_sms'), 'properties' => ['type' => 'boolean', 'list' => [0 => $this->translator->trans('mautic.core.form.no'), 1 => $this->translator->trans('mautic.core.form.yes')]], 'operators' => 'bool', 'object' => 'lead'], 'hit_url' => ['label' => $this->translator->trans('mautic.lead.list.filter.visited_url'), 'properties' => ['type' => 'text'], 'operators' => ['include' => ['=', 'like']], 'object' => 'lead'], 'stage' => ['label' => $this->translator->trans('mautic.lead.lead.field.stage'), 'properties' => ['type' => 'stage'], 'operators' => ['include' => ['=', '!=']], 'object' => 'lead']]; //get list of custom fields $fields = $this->em->getRepository('MauticLeadBundle:LeadField')->getEntities(['filter' => ['isListable' => true, 'isPublished' => true], 'orderBy' => 'f.object']); foreach ($fields as $field) { $type = $field->getType(); $properties = $field->getProperties(); $properties['type'] = $type; if (in_array($type, ['lookup', 'multiselect', 'boolean'])) { if ($type == 'boolean') { //create a lookup list with ID $properties['list'] = [0 => $properties['no'], 1 => $properties['yes']]; } else { $properties['callback'] = 'activateLeadFieldTypeahead'; } $properties['list'] = isset($properties['list']) ? FormFieldHelper::formatList(FormFieldHelper::FORMAT_BAR, FormFieldHelper::parseList($properties['list'])) : ''; } $choices[$field->getObject()][$field->getAlias()] = ['label' => $field->getLabel(), 'properties' => $properties, 'object' => $field->getObject()]; // Set operators allowed if ($type == 'boolean') { $choices[$field->getObject()][$field->getAlias()]['operators'] = 'bool'; } elseif (in_array($type, ['select', 'multiselect', 'country', 'timezone', 'region', 'locale'])) { $choices[$field->getObject()][$field->getAlias()]['operators'] = 'select'; } elseif (in_array($type, ['lookup', 'lookup_id', 'text', 'email', 'url', 'email', 'tel'])) { $choices[$field->getObject()][$field->getAlias()]['operators'] = 'text'; } else { $choices[$field->getObject()][$field->getAlias()]['operators'] = 'default'; } } foreach ($choices as $key => $choice) { $cmp = function ($a, $b) { return strcmp($a['label'], $b['label']); }; uasort($choice, $cmp); $choices[$key] = $choice; } foreach ($choices as $object => $choiceObject) { foreach ($choiceObject as $key => $choice) { if (array_key_exists('operators', $choice) && is_string($choice['operators']) && array_key_exists($choice['operators'], $operators)) { $choices[$object][$key]['operators'] = $operators[$choice['operators']]; } } } return $choices; }
/** * {@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); }
/** * @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', array('label' => 'mautic.lead.field.label', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control', 'length' => 50))); $disabled = !empty($options['data']) ? $options['data']->isFixed() : false; $builder->add('group', 'choice', array('choices' => array('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' => array('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; $default = $new ? 'text' : $options['data']->getType(); $fieldHelper = new FormFieldHelper(); $fieldHelper->setTranslator($this->translator); $builder->add('type', 'choice', array('choices' => $fieldHelper->getChoiceList(), 'expanded' => false, 'multiple' => false, 'label' => 'mautic.lead.field.type', 'empty_value' => false, 'disabled' => $disabled || !$new, 'attr' => array('class' => 'form-control', 'onchange' => 'Mautic.updateLeadFieldProperties(this.value);'), 'data' => $default, 'required' => false)); $builder->add('properties_select_template', 'sortablelist', array('mapped' => false, 'label' => 'mautic.lead.field.form.properties.select', 'option_required' => false)); $builder->add('default_template', 'text', array('label' => 'mautic.core.defaultvalue', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control'), 'required' => false, 'mapped' => false)); $builder->add('default_bool_template', 'yesno_button_group', array('label' => 'mautic.core.defaultvalue', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control'), 'required' => false, 'mapped' => false, 'data' => false)); $builder->add('properties', 'collection', array('required' => false, 'allow_add' => true, 'error_bubbling' => false)); $builder->add('defaultValue', 'text', array('label' => 'mautic.core.defaultvalue', 'label_attr' => array('class' => 'control-label'), 'attr' => array('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(); if ($type == 'select' || $type == 'lookup') { if (is_array($data) && isset($data['properties'])) { $properties = $data['properties']; } else { $properties = $data->getProperties(); } if (isset($properties['list']) && is_string($properties['list'])) { $properties['list'] = array_map('trim', explode('|', $properties['list'])); } $form->add('properties', 'sortablelist', array('required' => false, 'label' => 'mautic.lead.field.form.properties.select', 'data' => $properties)); } elseif ($type == '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'; } $form->add('defaultValue', 'yesno_button_group', array('label' => 'mautic.core.defaultvalue', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control'), 'required' => false, 'data' => !empty($value), 'choice_list' => new ChoiceList(array(false, true), array($noLabel, $yesLabel)))); } elseif (in_array($type, array('datetime', 'date', 'time'))) { $constraints = array(); if ($type === 'datetime') { $constraints = array(new Assert\Callback(function ($object, ExecutionContextInterface $context) { if (\DateTime::createFromFormat('Y-m-d H:i', $object) === false) { $context->buildViolation('mautic.lead.datetime.invalid')->addViolation(); } })); } elseif ($type === 'date') { $constraints = array(new Assert\Date(array('message' => 'mautic.lead.date.invalid'))); } elseif ($type === 'time') { $constraints = array(new Assert\Regex(array('pattern' => '/(2[0-3]|[01][0-9]):([0-5][0-9])/', 'message' => 'mautic.lead.time.invalid'))); } $form->add('defaultValue', 'text', array('label' => 'mautic.core.defaultvalue', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control'), 'required' => false, 'constraints' => $constraints)); } }; $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', array('label' => 'mautic.core.order', 'class' => 'MauticLeadBundle:LeadField', 'property' => 'label', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control'), 'query_builder' => function (EntityRepository $er) { return $er->createQueryBuilder('f')->orderBy('f.order', 'ASC'); }, 'required' => false))->addModelTransformer($transformer)); $builder->add('alias', 'text', array('label' => 'mautic.core.alias', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control', 'length' => 25, 'tooltip' => 'mautic.lead.field.help.alias'), 'required' => false, 'disabled' => $disabled || !$new)); $data = $disabled ? true : $options['data']->getIsPublished(); $builder->add('isPublished', 'yesno_button_group', array('disabled' => $disabled, 'data' => $data)); $builder->add('isRequired', 'yesno_button_group', array('label' => 'mautic.core.required')); $builder->add('isVisible', 'yesno_button_group', array('label' => 'mautic.lead.field.form.isvisible')); $builder->add('isShortVisible', 'yesno_button_group', array('label' => 'mautic.lead.field.form.isshortvisible')); $builder->add('isListable', 'yesno_button_group', array('label' => 'mautic.lead.field.form.islistable')); $data = $options['data']->isUniqueIdentifier(); $builder->add('isUniqueIdentifer', 'yesno_button_group', array('label' => 'mautic.lead.field.form.isuniqueidentifer', 'attr' => array('tooltip' => 'mautic.lead.field.form.isuniqueidentifer.tooltip', 'onchange' => 'Mautic.displayUniqueIdentifierWarning(this)'), 'data' => !empty($data))); $builder->add('isPubliclyUpdatable', 'yesno_button_group', array('label' => 'mautic.lead.field.form.ispubliclyupdatable', 'attr' => array('tooltip' => 'mautic.lead.field.form.ispubliclyupdatable.tooltip'))); $builder->add('buttons', 'form_buttons'); if (!empty($options["action"])) { $builder->setAction($options["action"]); } }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { // Populate settings $cleanMasks = ['labelAttributes' => 'string', 'inputAttributes' => 'string', 'containerAttributes' => 'string', 'label' => 'strict_html']; $addHelpMessage = $addShowLabel = $allowCustomAlias = $addDefaultValue = $addLabelAttributes = $addInputAttributes = $addContainerAttributes = $addLeadFieldList = $addSaveResult = $addBehaviorFields = $addIsRequired = true; if (!empty($options['customParameters'])) { $type = 'custom'; $customParams = $options['customParameters']; $formTypeOptions = ['required' => false, 'label' => false]; if (!empty($customParams['formTypeOptions'])) { $formTypeOptions = array_merge($formTypeOptions, $customParams['formTypeOptions']); } $addFields = ['labelText', 'addHelpMessage', 'addShowLabel', 'labelText', 'addDefaultValue', 'addLabelAttributes', 'labelAttributesText', 'addInputAttributes', 'inputAttributesText', 'addContainerAttributes', 'containerAttributesText', 'addLeadFieldList', 'addSaveResult', 'addBehaviorFields', 'addIsRequired', 'addHtml']; foreach ($addFields as $f) { if (isset($customParams['builderOptions'][$f])) { ${$f} = (bool) $customParams['builderOptions'][$f]; } } } else { $type = $options['data']['type']; switch ($type) { case 'freetext': $addHelpMessage = $addDefaultValue = $addIsRequired = $addLeadFieldList = $addSaveResult = $addBehaviorFields = false; $labelText = 'mautic.form.field.form.header'; $showLabelText = 'mautic.form.field.form.showheader'; $inputAttributesText = 'mautic.form.field.form.freetext_attributes'; $labelAttributesText = 'mautic.form.field.form.header_attributes'; // Allow html $cleanMasks['properties'] = 'html'; break; case 'button': $addHelpMessage = $addShowLabel = $addDefaultValue = $addLabelAttributes = $addIsRequired = $addLeadFieldList = $addSaveResult = $addBehaviorFields = false; break; case 'hidden': $addHelpMessage = $addShowLabel = $addLabelAttributes = $addIsRequired = false; break; case 'captcha': $addShowLabel = $addIsRequired = $addDefaultValue = $addLeadFieldList = $addSaveResult = $addBehaviorFields = false; break; case 'pagebreak': $addShowLabel = $allowCustomAlias = $addHelpMessage = $addIsRequired = $addDefaultValue = $addLeadFieldList = $addSaveResult = $addBehaviorFields = false; break; case 'email': $addBehaviorFields = false; break; case 'select': $cleanMasks['properties']['list']['list']['label'] = 'strict_html'; break; case 'checkboxgrp': case 'radiogrp': $cleanMasks['properties']['optionlist']['list']['label'] = 'strict_html'; break; } } // Build form fields $builder->add('label', 'text', ['label' => !empty($labelText) ? $labelText : 'mautic.form.field.form.label', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control'], 'constraints' => [new Assert\NotBlank(['message' => 'mautic.form.field.label.notblank'])]]); if ($allowCustomAlias) { $builder->add('alias', 'text', ['label' => 'mautic.form.field.form.alias', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control', 'tooltip' => 'mautic.form.field.form.alias.tooltip'], 'disabled' => !empty($options['data']['id']) && strpos($options['data']['id'], 'new') === false ? true : false, 'required' => false]); } if ($addShowLabel) { $default = !isset($options['data']['showLabel']) ? true : (bool) $options['data']['showLabel']; $builder->add('showLabel', 'yesno_button_group', ['label' => !empty($showLabelText) ? $showLabelText : 'mautic.form.field.form.showlabel', 'data' => $default]); } if ($addDefaultValue) { $builder->add('defaultValue', $type == 'textarea' ? 'textarea' : 'text', ['label' => 'mautic.core.defaultvalue', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control'], 'required' => false]); } if ($addHelpMessage) { $builder->add('helpMessage', 'text', ['label' => 'mautic.form.field.form.helpmessage', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control', 'tooltip' => 'mautic.form.field.help.helpmessage'], 'required' => false]); } if ($addIsRequired) { $default = !isset($options['data']['isRequired']) ? false : (bool) $options['data']['isRequired']; $builder->add('isRequired', 'yesno_button_group', ['label' => 'mautic.core.required', 'data' => $default]); $builder->add('validationMessage', 'text', ['label' => 'mautic.form.field.form.validationmsg', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control'], 'required' => false]); } if ($addLabelAttributes) { $builder->add('labelAttributes', 'text', ['label' => !empty($labelAttributesText) ? $labelAttributesText : 'mautic.form.field.form.labelattr', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control', 'tooltip' => 'mautic.form.field.help.attr', 'maxlength' => '255'], 'required' => false]); } if ($addInputAttributes) { $builder->add('inputAttributes', 'text', ['label' => !empty($inputAttributesText) ? $inputAttributesText : 'mautic.form.field.form.inputattr', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control', 'tooltip' => 'mautic.form.field.help.attr', 'maxlength' => '255'], 'required' => false]); } if ($addContainerAttributes) { $builder->add('containerAttributes', 'text', ['label' => !empty($containerAttributesText) ? $containerAttributesText : 'mautic.form.field.form.container_attr', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control', 'tooltip' => 'mautic.form.field.help.container_attr', 'maxlength' => '255'], 'required' => false]); } if ($addSaveResult) { $default = !isset($options['data']['saveResult']) || $options['data']['saveResult'] === null ? true : (bool) $options['data']['saveResult']; $builder->add('saveResult', 'yesno_button_group', ['label' => 'mautic.form.field.form.saveresult', 'data' => $default, 'attr' => ['tooltip' => 'mautic.form.field.help.saveresult']]); } if ($addBehaviorFields) { $default = !isset($options['data']['showWhenValueExists']) || $options['data']['showWhenValueExists'] === null ? true : (bool) $options['data']['showWhenValueExists']; $builder->add('showWhenValueExists', 'yesno_button_group', ['label' => 'mautic.form.field.form.show.when.value.exists', 'data' => $default, 'attr' => ['tooltip' => 'mautic.form.field.help.show.when.value.exists']]); $builder->add('showAfterXSubmissions', 'text', ['label' => 'mautic.form.field.form.show.after.x.submissions', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control', 'tooltip' => 'mautic.form.field.help.show.after.x.submissions'], 'required' => false]); $isAutoFillValue = !isset($options['data']['isAutoFill']) ? false : (bool) $options['data']['isAutoFill']; $builder->add('isAutoFill', 'yesno_button_group', ['label' => 'mautic.form.field.form.auto_fill', 'data' => $isAutoFillValue, 'attr' => ['class' => 'auto-fill-data', 'tooltip' => 'mautic.form.field.help.auto_fill']]); } if ($addLeadFieldList) { if (!isset($options['data']['leadField'])) { switch ($type) { case 'email': $data = 'email'; break; case 'country': $data = 'country'; break; case 'tel': $data = 'phone'; break; default: $data = ''; break; } } elseif (isset($options['data']['leadField'])) { $data = $options['data']['leadField']; } else { $data = ''; } $builder->add('leadField', 'choice', ['choices' => $options['leadFields'], 'choice_attr' => function ($val, $key, $index) use($options) { if (!empty($options['leadFieldProperties'][$val]) && (in_array($options['leadFieldProperties'][$val]['type'], FormFieldHelper::getListTypes()) || !empty($options['leadFieldProperties'][$val]['properties']['list']) || !empty($options['leadFieldProperties'][$val]['properties']['optionlist']))) { return ['data-list-type' => 1]; } return []; }, 'label' => 'mautic.form.field.form.lead_field', 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control', 'tooltip' => 'mautic.form.field.help.lead_field'], 'required' => false, 'data' => $data]); } $builder->add('type', 'hidden'); $update = !empty($options['data']['id']) ? true : false; if (!empty($update)) { $btnValue = 'mautic.core.form.update'; $btnIcon = 'fa fa-pencil'; } else { $btnValue = 'mautic.core.form.add'; $btnIcon = 'fa fa-plus'; } $builder->add('buttons', 'form_buttons', ['save_text' => $btnValue, 'save_icon' => $btnIcon, 'apply_text' => false, 'container_class' => 'bottom-form-buttons']); $builder->add('formId', 'hidden', ['mapped' => false]); // Put properties last so that the other values are available to form events if (!empty($options['customParameters'])) { $builder->add('properties', $customParams['formType'], $formTypeOptions); } else { $propertiesData = isset($options['data']['properties']) ? $options['data']['properties'] : []; switch ($type) { case 'select': case 'country': $builder->add('properties', 'formfield_select', ['field_type' => $type, 'label' => false, 'parentData' => $options['data'], 'data' => $propertiesData]); break; case 'checkboxgrp': case 'radiogrp': $builder->add('properties', 'formfield_group', ['label' => false, 'data' => $propertiesData]); break; case 'freetext': $builder->add('properties', 'formfield_text', ['required' => false, 'label' => false, 'editor' => true, 'data' => $propertiesData]); break; case 'date': case 'email': case 'number': case 'tel': case 'text': case 'url': $builder->add('properties', 'formfield_placeholder', ['label' => false, 'data' => $propertiesData]); break; case 'captcha': $builder->add('properties', 'formfield_captcha', ['label' => false, 'data' => $propertiesData]); break; case 'pagebreak': $builder->add('properties', FormFieldPageBreakType::class, ['label' => false, 'data' => $propertiesData]); break; } } $builder->addEventSubscriber(new CleanFormSubscriber($cleanMasks)); if (!empty($options['action'])) { $builder->setAction($options['action']); } }
/** * @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']); } }
</div> <div class="tab-pane fade bdr-w-0" id="filters"> <div class="form-group"> <div class="available-filters mb-md pl-0 col-md-4" data-prototype="<?php echo $view->escape($view['form']->row($form['filters']->vars['prototype'])); ?> " data-index="<?php echo $index + 1; ?> "> <select class="chosen form-control" id="available_filters"> <option value=""></option> <?php foreach ($fields as $value => $params) { $list = !empty($params['properties']['list']) ? $params['properties']['list'] : array(); $choices = \Mautic\LeadBundle\Helper\FormFieldHelper::parseListStringIntoArray($list); $list = json_encode($choices); $callback = !empty($params['properties']['callback']) ? $params['properties']['callback'] : ''; $operators = !empty($params['operators']) ? $view->escape(json_encode($params['operators'])) : '{}'; ?> <option value="<?php echo $value; ?> " id="available_<?php echo $value; ?> " data-field-type="<?php echo $params['properties']['type']; ?> " data-field-list="<?php echo $view->escape($list);
*/ $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"> <a href="#details" role="tab" data-toggle="tab"><?php
"> <select class="chosen form-control" id="available_filters"> <option value=""></option> <?php foreach ($fields as $object => $field) { $header = $object; $icon = $object == 'company' ? 'fa-building' : 'fa-user'; ?> <optgroup label="<?php echo $view['translator']->trans('mautic.lead.' . $header); ?> "> <?php foreach ($field as $value => $params) { $list = !empty($params['properties']['list']) ? $params['properties']['list'] : []; $choices = \Mautic\LeadBundle\Helper\FormFieldHelper::parseList($list); $object = $object; $list = json_encode($choices); $callback = !empty($params['properties']['callback']) ? $params['properties']['callback'] : ''; $operators = !empty($params['operators']) ? $view->escape(json_encode($params['operators'])) : '{}'; ?> <option value="<?php echo $value; ?> " id="available_<?php echo $value; ?> " data-field-object="<?php echo $object; ?> " data-field-type="<?php
/** * @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"]); } }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('glue', 'choice', ['label' => false, 'choices' => ['and' => 'mautic.lead.list.form.glue.and', 'or' => 'mautic.lead.list.form.glue.or'], 'attr' => ['class' => 'form-control not-chosen glue-select', 'onchange' => 'Mautic.updateFilterPositioning(this)']]); $translator = $this->translator; $operatorChoices = $this->operatorChoices; $currentListId = $this->currentListId; $formModifier = function (FormEvent $event, $eventName) use($translator, $operatorChoices, $currentListId) { $data = $event->getData(); $form = $event->getForm(); $options = $form->getConfig()->getOptions(); $fieldType = $data['type']; $fieldName = $data['field']; $type = 'text'; $attr = ['class' => 'form-control']; $displayType = 'hidden'; $displayAttr = []; $field = []; if (isset($options['fields']['lead'][$fieldName])) { $field = $options['fields']['lead'][$fieldName]; } elseif (isset($options['fields']['company'][$fieldName])) { $field = $options['fields']['company'][$fieldName]; } $customOptions = []; switch ($fieldType) { case 'leadlist': if (!isset($data['filter'])) { $data['filter'] = []; } elseif (!is_array($data['filter'])) { $data['filter'] = [$data['filter']]; } // Don't show the current list ID in the choices if (!empty($currentListId)) { unset($options['lists'][$currentListId]); } $customOptions['choices'] = $options['lists']; $customOptions['multiple'] = true; $type = 'choice'; break; case 'lead_email_received': if (!isset($data['filter'])) { $data['filter'] = []; } elseif (!is_array($data['filter'])) { $data['filter'] = [$data['filter']]; } $customOptions['choices'] = $options['emails']; $customOptions['multiple'] = true; $type = 'choice'; break; case 'tags': if (!isset($data['filter'])) { $data['filter'] = []; } elseif (!is_array($data['filter'])) { $data['filter'] = [$data['filter']]; } $customOptions['choices'] = $options['tags']; $customOptions['multiple'] = true; $attr = array_merge($attr, ['data-placeholder' => $translator->trans('mautic.lead.tags.select_or_create'), 'data-no-results-text' => $translator->trans('mautic.lead.tags.enter_to_create'), 'data-allow-add' => 'true', 'onchange' => 'Mautic.createLeadTag(this)']); $type = 'choice'; break; case 'stage': $customOptions['choices'] = $options['stage']; $type = 'choice'; break; case 'timezone': case 'country': case 'region': case 'locale': switch ($fieldType) { case 'timezone': $choiceKey = 'timezones'; break; case 'country': $choiceKey = 'countries'; break; case 'region': $choiceKey = 'regions'; break; case 'locale': $choiceKey = 'locales'; break; } $type = 'choice'; $customOptions['choices'] = $options[$choiceKey]; $customOptions['multiple'] = in_array($data['operator'], ['in', '!in']); if ($customOptions['multiple']) { array_unshift($customOptions['choices'], ['' => '']); if (!isset($data['filter'])) { $data['filter'] = []; } } break; case 'time': case 'date': case 'datetime': $attr['data-toggle'] = $fieldType; break; case 'lookup_id': $type = 'hidden'; $displayType = 'text'; $displayAttr = array_merge($displayAttr, ['class' => 'form-control', 'data-toggle' => 'field-lookup', 'data-target' => $data['field'], 'data-action' => 'lead:fieldList', 'placeholder' => $translator->trans('mautic.lead.list.form.filtervalue')]); if (isset($field['properties']['list'])) { $displayAttr['data-options'] = $field['properties']['list']; } break; case 'select': case 'multiselect': case 'boolean': $type = 'choice'; $attr = array_merge($attr, ['placeholder' => $translator->trans('mautic.lead.list.form.filtervalue')]); if (in_array($data['operator'], ['in', '!in'])) { $customOptions['multiple'] = true; if (!isset($data['filter'])) { $data['filter'] = []; } elseif (!is_array($data['filter'])) { $data['filter'] = [$data['filter']]; } } $list = $field['properties']['list']; $choices = FormFieldHelper::parseList($list); if ($fieldType == 'select') { // array_unshift cannot be used because numeric values get lost as keys $choices = array_reverse($choices, true); $choices[''] = ''; $choices = array_reverse($choices, true); } $customOptions['choices'] = $choices; break; case 'lookup': default: $attr = array_merge($attr, ['data-toggle' => 'field-lookup', 'data-target' => $data['field'], 'data-action' => 'lead:fieldList', 'placeholder' => $translator->trans('mautic.lead.list.form.filtervalue')]); if (isset($field['properties']['list'])) { $attr['data-options'] = $field['properties']['list']; } break; } if (in_array($data['operator'], ['empty', '!empty'])) { $attr['disabled'] = 'disabled'; } else { $customOptions['constraints'] = [new NotBlank(['message' => 'mautic.core.value.required'])]; } // @todo implement in UI if (in_array($data['operator'], ['between', '!between'])) { $form->add('filter', 'collection', ['type' => $type, 'options' => ['label' => false, 'attr' => $attr], 'label' => false]); } else { $form->add('filter', $type, array_merge(['label' => false, 'attr' => $attr, 'data' => isset($data['filter']) ? $data['filter'] : '', 'error_bubbling' => false], $customOptions)); } $form->add('display', $displayType, ['label' => false, 'attr' => $displayAttr, 'data' => $data['display'], 'error_bubbling' => false]); $choices = $operatorChoices; if (isset($field['operators']['include'])) { // Inclusive operators $choices = array_intersect_key($choices, array_flip($field['operators']['include'])); } elseif (isset($field['operators']['exclude'])) { // Inclusive operators $choices = array_diff_key($choices, array_flip($field['operators']['exclude'])); } $form->add('operator', 'choice', ['label' => false, 'choices' => $choices, 'attr' => ['class' => 'form-control not-chosen', 'onchange' => 'Mautic.convertLeadFilterInput(this)']]); if ($eventName == FormEvents::PRE_SUBMIT) { $event->setData($data); } }; $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); }); $builder->add('field', 'hidden'); $builder->add('object', 'hidden'); $builder->add('type', 'hidden'); }
/** * @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); }
break; case 'boolean' == $leadFieldType: $parseList = [0 => $contactFields[$field['leadField']]['properties']['no'], 1 => $contactFields[$field['leadField']]['properties']['yes']]; $ignoreNumericalKeys = true; break; case 'country' == $leadFieldType: $list = \Mautic\LeadBundle\Helper\FormFieldHelper::getCountryChoices(); break; case 'region' == $leadFieldType: $list = \Mautic\LeadBundle\Helper\FormFieldHelper::getRegionChoices(); break; case 'timezone' == $leadFieldType: $list = \Mautic\LeadBundle\Helper\FormFieldHelper::getTimezonesChoices(); break; case 'locale': $list = \Mautic\LeadBundle\Helper\FormFieldHelper::getLocaleChoices(); break; } } if (empty($parseList)) { if (isset($list)) { $parseList = $list; } elseif (!empty($properties['list'])) { $parseList = $properties['list']; } elseif (!empty($properties['optionlist'])) { $parseList = $properties['optionlist']; } if (isset($parseList['list'])) { $parseList = $parseList['list']; } }
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; } } }
<?php /** * @copyright 2014 Mautic Contributors. All rights reserved * @author Mautic * * @link http://mautic.org * * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html */ echo $view->render('MauticFormBundle:Field:select.html.php', ['field' => $field, 'inForm' => isset($inForm) ? $inForm : false, 'list' => \Mautic\LeadBundle\Helper\FormFieldHelper::getCountryChoices(), 'id' => $id, 'formId' => isset($formId) ? $formId : 0, 'formName' => isset($formName) ? $formName : '']);
/** * @param $entity * @param properties * @return bool */ public function setFieldProperties(&$entity, $properties) { if (!$entity instanceof LeadField) { throw new MethodNotAllowedHttpException(array('LeadEntity')); } if (!empty($properties) && is_array($properties)) { $properties = InputHelper::clean($properties); } else { $properties = array(); } //validate properties $type = $entity->getType(); $result = FormFieldHelper::validateProperties($type, $properties); if ($result[0]) { $entity->setProperties($properties); return true; } else { return $result[1]; } }
/** * @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"]); } }