[Rt-commit] rt branch, 4.2/expose-cf-to-cfvs, created. rt-4.2.9-46-g7e382cb
Kevin Falcone
falcone at bestpractical.com
Thu Dec 11 17:45:08 EST 2014
The branch, 4.2/expose-cf-to-cfvs has been created
at 7e382cb9faf0b7954c4bb7d62ca01832d00eeabc (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 7e382cb9faf0b7954c4bb7d62ca01832d00eeabc
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. This is transparently returned by
->CustomFieldObj as long as SetCustomFieldObj was called previously and
passed a CustomField which matches the one the database says this
CustomFieldValue belongs to.
diff --git a/lib/RT/CustomFieldValue.pm b/lib/RT/CustomFieldValue.pm
index 1ba73ef..9841cae 100644
--- a/lib/RT/CustomFieldValue.pm
+++ b/lib/RT/CustomFieldValue.pm
@@ -144,18 +144,37 @@ Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
(In the database, CustomField will be stored as a int(11).)
+=head2 SetCustomFieldObj
+
+Store the CustomField object which loaded this CustomFieldValue.
+Passed down from the CustomFieldValues collection in AddRecord.
+
+This object will be transparently returned from CustomFieldObj rather
+than loading from the database.
+
=cut
+sub SetCustomFieldObj {
+ my $self = shift;
+ return $self->{'custom_field'} = shift;
+}
=head2 CustomFieldObj
-Returns the CustomField Object which has the id returned by CustomField
+If a CustomField object was stored using SetCustomFieldObj and it is
+the same CustomField stored in the CustomField column, then the stored
+CustomField object (likely passed down from CustomField->Values) will be returned.
+Otherwise returns the CustomField Object which has the id returned by CustomField
=cut
sub CustomFieldObj {
my $self = shift;
+
+ return $self->{custom_field} if $self->{custom_field}
+ and $self->{custom_field}->id == $self->__Value('CustomField');
+
my $CustomField = RT::CustomField->new($self->CurrentUser);
$CustomField->Load($self->__Value('CustomField'));
return($CustomField);
@@ -307,7 +326,6 @@ sub FindDependencies {
$deps->Add( out => $self->CustomFieldObj );
}
-
RT::Base->_ImportOverlays();
1;
diff --git a/lib/RT/CustomFieldValues.pm b/lib/RT/CustomFieldValues.pm
index 9a49482..f0426dc 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->SetCustomFieldObj($self->CustomFieldObject);
+
+ push @{$self->{'items'}}, $CFV;
+ $self->{'rows'}++;
+}
+
RT::Base->_ImportOverlays();
-----------------------------------------------------------------------
More information about the rt-commit
mailing list