Skip to content
Snippets Groups Projects
Commit 82d8807d authored by Eirik Morland's avatar Eirik Morland
Browse files

Issue #3425417 by eiriksm: Make it possible to get and set the slack webhook for the team

parent 94282b2b
No related branches found
No related tags found
1 merge request!34Make it possible and add some tests
Pipeline #110465 passed with warnings
......@@ -379,4 +379,25 @@ class TeamNode extends Node {
return in_array($user_id, $this->getMemberIds()) || in_array($user_id, $this->getAdministratorIds());
}
/**
* Getter for the slack webhook.
*/
public function getTeamSlackWebhook() {
if (!$this->hasField('field_slack_webhook') || $this->get('field_slack_webhook')->isEmpty()) {
return FALSE;
}
return $this->get('field_slack_webhook')->first()->getString();
}
/**
* Setter for the slack webhook.
*/
public function setTeamSlackWebhook($webhook) : self {
if (!$this->hasField('field_slack_webhook')) {
return $this;
}
$this->set('field_slack_webhook', $webhook);
return $this;
}
}
......@@ -241,6 +241,22 @@ abstract class KernelTestBase extends CoreKernelTestBase {
'required' => FALSE,
]);
$field->save();
// Slack webhook.
$fieldStorage = FieldStorageConfig::create([
'field_name' => 'field_slack_webhook',
'entity_type' => 'node',
'type' => 'string',
'cardinality' => 1,
]);
$fieldStorage->save();
$field = FieldConfig::create([
'field_storage' => $fieldStorage,
'bundle' => $this->nodeType->id(),
'field_type' => 'string',
'required' => FALSE,
]);
$field->save();
$this->installSchema('user', ['users_data']);
}
......
......@@ -141,6 +141,21 @@ class TeamNodeTest extends KernelTestBase {
self::assertEquals($expexted, $node->isNotificationsEnabledForSlack());
}
/**
* Test for the method to set and get the slack webhook.
*/
public function testGetSlackWebhook() {
/** @var \Drupal\violinist_teams\TeamNode $node */
$node = Node::create([
'type' => $this->nodeType->id(),
]);
$node->set('field_slack_webhook', 'https://example.com/slack_hook');
self::assertEquals('https://example.com/slack_hook', $node->getTeamSlackWebhook());
// Should actually also be possible to use a setter method.
$node->setTeamSlackWebhook('https://example.com/slack_hook2');
self::assertEquals('https://example.com/slack_hook2', $node->getTeamSlackWebhook());
}
/**
* Test migrating billing emails.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment