Skip to content

Commit

Permalink
Also make name in emailadresses configurable (#54)
Browse files Browse the repository at this point in the history
* Also make name in emailadresses configurable

* Style corrections

* Correct docblock
  • Loading branch information
reyostallenberg authored and alexander-schranz committed Apr 1, 2017
1 parent 202fb2a commit 63e4d48
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 15 deletions.
16 changes: 16 additions & 0 deletions DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ public function process(ContainerBuilder $container)
$webspaceConfig[Configuration::ROLE] = ucfirst($webspaceKey) . 'User';
}

if (isset($webspaceConfig[Configuration::EMAIL_FROM])) {
$webspaceConfig[Configuration::EMAIL_FROM] = [
$webspaceConfig[Configuration::EMAIL_FROM][Configuration::EMAIL_FROM_EMAIL] => $webspaceConfig[Configuration::EMAIL_FROM][Configuration::EMAIL_FROM_NAME],
];
} else {
$webspaceConfig[Configuration::EMAIL_FROM] = null;
}

if (isset($webspaceConfig[Configuration::EMAIL_TO])) {
$webspaceConfig[Configuration::EMAIL_TO] = [
$webspaceConfig[Configuration::EMAIL_TO][Configuration::EMAIL_TO_EMAIL] => $webspaceConfig[Configuration::EMAIL_TO][Configuration::EMAIL_TO_NAME],
];
} else {
$webspaceConfig[Configuration::EMAIL_TO] = null;
}

$webspaceConfig[Configuration::WEBSPACE_KEY] = $webspaceKey;

$definition = new DefinitionDecorator('sulu_community.community_manager');
Expand Down
36 changes: 34 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class Configuration implements ConfigurationInterface

// Basic Webspace configuration
const EMAIL_FROM = 'from';
const EMAIL_FROM_NAME = 'name';
const EMAIL_FROM_EMAIL = 'email';
const EMAIL_TO = 'to';
const EMAIL_TO_NAME = 'name';
const EMAIL_TO_EMAIL = 'email';
const ROLE = 'role';
const WEBSPACE_KEY = 'webspace_key';
const FIREWALL = 'firewall';
Expand Down Expand Up @@ -93,8 +97,36 @@ public function getConfigTreeBuilder()
->prototype('array')
->children()
// Basic Webspace Configuration
->scalarNode(self::EMAIL_FROM)->defaultValue(null)->end()
->scalarNode(self::EMAIL_TO)->defaultValue(null)->end()
->arrayNode(self::EMAIL_FROM)
->children()
->scalarNode(self::EMAIL_FROM_NAME)->defaultValue(null)->end()
->scalarNode(self::EMAIL_FROM_EMAIL)->defaultValue(null)->end()
->end()
->beforeNormalization()
->ifString()
->then(function($value) {
return [
self::EMAIL_FROM_NAME => $value,
self::EMAIL_FROM_EMAIL => $value,
];
})
->end()
->end()
->arrayNode(self::EMAIL_TO)
->children()
->scalarNode(self::EMAIL_TO_NAME)->defaultValue(null)->end()
->scalarNode(self::EMAIL_TO_EMAIL)->defaultValue(null)->end()
->end()
->beforeNormalization()
->ifString()
->then(function($value) {
return [
self::EMAIL_TO_NAME => $value,
self::EMAIL_TO_EMAIL => $value,
];
})
->end()
->end()
->scalarNode(self::ROLE)->defaultValue(null)->end()
->scalarNode(self::FIREWALL)->defaultValue(null)->end()
// Login
Expand Down
16 changes: 8 additions & 8 deletions Mail/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Mail
/**
* Get mail settings for specific type.
*
* @param string $from
* @param string $to
* @param string|array $from
* @param string|array $to
* @param array $config
*
* @return Mail
Expand All @@ -39,12 +39,12 @@ public static function create($from, $to, $config)
}

/**
* @var string
* @var string|array
*/
private $from;

/**
* @var string
* @var string|array
*/
private $to;

Expand All @@ -69,8 +69,8 @@ public static function create($from, $to, $config)
private $adminTemplate;

/**
* @param string $from
* @param string $to
* @param string|array $from
* @param string|array $to
* @param string $subject
* @param null|string $userTemplate
* @param null|string $adminTemplate
Expand All @@ -87,7 +87,7 @@ public function __construct($from, $to, $subject, $userTemplate = null, $adminTe
/**
* Returns from.
*
* @return string
* @return string|array
*/
public function getFrom()
{
Expand All @@ -97,7 +97,7 @@ public function getFrom()
/**
* Returns to.
*
* @return string
* @return string|array
*/
public function getTo()
{
Expand Down
4 changes: 3 additions & 1 deletion Resources/doc/2-setup-webspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ Enable community features for your webspace:
sulu_community:
webspaces:
<webspace_key>:
from: %from_email%
from:
name: 'Website'
email: %from_email%
```
## Enable Security
Expand Down
8 changes: 6 additions & 2 deletions Resources/doc/3-customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ sulu_community:
refresh_interval: 600
webspaces:
<webspace_key>:
from: %sulu_admin.email%
to: %sulu_admin.email%
from:
name: 'Website'
email: %sulu_admin.email%
to:
name: 'Admin'
email: %sulu_admin.email%
role: CustomRoleName
firewall: CustomFirewallName

Expand Down
4 changes: 2 additions & 2 deletions Tests/Unit/Listener/BlacklistListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public function testValidateEmail()

$event = $this->prophesize(CommunityEvent::class);
$event->getConfigProperty(Configuration::WEBSPACE_KEY)->willReturn('sulu_io');
$event->getConfigProperty(Configuration::EMAIL_TO)->willReturn('[email protected]');
$event->getConfigProperty(Configuration::EMAIL_FROM)->willReturn('[email protected]');
$event->getConfigProperty(Configuration::EMAIL_TO)->willReturn(['[email protected]' => '[email protected]']);
$event->getConfigProperty(Configuration::EMAIL_FROM)->willReturn(['[email protected]' => '[email protected]']);
$event->getConfigTypeProperty(Configuration::TYPE_BLACKLISTED, Configuration::EMAIL)->willReturn(
[
Configuration::EMAIL_SUBJECT => 'subject',
Expand Down

0 comments on commit 63e4d48

Please sign in to comment.