Problem/Motivation

We use \Drupal\collect_crm\Plugin\collect\Processor\ActivityCreator processor to integrate with CRM Core and specifically to create CRM Core Activities.

In our collect_demo, titles of created activities are usually meaningless. Thus, we have "Collect Demo User" as a name of activity with collect_container as an activity type which doesn't tell us too much.
We could improve it by adding "User registration for Collect Demo User" or to use {entity_type} + {bundle} (if it is different than default one) for titles.
However, on AcitivityCreator processor settings page we have an option to choose the title of a processed activity. For instance, in case of an email message we can choose to use "Subject" or "Body" for activity title. In some cases that's not enough. We might want to use "From To " title...

Proposed resolution

We could try to provide custom title properties per plugin (email message, node, user etc).

Ideally, it would be great to have title as a text field and that we have support for tokens of container properties. In there, we could say "From {from} To {to}" which would be replaced with concrete values later then.

CommentFileSizeAuthor
#32 improve_activity_titles-2705481-32-interdiff.txt616 bytesmbovan
#32 improve_activity_titles-2705481-32.patch16.75 KBmbovan
#27 improve_activity_titles-2705481-27-interdiff.txt710 bytesmbovan
#27 improve_activity_titles-2705481-27.patch16.71 KBmbovan
#26 improve_activity_titles-2705481-26-interdiff.txt3.86 KBmbovan
#26 improve_activity_titles-2705481-26.patch16.73 KBmbovan
#23 improve_activity_titles-2705481-23-interdiff.txt18.63 KBmbovan
#23 improve_activity_titles-2705481-23.patch15.68 KBmbovan
#22 collect_2705481_json_entity_bundle.txt4.16 KBmiro_dietiker
#19 improve_activity_titles-2705481-19-interdiff.txt9.02 KBmbovan
#19 improve_activity_titles-2705481-19.patch19.71 KBmbovan
#14 improve_activity_titles-2705481-14-interdiff.txt10.1 KBmbovan
#14 improve_activity_titles-2705481-14.patch16.7 KBmbovan
#10 improve_activity_titles-2705481-10-interdiff.txt10.58 KBmbovan
#10 improve_activity_titles-2705481-10.patch16.71 KBmbovan
#8 improve_activity_titles-2705481-8-interdiff.txt6.37 KBmbovan
#8 improve_activity_titles-2705481-8.patch12.68 KBmbovan
#6 improve_activity_titles-2705481-6-interdiff.txt6.9 KBmbovan
#6 improve_activity_titles-2705481-6.patch9.19 KBmbovan
#3 improve_activity_titles-2705481-3-INMAIL.patch1.03 KBmbovan
#3 improve_activity_titles-2705481-3.patch5.69 KBmbovan
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mbovan created an issue. See original summary.

miro_dietiker’s picture

This is a key question that will result to many different answers depending on the evolution of both collect (configurability) and activity (pluggability).

1) Initially, we want to know about a fast coded approach. It makes sense that the code could provide a property that is a concatenated thing for the two cases:
- entity capture will display: "Entity " $entity_type [+ $bundle] + $title
- mail capture will display: "Mail " $subject // No From, To!
This will be persisted as activity label.

Note that with advanced configurability, these processed properties could be created through the UI. This is not a high priority now.

2) Activity will get pluggable and instead of the label, the activity view will display a summary. The collect container activity plugin will then be able to ship a more specific summary with more rich data such as Mail From + To and more.

At this stage, we will be able to make the activity look nice with the different summaries. Some first UX love will be spent to make the different summaries intuitive.

3) We want to have better type information in the activity. It should not be "Collect container". Instead it should be "Mail" or "Entity" and then this information can be removed from the label / summary.

Once we have this all don, Activity is pretty mature.
We will be able to split this all into multiple issues.

mbovan’s picture

Uploading an initial patch regarding #2.1 hard-coded approach.

I added a static _default_title property which should be used to provide default title for a container based on model plugin information/context.
This property can be used as any other property. Each model plugin can define its default title based on the given container data and context. In case of an InmailMessage plugin, it can be "Mail (@subject)". (See attached patch for Inmail)

Also, not sure if this is a direction we want to go (because #2.2 and #2.3).
On the other side, one purpose of it can be to improve activity titles easily.

The last submitted patch, 3: improve_activity_titles-2705481-3.patch, failed testing.

miro_dietiker’s picture

Status: Needs review » Needs work

Failing tests = Needs work.

mbovan’s picture

Added implementation of CollectJson::getDefaultTitle(), added tests and fixed old ones.

Status: Needs review » Needs work

The last submitted patch, 6: improve_activity_titles-2705481-6.patch, failed testing.

mbovan’s picture

The test above relies on #2709007: Implement getDefaultTitle in InmailMessage plugin. Changed it to separate ActivityCreatorTest.

miro_dietiker’s picture

Status: Needs review » Needs work
+++ b/crm/src/Plugin/collect/Processor/ActivityCreator.php
+++ b/crm/src/Plugin/collect/Processor/ActivityCreator.php
@@ -72,7 +72,28 @@ class ActivityCreator extends ProcessorBase {

@@ -72,7 +72,28 @@ class ActivityCreator extends ProcessorBase {
-        $title = $data->get($title_property);
+        // Check for default title property provided by a model plugin.
+        if ($title_property == CollectDataInterface::DEFAULT_TITLE_KEY) {
... (and many more)

The processing setting should simply point to the property _default_title and you will get it here as $title_property.
No changes needed here.

You just need to provide the static property with ModelPluginInterface:: getStaticPropertyDefinitions() and then intercept on resolveQueryPath() to provide the _default_title value.

mbovan’s picture

You just need to provide the static property with ModelPluginInterface:: getStaticPropertyDefinitions() and then intercept on resolveQueryPath() to provide the _default_title value.

As discussed, it won't work easily as $data that we get in resolveQueryPath() is raw (parsed) data.

With some API changes, it might work...

Status: Needs review » Needs work

The last submitted patch, 10: improve_activity_titles-2705481-10.patch, failed testing.

mbovan’s picture

Status: Needs work » Needs review
miro_dietiker’s picture

Status: Needs review » Needs work
  1. +++ b/src/Model/ModelPluginBase.php
    @@ -14,6 +14,7 @@ use Drupal\collect\TypedData\CollectDataInterface;
    @@ -105,7 +106,13 @@ abstract class ModelPluginBase extends PluginBase implements ModelPluginInterfac
    
    @@ -105,7 +106,13 @@ abstract class ModelPluginBase extends PluginBase implements ModelPluginInterfac
       public static function getStaticPropertyDefinitions() {
    ...
    +      '_default_title' => new PropertyDefinition('_default_title', $default_title_data_definition),
    

    I'm a bit confused, instead of defining the title property just for the two mentioned models such as Inmail and Collect, you extend the Model interface and put many things into the Base. In fact that doubles the complexity.
    (The issue was not about introducing a title for all Collect containers. We should decide about generalisation at a later point IMHO.)

  2. +++ b/src/Plugin/collect/Model/CollectJson.php
    @@ -292,4 +292,51 @@ class CollectJson extends Json implements DynamicModelTypedDataInterface, Contai
    +    if ($property_name == CollectDataInterface::DEFAULT_TITLE_KEY) {
    
    +++ b/src/TypedData/CollectDataInterface.php
    @@ -19,6 +19,13 @@ interface CollectDataInterface extends ComplexDataInterface {
    +  const DEFAULT_TITLE_KEY = '_default_title';
    

    Please simply use the strings.

  3. +++ b/src/Plugin/collect/Model/CollectJson.php
    @@ -292,4 +292,51 @@ class CollectJson extends Json implements DynamicModelTypedDataInterface, Contai
    +          return $this->t('@entity_type @bundle', ['@entity_type' => $entity_type, '@bundle' => $bundle]);
    ...
    +        return $this->t('@entity_type', ['@entity_type' => $entity_type]);
    

    No t() for simple placeholders.

  4. +++ b/src/Plugin/collect/Model/CollectJson.php
    @@ -292,4 +292,51 @@ class CollectJson extends Json implements DynamicModelTypedDataInterface, Contai
    +        $this->logger->warning($e->getMessage());
    

    When does this happen? Comment?

  5. +++ b/src/Plugin/collect/Model/FieldDefinition.php
    @@ -177,6 +177,29 @@ class FieldDefinition extends Json implements SpecializedDisplayModelPluginInter
    +  public static function getDefinitionContainerTypedData(CollectContainerInterface $values_container) {
    

    This code is outsourced. Call it from the origin. If i remember right it contained some more error handling that is needed. I think the method should throw an exception if it fails..

mbovan’s picture

Addressing the points from #13.

Status: Needs review » Needs work

The last submitted patch, 14: improve_activity_titles-2705481-14.patch, failed testing.

mbovan’s picture

Status: Needs work » Needs review
miro_dietiker’s picture

Status: Needs review » Needs work

Yeah, right direction. We're getting to the point. :-)

  1. +++ b/src/Model/ModelPluginBase.php
    @@ -153,4 +153,11 @@ abstract class ModelPluginBase extends PluginBase implements ModelPluginInterfac
    +  public function getDefaultTitle(CollectDataInterface $data) {
    
    +++ b/src/Model/ModelPluginInterface.php
    @@ -115,4 +115,17 @@ interface ModelPluginInterface extends PluginInspectionInterface {
    +  public function getDefaultTitle(CollectDataInterface $data);
    

    Then this need to die also. No Interface or Base changes. All on specific model levels.

  2. +++ b/src/Plugin/collect/Model/CollectJson.php
    @@ -217,25 +218,21 @@ class CollectJson extends Json implements DynamicModelTypedDataInterface, Contai
         if (isset($values_data['fields'])) {
    ...
    +        $field_definition_data = FieldDefinition::getDefinitionContainerTypedData($collect_container);
    

    Note here that Typed data definition is not necessarily a container, although we switched to that.
    Field definition could be attached as part of the value container.

    The helper API should cover both cases and return TypedData. If there is a definition Container or direct definition is an internal problem.

  3. +++ b/src/Plugin/collect/Model/CollectJson.php
    @@ -292,4 +289,64 @@ class CollectJson extends Json implements DynamicModelTypedDataInterface, Contai
    +      if ($collect_data) {
    

    Move this check into getDefaultTitle().
    And then the @todo default title case will disappear.

miro_dietiker’s picture

Also the default config for collect_demo needs an update (select default_title as CollectJson processing for activity matcher) and be properly asserted in demo test.

mbovan’s picture

Updated demo settings, added tests and addressed #17

Note here that Typed data definition is not necessarily a container, although we switched to that.
Field definition could be attached as part of the value container.

The helper API should cover both cases and return TypedData. If there is a definition Container or direct definition is an internal problem.

I guess we should always pass a container and then handle it inside a method... Added support for "fields definitions attached to values container".

Status: Needs review » Needs work

The last submitted patch, 19: improve_activity_titles-2705481-19.patch, failed testing.

mbovan’s picture

Status: Needs work » Needs review
miro_dietiker’s picture

As discussed a minimum invasive POC attached, will not work. ;-)

mbovan’s picture

Uploading a patch based on #22 and discussion with @miro_dietiker. However, it's slightly modified in some aspects.

This might wait for #2710733: Update contact matchers with name fields changes

miro_dietiker’s picture

Status: Needs review » Needs work

Looks pretty good. One major thing.

+++ b/src/Plugin/collect/Model/CollectJson.php
@@ -173,12 +184,46 @@ class CollectJson extends Json implements DynamicModelTypedDataInterface, Contai
+      return $default_title;

The original label/title is wrongly dropped from the default_title... It's nor just entity type + bundle.

The last submitted patch, 23: improve_activity_titles-2705481-23.patch, failed testing.

mbovan’s picture

We kind of lost it somewhere on the way...

Before, we could choose the exact property to use for activity title. As of now, it's not that easy to get the label of captured entity at the point we create it.
I'm attaching some sort of hacks to check if name/title field exists and if yes using that value... Not sure if it is acceptable, but currently I don't see other solution.

mbovan’s picture

The last submitted patch, 26: improve_activity_titles-2705481-26.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 27: improve_activity_titles-2705481-27.patch, failed testing.

mbovan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 27: improve_activity_titles-2705481-27.patch, failed testing.

mbovan’s picture

Fixed a remaining test fail.

  • slashrsm committed 24f2142 on 8.x-1.x authored by mbovan
    Issue #2705481 by mbovan, miro_dietiker, slashrsm: Improve activity...
slashrsm’s picture

Status: Needs review » Fixed

Reviewed and committed.

Status: Fixed » Closed (fixed)

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