From f2b33ffd5528271be2567377095ade1925c19739 Mon Sep 17 00:00:00 2001 From: Mathieu Moulin Date: Mon, 4 Nov 2024 23:52:10 +0100 Subject: [PATCH] Fix use of extrafield of type link with CommonObjectLine (#29957) * define default getNomUrl() in CommonObjectLine class * Fix mistakes (pre-commit...) and precise function description * Fix CommonObjectLine::getNomUrl to be useable with existing * Update commonobjectline.class.php * Update commonobjectline.class.php * Update commonobjectline.class.php --------- Co-authored-by: Laurent Destailleur --- htdocs/core/class/commonobjectline.class.php | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php index 7e9adc49a8b..39922f4f1a9 100644 --- a/htdocs/core/class/commonobjectline.class.php +++ b/htdocs/core/class/commonobjectline.class.php @@ -330,4 +330,25 @@ abstract class CommonObjectLine extends CommonObject { return -1; // NOK because nothing done. } + + /** + * Return clicable link of object line (with eventually picto) + * May (should) also return information about the associated "parent" object. + * To overload + * + * @param int $withpicto Add picto into link + * @return string String with URL + */ + public function getNomUrl($withpicto = 0) + { + $parent_element_properties = getElementProperties($this->parent_element); + $parent_classname = $parent_element_properties['classname']; + $parent_element = new $parent_classname($this->db); + $parentattribute = $this->fk_parent_attribute; + if ($parentattribute) { + $parent_element->fetch($this->$parentattribute); + } + + return $parent_element->getNomUrl($withpicto).' - Line #'.$this->id; + } }