Commit c6abbb9a authored by bojanz's avatar bojanz

Issue #2759939 by bojanz, mglaman: Replace the name column with separate...

Issue #2759939 by bojanz, mglaman: Replace the name column with separate given_name/family_name columns
parent ddb1bb6c
......@@ -30,7 +30,9 @@ function address_theme() {
return [
'address_plain' => [
'variables' => [
'recipient' => '',
'given_name' => '',
'additional_name' => '',
'family_name' => '',
'organization' => '',
'address_line1' => '',
'address_line2' => '',
......
......@@ -108,9 +108,15 @@ field.value.address:
organization:
type: string
label: 'Organization'
recipient:
given_name:
type: string
label: 'Recipient'
label: 'Given name'
additional_name:
type: string
label: 'Additional name'
family_name:
type: string
label: 'Family name'
field.field_settings.address:
type: mapping
......
......@@ -28,7 +28,9 @@ class FieldHelper {
AddressField::ADDRESS_LINE1 => 'address_line1',
AddressField::ADDRESS_LINE2 => 'address_line2',
AddressField::ORGANIZATION => 'organization',
AddressField::RECIPIENT => 'recipient',
AddressField::GIVEN_NAME => 'given_name',
AddressField::ADDITIONAL_NAME => 'additional_name',
AddressField::FAMILY_NAME => 'family_name',
];
return isset($property_mapping[$field]) ? $property_mapping[$field] : NULL;
......@@ -55,7 +57,9 @@ class FieldHelper {
AddressField::ADDRESS_LINE1 => 'address-line1',
AddressField::ADDRESS_LINE2 => 'address-line2',
AddressField::ORGANIZATION => 'organization',
AddressField::RECIPIENT => 'name',
AddressField::FAMILY_NAME => 'family-name',
AddressField::ADDITIONAL_NAME => 'additional-name',
AddressField::GIVEN_NAME => 'given-name',
];
return isset($autocomplete_mapping[$field]) ? $autocomplete_mapping[$field] : NULL;
......
......@@ -44,7 +44,9 @@ class LabelHelper {
// The address line 2 label is usually shown only to screen-reader users.
AddressField::ADDRESS_LINE2 => t('Street address line 2', [], ['context' => 'Address label']),
AddressField::ORGANIZATION => t('Company', [], ['context' => 'Address label']),
AddressField::RECIPIENT => t('Contact name', [], ['context' => 'Address label']),
AddressField::GIVEN_NAME => t('First name', [], ['context' => 'Address label']),
AddressField::ADDITIONAL_NAME => t('Middle name', [], ['context' => 'Address label']),
AddressField::FAMILY_NAME => t('Last name', [], ['context' => 'Address label']),
];
}
......@@ -66,7 +68,9 @@ class LabelHelper {
AddressField::ADDRESS_LINE1 => t('Address line 1', [], ['context' => 'Address label']),
AddressField::ADDRESS_LINE2 => t('Address line 2', [], ['context' => 'Address label']),
AddressField::ORGANIZATION => t('Organization', [], ['context' => 'Address label']),
AddressField::RECIPIENT => t('Recipient', [], ['context' => 'Address label']),
AddressField::GIVEN_NAME => t('Given name', [], ['context' => 'Address label']),
AddressField::ADDITIONAL_NAME => t('Additional name', [], ['context' => 'Address label']),
AddressField::FAMILY_NAME => t('Family name', [], ['context' => 'Address label']),
];
}
......
......@@ -132,7 +132,9 @@ class AddressPlainFormatter extends FormatterBase implements ContainerFactoryPlu
$element = [
'#theme' => 'address_plain',
'#recipient' => $values['recipient'],
'#given_name' => $values['givenName'],
'#additional_name' => $values['additionalName'],
'#family_name' => $values['familyName'],
'#organization' => $values['organization'],
'#address_line1' => $values['addressLine1'],
'#address_line2' => $values['addressLine2'],
......
......@@ -79,7 +79,15 @@ class AddressItem extends FieldItemBase implements AddressInterface {
'type' => 'varchar',
'length' => 255,
],
'recipient' => [
'given_name' => [
'type' => 'varchar',
'length' => 255,
],
'additional_name' => [
'type' => 'varchar',
'length' => 255,
],
'family_name' => [
'type' => 'varchar',
'length' => 255,
],
......@@ -112,8 +120,12 @@ class AddressItem extends FieldItemBase implements AddressInterface {
->setLabel(t('The second line of the address block.'));
$properties['organization'] = DataDefinition::create('string')
->setLabel(t('The organization'));
$properties['recipient'] = DataDefinition::create('string')
->setLabel(t('The recipient.'));
$properties['given_name'] = DataDefinition::create('string')
->setLabel(t('The given name.'));
$properties['additional_name'] = DataDefinition::create('string')
->setLabel(t('The additional name.'));
$properties['family_name'] = DataDefinition::create('string')
->setLabel(t('The family name.'));
return $properties;
}
......@@ -340,8 +352,22 @@ class AddressItem extends FieldItemBase implements AddressInterface {
/**
* {@inheritdoc}
*/
public function getRecipient() {
return $this->recipient;
public function getGivenName() {
return $this->given_name;
}
/**
* {@inheritdoc}
*/
public function getAdditionalName() {
return $this->additional_name;
}
/**
* {@inheritdoc}
*/
public function getFamilyName() {
return $this->family_name;
}
}
......@@ -239,7 +239,9 @@ class AddressDefaultWidget extends WidgetBase implements ContainerFactoryPluginI
'address_line1' => '',
'address_line2' => '',
'organization' => '',
'recipient' => '',
'given_name' => '',
'additional_name' => '',
'family_name' => '',
];
// Allow other modules to alter the values.
$event = new InitialValuesEvent($initial_values, $this->fieldDefinition);
......
......@@ -180,7 +180,8 @@ class AddressDefaultWidgetTest extends WebTestBase {
// Create an article with one of them.
$address = [
'country_code' => 'US',
'recipient' => 'Some Recipient',
'given_name' => 'John',
'family_name' => 'Smith',
'organization' => 'Some Organization',
'address_line1' => '1098 Alta Ave',
'locality' => 'Mountain View',
......@@ -211,7 +212,8 @@ class AddressDefaultWidgetTest extends WebTestBase {
// 'US' should be in the list along with the available countries and should
// be selected.
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertFieldByName($field_name . '[0][recipient]', $address['recipient']);
$this->assertFieldByName($field_name . '[0][given_name]', $address['given_name']);
$this->assertFieldByName($field_name . '[0][family_name]', $address['family_name']);
$this->assertFieldByName($field_name . '[0][organization]', $address['organization']);
$this->assertFieldByName($field_name . '[0][address_line1]', $address['address_line1']);
$this->assertFieldByName($field_name . '[0][locality]', $address['locality']);
......@@ -233,7 +235,8 @@ class AddressDefaultWidgetTest extends WebTestBase {
// Submitting the form should result in no data loss.
$this->drupalPostForm(NULL, [], t('Save'));
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertFieldByName($field_name . '[0][recipient]', $address['recipient']);
$this->assertFieldByName($field_name . '[0][given_name]', $address['given_name']);
$this->assertFieldByName($field_name . '[0][family_name]', $address['family_name']);
$this->assertFieldByName($field_name . '[0][organization]', $address['organization']);
$this->assertFieldByName($field_name . '[0][address_line1]', $address['address_line1']);
$this->assertFieldByName($field_name . '[0][locality]', $address['locality']);
......@@ -287,7 +290,8 @@ class AddressDefaultWidgetTest extends WebTestBase {
'addressLine1' => $field_name . '[0][address_line1]',
'addressLine2' => $field_name . '[0][address_line2]',
'organization' => $field_name . '[0][organization]',
'recipient' => $field_name . '[0][recipient]',
'givenName' => $field_name . '[0][given_name]',
'familyName' => $field_name . '[0][family_name]',
];
$allFieldsKeys = array_keys($allFields);
......@@ -312,8 +316,8 @@ class AddressDefaultWidgetTest extends WebTestBase {
$this->assertFieldValues($usedFields, $formFields, 'Expected fields ' . implode(', ', $usedFields) . ' exists for country ' . $country . ", only found " . implode(', ', $formFields));
}
// Disable the recipient and postal code fields.
$disabledFields = ['recipient', 'postalCode'];
// Disable the name and postal code fields.
$disabledFields = ['givenName', 'familyName', 'postalCode'];
$edit = [];
foreach ($allFieldsKeys as $field) {
$edit['settings[fields][' . $field . ']'] = !in_array($field, $disabledFields);
......@@ -383,7 +387,8 @@ class AddressDefaultWidgetTest extends WebTestBase {
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName(8);
$edit[$field_name . '[0][country_code]'] = 'US';
$edit[$field_name . '[0][recipient]'] = 'Some Recipient';
$edit[$field_name . '[0][given_name]'] = 'John';
$edit[$field_name . '[0][family_name]'] = 'Smith';
$edit[$field_name . '[0][organization]'] = 'Some Organization';
$edit[$field_name . '[0][address_line1]'] = '1098 Alta Ave';
$edit[$field_name . '[0][address_line2]'] = 'Street 2';
......
......@@ -4,7 +4,9 @@
* Default template for the 'plain' address formatter.
*
* Available variables:
* - recipient: Recipient.
* - given_name: Given name.
* - additional_name: Additional name.
* - family_name: Family name.
* - organization: Organization.
* - address_line1: First address line.
* - address_line2: Second address line.
......@@ -31,8 +33,8 @@
*/
#}
<p class="address" translate="no">
{% if recipient %}
{{ recipient }} <br>
{% if given_name or family_name %}
{{ given_name }} {{ family_name }} <br>
{% endif %}
{% if organization %}
{{ organization }} <br>
......
......@@ -43,7 +43,8 @@ class AddressTestEventSubscriber implements EventSubscriberInterface {
'address_line1' => 'Some address',
'address_line2' => 'Some street',
'organization' => 'Some Organization',
'recipient' => 'Some Recipient',
'given_name' => 'John',
'family_name' => 'Smith',
];
}
......
......@@ -167,6 +167,8 @@ class DefaultFormatterTest extends KernelTestBase {
// Any HTML in the fields is supposed to be escaped.
'organization' => 'Giant <h2>Bike</h2> Store',
'recipient' => 'Mr. Liu',
'given_name' => 'Wu',
'family_name' => 'Chen',
];
$this->renderEntityFields($entity, $this->display);
$expected = implode('', [
......@@ -176,7 +178,7 @@ class DefaultFormatterTest extends KernelTestBase {
'line4' => '<span class="administrative-area">台北市</span><span class="locality">大安區</span><br>' . "\n",
'line5' => '<span class="address-line1">Sec. 3 Hsin-yi Rd.</span><br>' . "\n",
'line6' => '<span class="organization">Giant &lt;h2&gt;Bike&lt;/h2&gt; Store</span><br>' . "\n",
'line7' => '<span class="recipient">Mr. Liu</span>',
'line7' => '<span class="family-name">Chen</span><span class="given-name">Wu</span>',
'line8' => '</p>',
]);
$this->assertRaw($expected, 'The TW address has been properly formatted.');
......
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