[Rt-commit] rt branch, 4.2/expose-cf-to-cfvs, created. rt-4.2.9-46-g803ca7f

Kevin Falcone falcone at bestpractical.com
Mon Dec 8 15:48:46 EST 2014


The branch, 4.2/expose-cf-to-cfvs has been created
        at  803ca7ff7d9b3b871f6f13f18fc3d05f544af86b (commit)

- Log -----------------------------------------------------------------
commit a84b429e9c105bec42a63a83e6e086f219a9fc1a
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Wed Dec 3 11:10:21 2014 -0500

    Keep track of which Custom Field object these Values belong to
    
    While you can reverse the Custom Field by looking at
    $cfvs->First->CustomFieldObj you lose the Context Object of the Custom
    Field (and more importantly, the ACLEquivalenceObjects).
    
    Knowing this lets you know what Queue a CF was loaded against so if you're
    writing an External Custom Field (or otherwise massaging values) you
    could tweak the output based on the Queue.

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 91ffdc3..0359ef5 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -604,6 +604,7 @@ sub Values {
         $class->require or die "Can't load $class: $@";
     }
     my $cf_values = $class->new( $self->CurrentUser );
+    $cf_values->SetCustomFieldObject( $self );
     # if the user has no rights, return an empty object
     if ( $self->id && $self->CurrentUserHasRight( 'SeeCustomField') ) {
         $cf_values->LimitToCustomField( $self->Id );
@@ -1029,7 +1030,6 @@ sub ValidateContextObject {
     return $self->IsAdded($added_to->id);
 }
 
-
 sub _Set {
     my $self = shift;
 
diff --git a/lib/RT/CustomFieldValues.pm b/lib/RT/CustomFieldValues.pm
index 25d5d69..9a49482 100644
--- a/lib/RT/CustomFieldValues.pm
+++ b/lib/RT/CustomFieldValues.pm
@@ -93,6 +93,33 @@ sub LimitToCustomField {
     );
 }
 
+=head2 SetCustomFieldObject
+
+Store the CustomField object which loaded this CustomFieldValues collection.
+Consumers of CustomFieldValues collection (such as External Custom Fields)
+can now work out how they were loaded (off a Queue or Ticket or something else)
+by inspecting the CustomField.
+
+=cut
+
+sub SetCustomFieldObject {
+    my $self = shift;
+    return $self->{'custom_field'} = shift;
+}
+
+=head2 CustomFieldObject
+
+Returns the CustomField object used to load this CustomFieldValues collection.
+Relies on $CustomField->Values having been called, is not set on manual loads.
+
+=cut
+
+sub CustomFieldObject {
+    my $self = shift;
+    return $self->{'custom_field'};
+}
+
+
 RT::Base->_ImportOverlays();
 
 1;

commit 803ca7ff7d9b3b871f6f13f18fc3d05f544af86b
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Mon Dec 8 15:12:27 2014 -0500

    Pass down the CustomField object from the collection.
    
    Given a RT::CustomFieldValue object you can now do the same
    introspection that External Custom Fields can do on
    RT::CustomFieldValues by looking at the actual CustomField object that
    was used to load the collection.

diff --git a/lib/RT/CustomFieldValue.pm b/lib/RT/CustomFieldValue.pm
index 1ba73ef..0fc95a4 100644
--- a/lib/RT/CustomFieldValue.pm
+++ b/lib/RT/CustomFieldValue.pm
@@ -307,6 +307,30 @@ sub FindDependencies {
     $deps->Add( out => $self->CustomFieldObj );
 }
 
+=head2 SetCustomFieldObject
+
+Store the CustomField object which loaded this CustomFieldValue.
+Passed down from the CustomFieldValues collection in AddRecord.
+
+=cut
+
+sub SetCustomFieldObject {
+    my $self = shift;
+    return $self->{'custom_field'} = shift;
+}
+
+=head2 CustomFieldObject
+
+Returns the CustomField object used to load this CustomFieldValue.
+Replies on the CustomFieldValues collection having a CustomFieldObject set.
+
+=cut
+
+sub CustomFieldObject {
+    my $self = shift;
+    return $self->{'custom_field'};
+}
+
 
 RT::Base->_ImportOverlays();
 
diff --git a/lib/RT/CustomFieldValues.pm b/lib/RT/CustomFieldValues.pm
index 9a49482..d8f02f4 100644
--- a/lib/RT/CustomFieldValues.pm
+++ b/lib/RT/CustomFieldValues.pm
@@ -119,6 +119,23 @@ sub CustomFieldObject {
     return $self->{'custom_field'};
 }
 
+=head2 AddRecord
+
+Propagates the CustomField object from the Collection
+down to individual CustomFieldValue objects.
+
+=cut
+
+sub AddRecord {
+    my $self = shift;
+    my $CFV = shift;
+
+    $CFV->SetCustomFieldObject($self->CustomFieldObject);
+
+    push @{$self->{'items'}}, $CFV;
+    $self->{'rows'}++;
+}
+
 
 RT::Base->_ImportOverlays();
 

-----------------------------------------------------------------------


More information about the rt-commit mailing list