WorkbenchEmailTestTrait.php in Workbench Email 8
File
tests/src/Traits/WorkbenchEmailTestTrait.php
View source
<?php
namespace Drupal\Tests\workbench_email\Traits;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\NodeTypeInterface;
use Drupal\workbench_moderation\Entity\ModerationState;
trait WorkbenchEmailTestTrait {
protected function setUpModerationForNodeType(NodeTypeInterface $node_type) {
$node_type
->setThirdPartySetting('workbench_moderation', 'enabled', TRUE);
$states = array_keys(ModerationState::loadMultiple());
$node_type
->setThirdPartySetting('workbench_moderation', 'allowed_moderation_states', $states);
$node_type
->setThirdPartySetting('workbench_moderation', 'default_moderation_state', 'draft');
$node_type
->save();
}
protected function setUpEmailFieldForNodeBundle($bundle = 'test') {
FieldStorageConfig::create([
'cardinality' => 1,
'entity_type' => 'node',
'field_name' => 'field_email',
'type' => 'email',
])
->save();
FieldConfig::create([
'field_name' => 'field_email',
'bundle' => 'test',
'label' => 'Notify',
'entity_type' => 'node',
])
->save();
if (!($entity_form_display = EntityFormDisplay::load(sprintf('node.%s.default', $bundle)))) {
$entity_form_display = EntityFormDisplay::create([
'targetEntityType' => 'node',
'bundle' => $bundle,
'mode' => 'default',
'status' => TRUE,
]);
}
$entity_form_display
->setComponent('field_email', [
'type' => 'email_default',
])
->save();
}
}