Skip to content

Commit

Permalink
Added additional receivers for sending notification as CC or BCC (sul…
Browse files Browse the repository at this point in the history
…u#20)

 * Added additional receivers for sending notification as CC or BCC (sulu#20)
  • Loading branch information
rs2487 authored and alexander-schranz committed Jan 30, 2017
1 parent 7b0626e commit 1f5c34e
Show file tree
Hide file tree
Showing 29 changed files with 919 additions and 160 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

## dev-develop

- FEATURE #20 Added additional receivers for sending notification as CC or BCC
- ENHANCEMENT #23 Fixed composer json links and description
- BUGFIX #16 Fixed setting of entity value in dynamic which represents an array
- ENHANCEMENT #13 Added dynamic type pool service for enabling custom form field types
Expand Down
16 changes: 10 additions & 6 deletions Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Routing\ClassResourceInterface;
use Sulu\Bundle\FormBundle\Dynamic\FormFieldTypeInterface;
use Sulu\Bundle\FormBundle\Entity\Dynamic;
use Sulu\Bundle\FormBundle\Entity\Form;
use Sulu\Bundle\FormBundle\Mail\HelperInterface;
use Sulu\Bundle\FormBundle\Manager\FormManager;
use Sulu\Component\Rest\ListBuilder\Doctrine\DoctrineListBuilderFactory;
use Sulu\Component\Rest\ListBuilder\Doctrine\FieldDescriptor\DoctrineCaseFieldDescriptor;
Expand Down Expand Up @@ -189,16 +189,18 @@ public function cgetTemplateAction(Request $request)
];

$types = $this->get('sulu_form.dynamic.form_field_type_pool')->all();

if (class_exists(\EWZ\Bundle\RecaptchaBundle\Form\Type\RecaptchaType::class)) {
$types[] = Dynamic::TYPE_RECAPTCHA;
}
$receiverTypes = [
'to' => HelperInterface::MAIL_RECEIVER_TO,
'cc' => HelperInterface::MAIL_RECEIVER_CC,
'bcc' => HelperInterface::MAIL_RECEIVER_BCC,
];

return $this->render(
$this->getBundleName() . ':' . $this->getListName() . ':template.html.twig',
[
'types' => $this->getSortedTypes($types),
'widths' => $widths,
'receiverTypes' => $receiverTypes,
]
);
}
Expand All @@ -212,13 +214,14 @@ public function getSortedTypes($types = [])
{
/** @var Translator $translator */
$translator = $this->get('translator');
$locale = $this->getUser()->getLocale();

$sortedTypes = [];
$returnTypes = [];

$i = 0;
foreach ($types as $alias => $type) {
$translation = $translator->trans($type->getConfiguration()->getTitle(), [], 'backend');
$translation = $translator->trans($type->getConfiguration()->getTitle(), [], 'backend', $locale);
$sortedTypes[$translation . $i] = ['alias' => $alias, 'type' => $type];
++$i;
}
Expand Down Expand Up @@ -515,6 +518,7 @@ private function getApiEntity(Form $entity, $locale)
'sendAttachments' => $translation->getSendAttachments(),
'deactivateNotifyMails' => $translation->getDeactivateNotifyMails(),
'deactivateCustomerMails' => $translation->getDeactivateCustomerMails(),
'receivers' => $translation->getReceivers(),
];
}

Expand Down
13 changes: 12 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,21 @@ public function getConfigTreeBuilder()

$rootNode->children()
->scalarNode('mailchimp_api_key')->defaultValue(null)->end()
->arrayNode('mail_helper')
->arrayNode('mail')
->children()
->scalarNode('from')->end()
->scalarNode('to')->end()
->arrayNode('templates')
->addDefaultsIfNotSet()
->children()
->scalarNode('notify')
->defaultValue('SuluFormBundle:mails:notify.html.twig')
->end()
->scalarNode('customer')
->defaultValue('SuluFormBundle:mails:customer.html.twig')
->end()
->end()
->end()
->end()
->end()
->arrayNode('ajax_templates')
Expand Down
6 changes: 4 additions & 2 deletions DependencyInjection/SuluFormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$container->setParameter('sulu_form.mail.from', $config['mail_helper']['from']);
$container->setParameter('sulu_form.mail.to', $config['mail_helper']['to']);
$container->setParameter('sulu_form.mail.from', $config['mail']['from']);
$container->setParameter('sulu_form.mail.to', $config['mail']['to']);
$container->setParameter('sulu_form.mail.template.notify', $config['mail']['templates']['notify']);
$container->setParameter('sulu_form.mail.template.customer', $config['mail']['templates']['customer']);
$container->setParameter('sulu_form.ajax_templates', $config['ajax_templates']);

$container->setParameter('sulu_form.mailchimp_api_key', $config['mailchimp_api_key']);
Expand Down
12 changes: 12 additions & 0 deletions Entity/Dynamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,18 @@ public function __isset($name)
* {@inheritdoc}
*/
public function __get($name)
{
return $this->getField($name);
}

/**
* Returns the fields value identified by its name.
*
* @param string $name
*
* @return mixed
*/
public function getField($name)
{
if (property_exists($this, $name)) {
if (in_array($name, self::$arrayTypes)) {
Expand Down
25 changes: 25 additions & 0 deletions Entity/FormTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ class FormTranslation implements AuditableInterface
*/
private $changed;

/**
* @var FormTranslationReceiver[]
*/
private $receivers;

/**
* @param string $title
*
Expand Down Expand Up @@ -452,4 +457,24 @@ public function setChanged($changed)

return $this;
}

/**
* Returns receivers.
*
* @return FormTranslationReceiver[]
*/
public function getReceivers()
{
return $this->receivers;
}

/**
* Sets receivers.
*
* @param FormTranslationReceiver[] $receivers
*/
public function setReceivers($receivers)
{
$this->receivers = $receivers;
}
}
151 changes: 151 additions & 0 deletions Entity/FormTranslationReceiver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php

namespace Sulu\Bundle\FormBundle\Entity;

class FormTranslationReceiver
{
/**
* @var int
*/
private $id;

/**
* @var string
*/
private $type;

/**
* @var string
*/
private $email;

/**
* @var string
*/
private $name;

/**
* @var FormTranslation
*/
private $formTranslation;

/**
* Returns id.
*
* @return int
*/
public function getId()
{
return $this->id;
}

/**
* Sets id.
*
* @param int $id
*
* @return FormTranslationReceiver
*/
public function setId($id)
{
$this->id = $id;

return $this;
}

/**
* Returns type.
*
* @return string
*/
public function getType()
{
return $this->type;
}

/**
* Sets type.
*
* @param string $type
*
* @return FormTranslationReceiver
*/
public function setType($type)
{
$this->type = $type;

return $this;
}

/**
* Returns email.
*
* @return string
*/
public function getEmail()
{
return $this->email;
}

/**
* Sets email.
*
* @param string $email
*
* @return FormTranslationReceiver
*/
public function setEmail($email)
{
$this->email = $email;

return $this;
}

/**
* Returns name.
*
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* Sets name.
*
* @param string $name
*
* @return FormTranslationReceiver
*/
public function setName($name)
{
$this->name = $name;

return $this;
}

/**
* Returns formTranslation.
*
* @return FormTranslation
*/
public function getFormTranslation()
{
return $this->formTranslation;
}

/**
* Sets formTranslation.
*
* @param FormTranslation $formTranslation
*
* @return FormTranslationReceiver
*/
public function setFormTranslation($formTranslation)
{
$this->formTranslation = $formTranslation;

return $this;
}
}
6 changes: 3 additions & 3 deletions Event/DynFormSavedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DynFormSavedEvent extends Event
* DynFormSavedEvent constructor.
*
* @param array $data
* @param Dynamic $dynamic will be required in the future
* @param Dynamic $dynamic
*/
public function __construct($data, $dynamic = null)
{
Expand All @@ -44,7 +44,7 @@ public function getFormSelect()
}

/**
* Get data.
* Returns data.
*
* @return array
*/
Expand All @@ -54,7 +54,7 @@ public function getData()
}

/**
* Get dynamic.
* Returns dynamic.
*
* @return Dynamic|null
*/
Expand Down
Loading

0 comments on commit 1f5c34e

Please sign in to comment.