Skip to content
Browse files

MINOR Argument checks in AssetTableField->getCustomFieldsFor() (AIR-40)

  • Loading branch information...
1 parent 3809c16 commit de13f144fad3ac78fcdd085f390c681e05c66a73 @chillu chillu committed Aug 26, 2011
Showing with 10 additions and 1 deletion.
  1. +10 −1 code/forms/AssetTableField.php
View
11 code/forms/AssetTableField.php
@@ -149,6 +149,10 @@ function getCustomFieldsFor($childData) {
return null;
}
+ if(!$childData instanceof File) {
+ throw new InvalidArgumentException(sprintf('$childData is of class "%s", subclass of "File" expected', get_class($childData)));
+ }
+
if($childData->ParentID) {
$folder = DataObject::get_by_id('File', $childData->ParentID );
} else {
@@ -207,10 +211,15 @@ function getCustomFieldsFor($childData) {
$links = $childData->BackLinkTracking();
if(class_exists('Subsite')) Subsite::disable_subsite_filter(false);
+ $linkArray = array();
if($links && $links->exists()) {
$backlinks = array();
foreach($links as $link) {
- $backlinks[] = "<li><a href=\"admin/show/$link->ID\">" . $link->Breadcrumbs(null,true). "</a></li>";
+ // Avoid duplicates
+ if (!in_array($link->ID, $linkArray)) {
+ $backlinks[] = "<li><a href=\"admin/show/$link->ID\">" . $link->Breadcrumbs(null,true). "</a></li>";
+ $linkArray[] = $link->ID;
+ }
}
$backlinks = "<div style=\"clear:left\">". _t('AssetTableField.PAGESLINKING','The following pages link to this file:') ."<ul>" . implode("",$backlinks) . "</ul></div>";
}

0 comments on commit de13f14

Please sign in to comment.
Something went wrong with that request. Please try again.