Commit f0d5d80e authored by RoSk0's avatar RoSk0

Issue #2721775 by RoSk0: Remove redundant base field from Individual

parent 5ee7e7e3
......@@ -3,12 +3,10 @@
namespace Drupal\crm_core_contact\Entity;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\crm_core\EntityOwnerTrait;
use Drupal\crm_core_contact\IndividualInterface;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\entity\Revision\RevisionableContentEntityBase;
/**
......@@ -108,108 +106,9 @@ class Individual extends RevisionableContentEntityBase implements IndividualInte
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['sex'] = BaseFieldDefinition::create('list_string')
->setLabel(t('Sex'))
->setDescription(t('Sex of the individual.'))
->setSetting('allowed_values', [
'unknown' => t('Unknown'),
'female' => t('Female'),
'male' => t('Male'),
'other' => t('Other'),
])
->setDefaultValue('unknown')
->setDisplayOptions('form', [
'type' => 'options_select',
'weight' => 1,
]);
$fields['birth_date'] = BaseFieldDefinition::create('datetime')
->setLabel(t('Birth date'))
->setDescription(t('Birth date of the individual.'))
->setRevisionable(TRUE)
->setSetting('datetime_type', ['datetime_type' => 'date'])
->setDisplayOptions('form', [
'type' => 'datetime_datelist',
'weight' => 2,
]);
$fields['email'] = BaseFieldDefinition::create('email_with_type')
->setLabel(t('Email'))
->setDescription(t('Email of the individual.'))
->setRevisionable(TRUE)
->setCardinality(FieldStorageConfigInterface::CARDINALITY_UNLIMITED)
->setSetting('email_types', [
'private' => t('Private'),
'corporate' => t('Corporate'),
])
->setDisplayOptions('form', [
'type' => 'email_with_type',
'weight' => 3,
]);
return $fields;
}
/**
* {@inheritdoc}
*/
public function setMainEmail(array $email) {
$this->get('email')->set(0, $email);
return $this;
}
/**
* {@inheritdoc}
*/
public function getMainEmail() {
return $this->get('email')->first()->getValue();
}
/**
* {@inheritdoc}
*/
public function addEmail(array $email) {
$this->get('email')->appendItem($email);
return $this;
}
/**
* {@inheritdoc}
*/
public function getEmailList() {
return $this->get('email')->getValue();
}
/**
* {@inheritdoc}
*/
public function setBirthDate($birth_date) {
$this->set('birth_date', $birth_date);
return $this;
}
/**
* {@inheritdoc}
*/
public function getBirthDate() {
return $this->get('birth_date')->value;
}
/**
* {@inheritdoc}
*/
public function setSex($sex) {
$this->set('sex', $sex);
return $this;
}
/**
* {@inheritdoc}
*/
public function getSex() {
return $this->get('sex')->value;
}
/**
* Gets the primary address.
*
......
......@@ -7,68 +7,4 @@ namespace Drupal\crm_core_contact;
*/
interface IndividualInterface extends ContactInterface {
/**
* Sets main email of individual.
*
* @param array $email
* Main email.
*/
public function setMainEmail(array $email);
/**
* Gets main email of individual.
*
* @return array
* Main email of individual.
*/
public function getMainEmail();
/**
* Sets email to email list.
*
* @param array $email
* Email to add to list.
*/
public function addEmail(array $email);
/**
* Gets email list for individual.
*
* @return array
* Email list.
*/
public function getEmailList();
/**
* Sets birth date of individual.
*
* @param int $birth_date
* Birth date field.
*/
public function setBirthDate($birth_date);
/**
* Gets birth date of individual.
*
* @return int
* Birth date of individual.
*/
public function getBirthDate();
/**
* Sets sex field of individual.
*
* @param string $sex
* Sex field.
*/
public function setSex($sex);
/**
* Gets sex of individual.
*
* @return string
* Sex of individual.
*/
public function getSex();
}
......@@ -118,12 +118,6 @@ class IndividualUiTest extends WebTestBase {
'name[0][family]' => 'Smith',
'name[0][generational]' => 'IV',
'name[0][credentials]' => '',
'sex' => 'male',
'email[type]' => 'private',
'email[value]' => 'john.smith@admin.com',
'birth_date[0][value][year]' => 2000,
'birth_date[0][value][month]' => 1,
'birth_date[0][value][day]' => 2,
];
$this->drupalPostForm('crm-core/individual/add/customer', $customer_node, 'Save Customer');
......@@ -159,33 +153,10 @@ class IndividualUiTest extends WebTestBase {
$this->assertText($this->container->get('date.formatter')->format($individual->get('changed')->value, 'medium'), 'Individual updated date is available.');
$this->drupalGet('crm-core/individual/1/edit');
$this->assertText('Sex');
$this->assertText('Birth date');
$this->assertText('Email');
$this->assertRaw('john.smith@admin.com', t('Email of individual found.'));
$this->assertOptionSelected('edit-email-type', 'private', t('Email type of individual selected.'));
$this->assertOptionSelected('edit-sex', 'male', t('Sex for individual selected.'));
$this->assertOptionSelected('edit-birth-date-0-value-year', '2000', t('Year of birth date for individual selected.'));
$this->assertOptionSelected('edit-birth-date-0-value-month', '1', t('Month of birth date for individual selected.'));
$this->assertOptionSelected('edit-birth-date-0-value-day', '2', t('Day of birth date for individual selected.'));
$this->assertRaw('crm-core/individual/1/delete" class="button button--danger" data-drupal-selector="edit-delete" id="edit-delete"', 'Delete link is available.');
$this->assertRaw('nav class="tabs" role="navigation" aria-label="Tabs"');
$individual->setSex('unknown');
$individual->addEmail(['value' => 'unk@admin.com', 'type' => 'private']);
$individual->addEmail(['value' => 'unk@administrator.com', 'type' => 'private']);
$individual->setMainEmail(['value' => 'unknown@admin.com', 'type' => 'corporate']);
$individual->setBirthDate('2011-02-07');
$individual->save();
$unchanged = \Drupal::entityTypeManager()->getStorage('crm_core_individual')->loadUnchanged($individual->id());
$this->assertEqual($unchanged->getSex(), 'unknown');
$this->assertEqual($unchanged->getMainEmail()['value'], 'unknown@admin.com');
$this->assertEqual($unchanged->getMainEmail()['type'], 'corporate');
$this->assertEqual($unchanged->getEmailList()[1]['value'], 'unk@admin.com');
$this->assertEqual($unchanged->getEmailList()[1]['type'], 'private');
$this->assertEqual($unchanged->getEmailList()[2]['value'], 'unk@administrator.com');
$this->assertEqual($unchanged->getEmailList()[2]['type'], 'private');
$this->assertEqual($unchanged->getBirthDate(), '2011-02-07');
// Get test view data page.
$this->drupalGet('individual-view-data');
......
......@@ -178,15 +178,11 @@ class IndividualCRUDTest extends KernelTestBase {
$individual_customer_1 = Individual::create([
'type' => 'customer',
'name' => ['given' => 'John', 'family' => 'Smith'],
'email_value' => 'test1@example.com',
'email_type' => 'private',
]);
$individual_customer_1->save();
$individual_customer_2 = Individual::create([
'type' => 'customer',
'name' => ['given' => 'Mark', 'family' => 'Jones'],
'email_value' => 'test2@example.com',
'email_type' => 'private',
]);
$individual_customer_2->save();
$individual_customer_3 = Individual::create([
......@@ -201,12 +197,6 @@ class IndividualCRUDTest extends KernelTestBase {
]);
$organization->save();
// Add primary email to individual type.
$individual_type_id = $individual_customer_1->type->target_id;
$individual_type = IndividualType::load($individual_type_id);
$individual_type->primary_fields['email'] = $individual_customer_1->get('email')->getName();
$individual_type->save();
// Create crm_member relation type.
$relation_type = RelationType::create([
'id' => 'crm_member',
......@@ -223,15 +213,6 @@ class IndividualCRUDTest extends KernelTestBase {
]);
$meeting_activity->save();
// Test send_email_action.
$send_email_action_plugin = $this->pluginManager->createInstance('send_email_action', ['subject' => 'Testing subject', 'message' => 'Testing message']);
$send_email_action_plugin->executeMultiple([$individual_customer_1, $individual_customer_2]);
// Get all emails sent during this test and test it's values.
$captured_emails = $this->container->get('state')->get('system.test_mail_collector', []);
$this->assertEquals($captured_emails[0]['to'], $individual_customer_1->email->value);
$this->assertEquals($captured_emails[1]['to'], $individual_customer_2->email->value);
// Test join_into_household_action.
// @todo there is no more household bundle after we rename contact to individual.
//$join_into_household_action_plugin = $this->pluginManager->createInstance('join_into_household_action', ['household' => $household_contact]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment