Skip to content

Commit 8134585

Browse files
Mile23paul-m
Mile23
authored andcommitted
Issue #2898380 by vegantriathlete, Mile23, eojthebrave, socketwench: Make content entity example more gender-inclusive
1 parent a321645 commit 8134585

File tree

5 files changed

+41
-33
lines changed

5 files changed

+41
-33
lines changed

content_entity_example/content_entity_example.info.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ core: 8.x
66
# These modules are required by the tests, must be available at bootstrap time
77
dependencies:
88
- drupal:options
9+
- drupal:user
910
- examples:examples

content_entity_example/src/Entity/Contact.php

-26
Original file line numberDiff line numberDiff line change
@@ -250,32 +250,6 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
250250
->setDisplayConfigurable('form', TRUE)
251251
->setDisplayConfigurable('view', TRUE);
252252

253-
// Gender field for the contact.
254-
// ListTextType with a drop down menu widget.
255-
// The values shown in the menu are 'male' and 'female'.
256-
// In the view the field content is shown as string.
257-
// In the form the choices are presented as options list.
258-
$fields['gender'] = BaseFieldDefinition::create('list_string')
259-
->setLabel(t('Gender'))
260-
->setDescription(t('The gender of the Contact entity.'))
261-
->setSettings([
262-
'allowed_values' => [
263-
'female' => 'female',
264-
'male' => 'male',
265-
],
266-
])
267-
->setDisplayOptions('view', [
268-
'label' => 'above',
269-
'type' => 'string',
270-
'weight' => -4,
271-
])
272-
->setDisplayOptions('form', [
273-
'type' => 'options_select',
274-
'weight' => -4,
275-
])
276-
->setDisplayConfigurable('form', TRUE)
277-
->setDisplayConfigurable('view', TRUE);
278-
279253
// Owner field of the contact.
280254
// Entity reference field, holds the reference to the user object.
281255
// The view shows the user name field of the user.

content_entity_example/src/Entity/Controller/ContactListBuilder.php

-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public function buildHeader() {
7878
$header['id'] = $this->t('ContactID');
7979
$header['name'] = $this->t('Name');
8080
$header['first_name'] = $this->t('First Name');
81-
$header['gender'] = $this->t('Gender');
8281
$header['role'] = $this->t('Role');
8382
return $header + parent::buildHeader();
8483
}
@@ -91,7 +90,6 @@ public function buildRow(EntityInterface $entity) {
9190
$row['id'] = $entity->id();
9291
$row['name'] = $entity->link();
9392
$row['first_name'] = $entity->first_name->value;
94-
$row['gender'] = $entity->gender->value;
9593
$row['role'] = $entity->role->value;
9694
return $row + parent::buildRow($entity);
9795
}

content_entity_example/tests/src/Functional/ContentEntityExampleTest.php

-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public function testContentEntityExample() {
6262
$edit = [
6363
'name[0][value]' => 'test name',
6464
'first_name[0][value]' => 'test first name',
65-
'gender' => 'male',
6665
'role' => 'administrator',
6766
];
6867
$this->drupalPostForm(NULL, $edit, 'Save');
@@ -77,7 +76,6 @@ public function testContentEntityExample() {
7776
$assert->pageTextContains('test name');
7877
$assert->pageTextContains('test first name');
7978
$assert->pageTextContains('administrator');
80-
$assert->pageTextContains('male');
8179
$assert->linkExists('Add contact');
8280
$assert->linkExists('Edit');
8381
$assert->linkExists('Delete');
@@ -113,7 +111,6 @@ public function testPaths() {
113111
$contact = Contact::create([
114112
'name' => 'somename',
115113
'first_name' => 'Joe',
116-
'gender' => 'female',
117114
'role' => 'administrator',
118115
]);
119116
$contact->save();
@@ -269,7 +266,6 @@ public function testCreateAdminPermission() {
269266
$edit = [
270267
'name[0][value]' => 'Test Admin Name',
271268
'first_name[0][value]' => 'Admin First Name',
272-
'gender' => 'female',
273269
'role' => 'administrator',
274270
];
275271
$this->drupalPostForm($add_url, $edit, 'Save');
@@ -288,7 +284,6 @@ public function testCreateAdminPermission() {
288284
$edit = [
289285
'name[0][value]' => 'Mere Mortal Name',
290286
'first_name[0][value]' => 'Mortal First Name',
291-
'gender' => 'male',
292287
'role' => 'user',
293288
];
294289
$this->drupalPostForm($add_url, $edit, 'Save');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Drupal\Tests\content_entity_example\Kernel;
4+
5+
use Drupal\content_entity_example\Entity\Contact;
6+
use Drupal\KernelTests\KernelTestBase;
7+
8+
/**
9+
* Test basic CRUD operations for our Contact entity type.
10+
*
11+
* @group content_entity_example
12+
* @group examples
13+
*
14+
* @ingroup content_entity_example
15+
*/
16+
class ContactTest extends KernelTestBase {
17+
18+
protected static $modules = ['content_entity_example', 'options', 'user'];
19+
20+
/**
21+
* Basic CRUD operations on a Contact entity.
22+
*/
23+
public function testEntity() {
24+
$this->installEntitySchema('content_entity_example_contact');
25+
$entity = Contact::create([
26+
'name' => 'Name',
27+
'first_name' => 'Firstname',
28+
'user_id' => 0,
29+
'role' => 'user',
30+
]);
31+
$this->assertNotNull($entity);
32+
$this->assertEquals(SAVED_NEW, $entity->save());
33+
$this->assertEquals(SAVED_UPDATED, $entity->set('role', 'administrator')->save());
34+
$entity_id = $entity->id();
35+
$this->assertNotEmpty($entity_id);
36+
$entity->delete();
37+
$this->assertNull(Contact::load($entity_id));
38+
}
39+
40+
}

0 commit comments

Comments
 (0)