Problem/Motivation

Every contact should have a mail field.
We also want to test a concept we intended to introduce more widely: a multivalue field with predicated type

Proposed resolution

We will introduce a new field type "mail with type".
The new type will subclass the mail field and add a new type base field.
"type" is a string
Allowed type values are for now hardcoded. Might be switched later to some configurable definition.

A multivalue field instance is added to the contact by default. (will be a follow-up)

The widget will offer the type selection (drop down), for now just offer "home" and "work".
Make sure the field also displays.

As a followup, make our collect_demo case build on top of this.
#2703967: Show email field in Collect CRM

User interface changes

A new field type "mail with type".

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

miro_dietiker created an issue. See original summary.

miro_dietiker’s picture

Status: Postponed » Active

Agree that providing the configuration is possibly not worth, but you can still start coding the field type, widget, formatter meanwhile.
Also attaching the field to a different entity type as a cleanup isn't that much duplicate work.

This is a prototype issue that will unlock many others. We want to start with this ASAP.

slashrsm’s picture

We can start working on the field type and add it to the entity in a follow-up.

mbovan’s picture

Status: Active » Needs review
FileSize
9.96 KB

Attaching an initial patch with 'mail_with_type' field type, widget, formatter, schemas and tests.

Not sure about naming... It will need some cleanup in configuration settings too.

miro_dietiker’s picture

Where are we placing an API to fetch a / the first value of a specific type?

Berdir’s picture

I think such an API would basically be a replacement for getPrimaryField(), so on the entities that use it? Anything else doesn't give you method autocomplete.

Berdir’s picture

  1. +++ b/modules/crm_core_contact/config/schema/crm_core_contact.schema.yml
    @@ -45,3 +45,33 @@ crm_core_contact.organization_type.*:
    +field.storage_settings.mail_with_type:
    +  type: mapping
    +  label: 'Mail with type settings'
    +  mapping:
    +    mail_types:
    +      type: string
    +      label: 'Mail types'
    

    we will also need schema for the field config settings and the field value

  2. +++ b/modules/crm_core_contact/src/Plugin/Field/FieldFormatter/MailWithTypeFormatter.php
    @@ -0,0 +1,44 @@
    + *   quickedit = {
    + *     "editor" = "plain_text"
    + *   }
    + * )
    + */
    +class MailWithTypeFormatter extends FormatterBase {
    

    Should we display it like \Drupal\Core\Field\Plugin\Field\FieldFormatter\MailToFormatter maybe? Or support both..

  3. +++ b/modules/crm_core_contact/src/Plugin/Field/FieldType/MailWithTypeItem.php
    @@ -0,0 +1,76 @@
    +    $schema['columns']['type'] = [
    +      'type' => 'varchar',
    +      'length' => 255,
    

    We need to define what we actually store? Do we support both pre-defined and and other labels? Or only pre-defined (would be a lot easier for storage, we can make it a 32 character ascii string)

mbovan’s picture

Added description for "Mail types".

Ha, didn't see #8 before uploading.

mbovan’s picture

Addressed #8.1, #8.2 and schema settings for #8.3.

slashrsm’s picture

FileSize
18.66 KB
20.25 KB

Changes on top of #10:
- renamed field/formatter/widget s/mail/email to be consistent with core
- made mail types list configurable
- slightly modified formatter's output
- improved test coverage

thenchev’s picture

Status: Needs review » Needs work
  1. +++ b/modules/crm_core_contact/tests/src/Kernel/MailWithTypeItemTest.php
    @@ -2,20 +2,40 @@
    +use Drupal\Core\Language\LanguageInterface;
    ...
    +use Symfony\Component\Validator\Constraints\True;
    

    Looks like these are not used.

  2. +++ b/modules/crm_core_contact/tests/src/Kernel/MailWithTypeItemTest.php
    @@ -28,28 +48,50 @@ class MailWithTypeItemTest extends KernelTestBase {
    +    $this->viewDisplay->setComponent(
    +      'field_mail_with_type', [
    +      'type' => 'email_with_type',
    +    ])->save();
    

    indentation.
    Other than that looks good.

slashrsm’s picture

Status: Needs work » Needs review
FileSize
18.51 KB
1.27 KB

Fixed.

thenchev’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to go.

  • slashrsm committed 79ec34b on 8.x-1.x
    Issue #2704451 by mbovan, slashrsm, miro_dietiker, Denchev, Berdir: Add...
slashrsm’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

Andreas Radloff’s picture

I'm a little late to the party, but I just wanted to point out that there is already a D8 version of Double Field which allows creating key-value fields. Maybe that could be useful for the social profiles and such?

Double field does not support an email field out of the box.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.