Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] Code readability changes on activity tokens. #17161

Merged
merged 1 commit into from
Apr 25, 2020

Conversation

eileenmcnaughton
Copy link
Contributor

Overview

Code readbility changes in 'inner workings' of token code

Before

Function name is ````getEntityContextSchema()```
activity_id key in the array is activityId

After

Function name is ````getEntityIDFieldName```
activity_id key in the array is activity_id

Technical Details

I've been trying to get to grips with this code - in part in the context of reviewing #16983 and this addresses 2 things I found very confusing - notably

  • using activityId when we were referring to a fieldname - we use a combination of & for
    variables but normally when it's closely related to a query we use activity_id
  • the function name getEntityContextSchema() was unclear to me - I concluded that in fact we were retrieving
    the name of the field for the entity ID

Comments

@mattwire @aydun putting this out there as more readable from my point of view (having battled a bit) before we got further

I've been trying to get to grips with this code and this addresses 2 things I found very confusing - notably

- using activityId when we were referring to a fieldname - we use a combination of  &  for
variables but normally when it's closely related to a query we use activity_id
- the function name getEntityContextSchema() was unclear to me - I concluded that in fact we were retrieving
the nname of the field for the entity ID
@civibot
Copy link

civibot bot commented Apr 24, 2020

(Standard links)

@mattwire
Copy link
Contributor

Token processor is currently only used via actionschedule, case PDF and (unmerged branch) to emailapi. So if we are going to change the format then now is a good time. We should do all schema keys though (ie. contactId as well). Also with \Civi\Payment\PropertyBag we standardized on the format activityID etc. We can be different here but we should have a good reason to do so!

@aydun
Copy link
Contributor

aydun commented Apr 24, 2020

  1. activityID vs activity_id - I wasn't aware of that distinction and have no strong preference

  2. The name of getEntityContextSchema arose from it's connection with TokenProcessor's $context['schema'] - but is confusing in that it does not return $context['schema'] - so yes, a name change is good.

@@ -53,7 +53,7 @@ public static function createDocument($activityIds, $html_message, $formValues)
$tp->addMessage('body_html', $html_message, 'text/html');

foreach ($activityIds as $activityId) {
$tp->addRow()->context('activityId', $activityId);
$tp->addRow()->context('activity_id', $activityId);
}
$tp->evaluate();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a view to one day standardising more of this, how about:

    $entityField = CRM_Activity_Tokens::getEntityIDFieldName();
    foreach ($activityIds as $activityId) {
      $tp->addRow()->context($entityField, $activityId);
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I commented below first so my comments may not make sense & also this comment supercedes the other..... If you look at my api PR I'm proposing removing this code inn favour of an api call

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thought was that 'acitivity_id' or 'activityId' is defined once and avoids mismatch between these various uses. But that's all void if we replace it anyway.

@@ -69,7 +69,7 @@ public static function createTokenProcessor() {
return new TokenProcessor(\Civi::dispatcher(), [
'controller' => get_class(),
'smarty' => FALSE,
'schema' => ['activityId'],
'schema' => ['activity_id'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, maybe:

    'schema' => (array) CRM_Activity_Tokens::getEntityIDFieldName();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in this case I don't know it adds value - it's harder to read & it's still hard-coded in the sense that the class is hard-coded

@eileenmcnaughton
Copy link
Contributor Author

@mattwire @aydun you are right that we don't have a clear standard - however we generally use $entityID for properties on classes but 'entity_id' for a field in an array. The row is kind of in between I guess but it feels a lot more like the latter since it's mostly populated by sql and it's an iterator class.

Agree re contactId as well - I haven't figured out where it is being set as yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants