Problem/Motivation

D7 version of CRM core relies on the Name field module to provide default name field. Field is added dynamically every time when a new contact bundle is created.

Proposed resolution

Add name field as a base field on the contact entity:
- check Name field module (it seems to have a D8 port), check if field type works as expected
- add Name field as a dependency of crm_core_contact
- add "name" base field to the contact entity
- remove all D7 code that was used to dynamically add name field
- provide test coverage that will assure field is there and works correctly

Comments

slashrsm created an issue. See original summary.

thenchev’s picture

Assigned: Unassigned » thenchev
berdir’s picture

I guess _crm_core_contact_contact_name_base() is related to that, as it defines name functionality and is currently unused.

thenchev’s picture

Status: Active » Needs review
StatusFileSize
new7.92 KB

Here is some initial code. There is an exception when i try to add a contact. In the name module name_element_pre_render when we checks the cardinality it tries to access the value as an array but we have a Drupal\name\Plugin\Field\FieldWidget\NameWidget.
Also tests are missing.

Status: Needs review » Needs work

The last submitted patch, 4: add_name_field_to_the-2691491-4.patch, failed testing.

thenchev’s picture

Status: Needs work » Needs review
StatusFileSize
new503 bytes

Think i we need to commit this dependencies so the test work.

Status: Needs review » Needs work

The last submitted patch, 6: add_name_field_to_the-2691491-6.patch, failed testing.

thenchev’s picture

Not sure how this lines affect activity UI tests.

fail: [Other] Line 33 of modules/crm_core/modules/crm_core_activity_ui/src/Tests/ActivityUiTest.php:
Unable to install modules: module 'crm_core_activity_ui' is missing its dependency module name.

thenchev’s picture

Status: Needs work » Needs review
StatusFileSize
new441 bytes

Of course. This should be green.

thenchev’s picture

Btw whats planned for the contact entity? The default household and organization don't make too much sense with the default name field settings(format). We need deferment field settings for these bundles. Are we going for field_ui_base_route?

slashrsm’s picture

Status: Needs review » Needs work

True. We were discussing to split those in separate entity types for exactly this reason. I'd say add this field to current Contact entity which will become Individual when we switch.

thenchev’s picture

Status: Needs work » Needs review
StatusFileSize
new454 bytes

just the name and entity dependencies.

slashrsm’s picture

Test dependencies committed.

thenchev’s picture

There is an issue on #2629910: WSOD caused by 'description' as array that causes problems when using name field.

thenchev’s picture

As discussed with @slashrsm updated the contact label to return first and last name. Also started with commenting out the tests but there are also some hardcoded urls and I would need to change a lot of code to make the test pass. So maybe it is ok for now to just use the name field for $household_node and $organization_node (left a comment there) until we split the contact into entities? It would be easier to later change them.

The test should fail since there are some not commited issues on name module. Like #2629910: WSOD caused by 'description' as array and #2700377: Call to undefined method on manage display

Status: Needs review » Needs work

The last submitted patch, 17: add_name_field_to_the-2691491-17.patch, failed testing.

thenchev’s picture

Status: Needs work » Needs review
StatusFileSize
new14.38 KB

Same as #17. Reuploading to see if tests pass now.

Status: Needs review » Needs work

The last submitted patch, 19: add_name_field_to_the-2691491-19.patch, failed testing.

mbovan’s picture

Tried the patch and it breaks Collect as we are changing the base field type here which results in property definition mismatch with Name field in CRM Core Match.

+++ b/modules/crm_core_contact_ui/src/Tests/ContactUiTest.php
@@ -151,17 +167,23 @@ class ContactUiTest extends WebTestBase {
-    $this->assertLink('Johnson', 0, 'Updated individual contact title listed.');
+    $this->assertLink('Maynard Keenan', 0, 'Updated individual contact title listed.');

Changing to metal genre here. :)

thenchev’s picture

Status: Needs work » Needs review
StatusFileSize
new14.76 KB

Just added name to the modules list in the test.

@mbovan Thought to sneak in some names :) don't know about standards here.

Status: Needs review » Needs work

The last submitted patch, 22: add_name_field_to_the-2691491-21.patch, failed testing.

mbovan’s picture

Created a followup for CRM Core Match #2701979: Update Name field

thenchev’s picture

Status: Needs work » Needs review
StatusFileSize
new364 bytes

This is just the dependency for crm_core matcher.

thenchev’s picture

StatusFileSize
new14.89 KB

Same as #22.

Status: Needs review » Needs work

The last submitted patch, 27: add_name_field_to_the-2691491-27.patch, failed testing.

thenchev’s picture

Status: Needs work » Needs review
StatusFileSize
new10.49 KB
new24.95 KB

Should fix some tests and update matcher for name field.

mbovan’s picture

Issue summary: View changes
Status: Needs review » Needs work
StatusFileSize
new21.16 KB
  1. +++ b/modules/crm_core_match/src/Plugin/crm_core_match/field/Name.php
    @@ -31,55 +53,59 @@ class Name extends FieldHandlerBase {
       public function match(ContactInterface $contact, $property = 'value') {
    +    if (!($this->field instanceof FieldConfigInterface) && !($this->field instanceof BaseFieldDefinition)) {
    +      return [];
    +    }
    

    Not sure about this check...

  2. +++ b/modules/crm_core_match/tests/src/Kernel/FieldMatcherTest.php
    @@ -1,11 +1,15 @@
    +/**
    + * @file
    + * Contains \Drupal\crm_core_match\Tests\FieldMatcherTest.
    + */
    

    Can be removed.

  3. +++ b/modules/crm_core_match/src/Plugin/crm_core_match/field/Name.php
    @@ -31,55 +53,59 @@ class Name extends FieldHandlerBase {
    +    foreach ($this->getPropertyNames() as $property) {
    +      if ($contact->get($field_name)->{$property}) {
    +        $valid_parts[$property] = $contact->get($field_name)->{$property};
           }
    

    Talked with @Denchev about this.

    We are not sure if should have a CRM field per "real" entity field (1:1), or a property per entity field? (See the screenshot below)
    Do we want to allow a user to favorize properties of each field (e.g. "family" and "given" in Name field) or we should do the matching for a field (and check all the properties in the background)?

thenchev’s picture

Status: Needs work » Needs review
StatusFileSize
new24.52 KB

reroll

Status: Needs review » Needs work

The last submitted patch, 31: add_name_field_to_the-2691491-31.patch, failed testing.

thenchev’s picture

Status: Needs work » Needs review
StatusFileSize
new3.55 KB
new25.02 KB

Changed tests and updated match so it only works with the defined property. #30.2 is removed, left #30.1 for now... i can for example remove it completely or check if this->field is defined not sure.

#30.3 created followup #2706203: Matcher form doesn't show properties

mbovan’s picture

This change breaks Collect, so I think we should open a followup to update it with the changes here.

Still not sure about #30.1.

Overall, looks good.

slashrsm’s picture

Status: Needs review » Needs work

#30.1 looks strange indeed. Let's figure out if we can improve that part.

Also, this will need to update the view after #2703565: Replace contact list builder with a view has landed.

thenchev’s picture

Status: Needs work » Needs review
StatusFileSize
new7.19 KB
new31.61 KB

The check is actually not rely needed, so i removed it completely, also updated the view. I have a few questions here:

1. I don't see any option in the view to make the name a link to the contact, and we don't have a view operation exposed. A followup on the name module?

2. We have to choose how the click sort works you have to choose one of given, title, family... I set it to family but not sure

3. The exposed filter works when we separate in different properties I don't see an options for both name and family to be in one exposed filter.

There will be test fails but i can fix them when we decide how the view should look and work.

Status: Needs review » Needs work

The last submitted patch, 36: add_name_field_to_the-2691491-36.patch, failed testing.

thenchev’s picture

StatusFileSize
new28.74 KB

view

slashrsm’s picture

1. and 3. sound like a Name field follow-up. 2. sounds ok.

thenchev’s picture

Status: Needs work » Needs review
StatusFileSize
new33.87 KB
new4.02 KB

created 2 followups #2709299: Combined views filter and #2709295: Link name field to the referenced entity

also there is some schema missing on name module i overlooked last time so when this patch [#2629910]is commited all test should be green.

Status: Needs review » Needs work

The last submitted patch, 40: add_name_field_to_the-2691491-40.patch, failed testing.

The last submitted patch, 40: add_name_field_to_the-2691491-40.patch, failed testing.

thenchev’s picture

Status: Needs work » Needs review
StatusFileSize
new609 bytes
new33.87 KB

Ok figured it out. This should fix the view.

mbovan’s picture

Hard to review, but seems like good to go... We will need to update Collect with the changes introduced here.

  • slashrsm committed 87a5f2f on 8.x-1.x authored by Denchev
    Issue #2691491 by Denchev, mbovan, slashrsm, Berdir: Add name field to...
slashrsm’s picture

Status: Needs review » Fixed

Committed. Will open follow-up for collect.

  • slashrsm committed 2c4a60a on 8.x-2.x authored by Denchev
    Issue #2691491 by Denchev: Add test dependency.
    
  • slashrsm committed 87a5f2f on 8.x-2.x authored by Denchev
    Issue #2691491 by Denchev, mbovan, slashrsm, Berdir: Add name field to...

Status: Fixed » Closed (fixed)

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