-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from lenonleite/feature/first-version
first version purge contact field
- Loading branch information
Showing
22 changed files
with
614 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
vendor | ||
composer.lock | ||
.idea | ||
.php-cs-fixer.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->name('*.php') | ||
->in(__DIR__) | ||
->exclude('vendor'); | ||
|
||
return (new PhpCsFixer\Config()) | ||
->setRules([ | ||
'@Symfony' => true, | ||
'binary_operator_spaces' => [ | ||
'operators' => [ | ||
'=>' => 'align', | ||
'=' => 'align', | ||
], | ||
], | ||
'phpdoc_to_comment' => false, | ||
'ordered_imports' => true, | ||
'array_syntax' => [ | ||
'syntax' => 'short', | ||
], | ||
'no_unused_imports' => true, | ||
/** | ||
* Our templates rely heavily on things like endforeach, endif, etc. | ||
* This setting should be turned off at least until we've switched to Twig | ||
* (which is required for Symfony 5). | ||
*/ | ||
'no_alternative_syntax' => false, | ||
]) | ||
->setFinder($finder); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
return [ | ||
'name' => 'Purge Contact Fields by Leuchtfeuer', | ||
'description' => 'Adds Mautic campaign action to purge a contact field', | ||
'version' => '1.0.0', | ||
'author' => 'Leuchtfeuer Digital Marketing GmbH', | ||
'services' => [ | ||
'integrations' => [ | ||
'mautic.integration.actionpurgecontactfield' => [ | ||
'class' => \MauticPlugin\LeuchtfeuerPurgeContactFieldBundle\Integration\ActionPurgeContactFieldIntegration::class, | ||
'tags' => [ | ||
'mautic.integration', | ||
'mautic.basic_integration', | ||
], | ||
], | ||
'actionpurgecontactfield.integration.configuration' => [ | ||
'class' => \MauticPlugin\LeuchtfeuerPurgeContactFieldBundle\Integration\Support\ConfigSupport::class, | ||
'tags' => [ | ||
'mautic.config_integration', | ||
], | ||
], | ||
], | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Mautic\CoreBundle\DependencyInjection\MauticCoreExtension; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return function (ContainerConfigurator $configurator): void { | ||
$services = $configurator->services() | ||
->defaults() | ||
->autowire() | ||
->autoconfigure() | ||
->public(); | ||
|
||
$excludes = [ | ||
]; | ||
|
||
$services->load('MauticPlugin\\LeuchtfeuerPurgeContactFieldBundle\\', '../') | ||
->exclude('../{'.implode(',', array_merge(MauticCoreExtension::DEFAULT_EXCLUDES, $excludes)).'}'); | ||
}; |
17 changes: 17 additions & 0 deletions
17
DependencyInjection/LeuchtfeuerPurgeContactFieldExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace MauticPlugin\LeuchtfeuerPurgeContactFieldBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\Extension; | ||
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; | ||
|
||
class LeuchtfeuerPurgeContactFieldExtension extends Extension | ||
{ | ||
public function load(array $configs, ContainerBuilder $container): void | ||
{ | ||
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Config')); | ||
$loader->load('services.php'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace MauticPlugin\LeuchtfeuerPurgeContactFieldBundle\EventListener; | ||
|
||
use Mautic\CampaignBundle\CampaignEvents; | ||
use Mautic\CampaignBundle\Event\CampaignBuilderEvent; | ||
use Mautic\CampaignBundle\Event\CampaignExecutionEvent; | ||
use Mautic\LeadBundle\Model\LeadModel; | ||
use MauticPlugin\LeuchtfeuerPurgeContactFieldBundle\Form\Type\PurgeContactFieldType; | ||
use MauticPlugin\LeuchtfeuerPurgeContactFieldBundle\LeuchtfeuerPurgeContactFieldEvents; | ||
use MauticPlugin\LeuchtfeuerPurgeContactFieldBundle\Model\LfFieldModel; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
class PurgeContactFieldsSubscriber implements EventSubscriberInterface | ||
{ | ||
public function __construct( | ||
private LeadModel $leadModel, | ||
private LfFieldModel $lfFieldModel | ||
) { | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
CampaignEvents::CAMPAIGN_ON_BUILD => ['addAction', 0], | ||
LeuchtfeuerPurgeContactFieldEvents::ON_PURGE_CONTACT_FIELD => ['purgeContactField', 0], | ||
]; | ||
} | ||
|
||
public function addAction(CampaignBuilderEvent $event) | ||
{ | ||
$event->addAction( | ||
'campaign.purgecontactfields', | ||
[ | ||
'label' => 'lf.campaign.action.purgecontactfield.title', | ||
'description' => 'lf.campaign.action.purgecontactfield.description', | ||
'formType' => PurgeContactFieldType::class, | ||
'eventName' => LeuchtfeuerPurgeContactFieldEvents::ON_PURGE_CONTACT_FIELD, | ||
] | ||
); | ||
} | ||
|
||
public function purgeContactField(CampaignExecutionEvent $event): void | ||
{ | ||
$fieldsPurged = $event->getConfig()['fields']; | ||
$purgeFieldsValues = []; | ||
foreach ($fieldsPurged as $fieldPurged) { | ||
$purgeFieldsValues[$fieldPurged] = $this->lfFieldModel->getPurgeValueByAlias($fieldPurged); | ||
} | ||
$lead = $event->getLead(); | ||
$this->leadModel->setFieldValues($lead, $purgeFieldsValues, true); | ||
$this->leadModel->saveEntity($lead); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace MauticPlugin\LeuchtfeuerPurgeContactFieldBundle\Form\Type; | ||
|
||
use Mautic\LeadBundle\Model\FieldModel; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class ContactFieldType extends AbstractType | ||
{ | ||
public function __construct( | ||
private FieldModel $fieldModel | ||
) { | ||
} | ||
|
||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$fields = $this->fieldModel->getLeadFields(); | ||
$choices = []; | ||
foreach ($fields as $field) { | ||
$key = $field->getLabel(); | ||
if (!empty($field->isUniqueIdentifer())) { | ||
$key .= '*'; | ||
} | ||
$choices[$key] = $field->getAlias(); | ||
} | ||
|
||
$resolver->setDefaults([ | ||
'choices' => $choices, | ||
'required' => false, | ||
'multiple' => true, | ||
'expanded' => false, | ||
'placeholder' => 'mautic.core.form.chooseone', | ||
'label' => 'lf.campaign.action.purgecontactfield.type.title', | ||
]); | ||
} | ||
|
||
public function getParent() | ||
{ | ||
return ChoiceType::class; | ||
} | ||
|
||
public function getBlockPrefix() | ||
{ | ||
return 'fieldlist_choices'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace MauticPlugin\LeuchtfeuerPurgeContactFieldBundle\Form\Type; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
class PurgeContactFieldType extends AbstractType | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder->add('fields', ContactFieldType::class, [ | ||
'label' => 'lf.campaign.action.purgecontactfield.type.title', | ||
'label_attr' => ['class' => 'control-label'], | ||
'attr' => [ | ||
'class' => 'form-control', | ||
'tooltip' => 'lf.campaign.action.purgecontactfield.type.desc', | ||
], | ||
'multiple' => true, | ||
'expanded' => false, | ||
'required' => true, | ||
]); | ||
} | ||
|
||
public function getBlockPrefix() | ||
{ | ||
return 'purgecontactfield'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace MauticPlugin\LeuchtfeuerPurgeContactFieldBundle\Integration; | ||
|
||
use Mautic\IntegrationsBundle\Integration\BasicIntegration; | ||
use Mautic\IntegrationsBundle\Integration\ConfigurationTrait; | ||
use Mautic\IntegrationsBundle\Integration\Interfaces\BasicInterface; | ||
|
||
class ActionPurgeContactFieldIntegration extends BasicIntegration implements BasicInterface | ||
{ | ||
use ConfigurationTrait; | ||
|
||
public const INTEGRATION_NAME = 'actionpurgecontactfield'; | ||
public const DISPLAY_NAME = 'Purge Contact Field'; | ||
|
||
public function getIcon(): string | ||
{ | ||
return 'plugins/LeuchtfeuerPurgeContactFieldBundle/Assets/img/icon.png'; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return self::INTEGRATION_NAME; | ||
} | ||
|
||
public function getDisplayName(): string | ||
{ | ||
return self::DISPLAY_NAME; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MauticPlugin\LeuchtfeuerPurgeContactFieldBundle\Integration\Support; | ||
|
||
use Mautic\IntegrationsBundle\Integration\DefaultConfigFormTrait; | ||
use Mautic\IntegrationsBundle\Integration\Interfaces\ConfigFormInterface; | ||
use MauticPlugin\LeuchtfeuerPurgeContactFieldBundle\Integration\ActionPurgeContactFieldIntegration; | ||
|
||
class ConfigSupport extends ActionPurgeContactFieldIntegration implements ConfigFormInterface | ||
{ | ||
use DefaultConfigFormTrait; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace MauticPlugin\LeuchtfeuerPurgeContactFieldBundle; | ||
|
||
use Mautic\PluginBundle\Bundle\PluginBundleBase; | ||
|
||
class LeuchtfeuerPurgeContactFieldBundle extends PluginBundleBase | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace MauticPlugin\LeuchtfeuerPurgeContactFieldBundle; | ||
|
||
final class LeuchtfeuerPurgeContactFieldEvents | ||
{ | ||
public const ON_PURGE_CONTACT_FIELD = 'leuchtfeuer_action_purge_contact_field.on_purge_contact_field'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace MauticPlugin\LeuchtfeuerPurgeContactFieldBundle\Model; | ||
|
||
use Mautic\LeadBundle\Helper\FormFieldHelper; | ||
use Mautic\LeadBundle\Model\FieldModel; | ||
|
||
class LfFieldModel extends FieldModel | ||
{ | ||
public const EMPTY_TEXT = [ | ||
'text', | ||
'email', | ||
'textarea', | ||
'timezone', | ||
'country', | ||
'locale', | ||
'region', | ||
]; | ||
|
||
public const EMPTY_NUMBER = [ | ||
'number', | ||
'tel', | ||
]; | ||
|
||
public const EMPTY_LIST = [ | ||
'select', | ||
'multiselect', | ||
'lookup', | ||
]; | ||
|
||
public const EMPTY_DATE = [ | ||
'date', | ||
'datetime', | ||
]; | ||
|
||
public const EMPTY_TIME = [ | ||
'time', | ||
]; | ||
|
||
public function getPurgeValueByAlias(string $alias) | ||
{ | ||
$field = $this->getEntityByAlias($alias); | ||
if (!$field instanceof \Mautic\LeadBundle\Entity\LeadField) { | ||
new \Exception('Field not found'); | ||
} | ||
|
||
return $this->getPurgeFieldValueByType($field->getType()); | ||
} | ||
|
||
public function getPurgeFieldValueByType($type) | ||
{ | ||
return $this->getPurgeFieldValues()[$type]; | ||
} | ||
|
||
public function getPurgeFieldValues(): array | ||
{ | ||
$fieldHelper = new FormFieldHelper(); | ||
$fieldsType = array_keys($fieldHelper->getTypes()); | ||
$result = []; | ||
foreach ($fieldsType as $fieldType) { | ||
switch ($fieldType) { | ||
case in_array($fieldType, self::EMPTY_TEXT): | ||
$value = null; | ||
break; | ||
case in_array($fieldType, self::EMPTY_NUMBER): | ||
$value = 0; | ||
break; | ||
case in_array($fieldType, self::EMPTY_LIST): | ||
$value = []; | ||
break; | ||
case in_array($fieldType, self::EMPTY_DATE): | ||
// $value = new \DateTime(); | ||
$value = null; | ||
break; | ||
case in_array($fieldType, self::EMPTY_TIME): | ||
// $value = new \DateTime(); | ||
$value = null; | ||
break; | ||
case 'boolean': | ||
$value = false; | ||
break; | ||
default: | ||
$value = null; | ||
break; | ||
} | ||
$result[$fieldType] = $value; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
Oops, something went wrong.