NEW Output of category tag is nicer for long subcategories.

This commit is contained in:
Laurent Destailleur 2025-10-29 16:50:09 +01:00
parent 4fd6894210
commit d0c4d2d8b4
17 changed files with 41 additions and 27 deletions

View file

@ -274,7 +274,7 @@ if ($action == 'edit') {
if ($result < 0) {
setEventMessages(null, $c->errors, 'errors');
}
$ways = $c->print_all_ways(' &gt;&gt; ', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
$ways = $c->print_all_ways('auto', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
$toprint = array();
foreach ($ways as $way) {
$toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '</li>';

View file

@ -629,7 +629,7 @@ if ($action != 'editxxx') {
if ($result < 0) {
setEventMessages(null, $c->errors, 'errors');
}
$ways = $c->print_all_ways(' &gt;&gt; ', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
$ways = $c->print_all_ways('auto', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
$toprint = array();
foreach ($ways as $way) {
$toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '</li>';

View file

@ -319,7 +319,7 @@ if ($action == 'edit') {
if ($result < 0) {
setEventMessages(null, $c->errors, 'errors');
}
$ways = $c->print_all_ways(' &gt;&gt; ', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
$ways = $c->print_all_ways('auto', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
$toprint = array();
foreach ($ways as $way) {
$toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '</li>';

View file

@ -622,7 +622,7 @@ if ($action == 'edit') {
if ($result < 0) {
setEventMessages(null, $c->errors, 'errors');
} elseif ($result > 0) {
$ways = $c->print_all_ways(' &gt;&gt; ', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
$ways = $c->print_all_ways('auto', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
$toprint = array();
foreach ($ways as $way) {
$toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '</li>';

View file

@ -1533,17 +1533,22 @@ class Categorie extends CommonObject
* Returns the path of the category, with the names of the categories
* separated by $sep (" >> " by default)
*
* @param string $sep Separator
* @param string $url Url ('', 'none' or 'urltouse')
* @param int $nocolor 0
* @param int $addpicto Add picto into link
* @param string $sep Separator
* @param string $url Url ('', 'none' or 'urltouse')
* @param int $nocolor 0
* @param int $addpicto Add picto into link
* @param int $notrunc Do not truncate names of parent categories
* @return string[]
*/
public function print_all_ways($sep = '&gt;&gt;', $url = '', $nocolor = 0, $addpicto = 0)
public function print_all_ways($sep = 'auto', $url = '', $nocolor = 0, $addpicto = 0, $notrunc = 0)
{
// phpcs:enable
$ways = array();
if ($sep == 'auto') {
$sep = '&gt;';
}
$all_ways = $this->get_all_ways(); // Load array of categories to reach this->id
foreach ($all_ways as $way) { // It seems we always have 1 entry in this array.
@ -1567,13 +1572,21 @@ class Categorie extends CommonObject
}
if ($url == '') {
$link = '<a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.((int) $cat->id).'&type='.urlencode($cat->type).'" class="'.($i < count($way) ? 'small ' : '').$forced_color.'">';
$linkend = '</a>';
$w[] = $link.(($addpicto && $i == 1) ? img_object('', 'category', 'class="paddingright"') : '').$cat->label.$linkend;
if (($i < count($way) && empty($notrunc)) && $i > 1) {
$link = '';
$linkend = '';
} else {
$link = '<a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.((int) $cat->id).'&type='.urlencode($cat->type).'" class="'.(($i < count($way) && empty($notrunc)) ? 'small ' : '').$forced_color.'">';
$linkend = '</a>';
}
$s = $link.(($addpicto && $i == 1) ? img_object('', 'category', 'class="paddingright"') : '');
$s .= (($i < count($way) && empty($notrunc)) ? ($i == 1 ? dol_trunc($cat->label, 3) : '') : $cat->label);
$s .= $linkend;
$w[] = $s;
} elseif ($url == 'none') {
$link = '<span class="valignmiddle '.($i < count($way) ? 'small ' : '').$forced_color.'">';
$linkend = '</span>';
$w[] = $link.(($addpicto && $i == 1) ? img_object('', 'category', 'class="paddingright"') : '').$cat->label.$linkend;
$w[] = $link.(($addpicto && $i == 1) ? img_object('', 'category', 'class="paddingright"') : '').($i < count($way) ? $cat->label : $cat->label).$linkend;
} else {
$w[] = '<a class="valignmiddle '.($i < count($way) ? 'small ' : '').$forced_color.'" href="'.DOL_URL_ROOT.'/'.$url.'?catid='.((int) $cat->id).'">'.($addpicto ? img_object('', 'category') : '').$cat->label.'</a>';
}

View file

@ -89,7 +89,7 @@ $linkback = '<a href="'.dol_sanitizeUrl($backtolist).'">'.$langs->trans("BackToL
$object->next_prev_filter = 'type:=:'.((int) $object->type);
$object->ref = $object->label;
$morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/categorie_list.php?leftmenu=cat&type='.urlencode($type).'">'.$langs->trans("Root").'</a> >> ';
$ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
$ways = $object->print_all_ways("auto", '', 1);
foreach ($ways as $way) {
$morehtmlref .= $way."<br>\n";
}

View file

@ -140,7 +140,7 @@ if ($object->id) {
$object->next_prev_filter = 'type:=:'.((int) $object->type);
$object->ref = $object->label;
$morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/categorie_list.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
$ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
$ways = $object->print_all_ways("auto", '', 1);
foreach ($ways as $way) {
$morehtmlref .= $way."<br>\n";
}

View file

@ -216,7 +216,7 @@ $linkback = '<a href="'.dol_sanitizeUrl($backtolist).'">'.$langs->trans("BackToL
$object->next_prev_filter = 'type:=:'.((int) $object->type);
$object->ref = $object->label;
$morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/categorie_list.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
$ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
$ways = $object->print_all_ways("auto", '', 1);
foreach ($ways as $way) {
$morehtmlref .= $way."<br>\n";
}

View file

@ -324,8 +324,9 @@ $backtolist = (GETPOST('backtolist') ? GETPOST('backtolist') : DOL_URL_ROOT.'/ca
$linkback = '<a href="'.dol_sanitizeUrl($backtolist).'">'.$langs->trans("BackToList").'</a>';
$object->next_prev_filter = 'type:=:'.((int) $object->type);
$object->ref = $object->label;
$morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/categorie_list.php?leftmenu=cat&type='.urlencode($type).'">'.$langs->trans("Root").'</a> >> ';
$ways = $object->print_all_ways(" &gt;&gt; ", '', 1);
$morehtmlref = '<br><div class="refidno"><a href="'.DOL_URL_ROOT.'/categories/categorie_list.php?leftmenu=cat&type='.urlencode($type).'">'.$langs->trans("Root").'</a>';
$morehtmlref .= ' > ';
$ways = $object->print_all_ways("auto", '', 1, 0, 1);
foreach ($ways as $way) {
$morehtmlref .= $way."<br>\n";
}

View file

@ -10134,7 +10134,7 @@ class Form
* Render list of categories linked to object with id $id and type $type
*
* @param int $id Id of object
* @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact'). Old mode (0, 1, 2, ...) is deprecated.
* @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact'). Old mode using number (0, 1, 2, ...) is deprecated.
* @param int<0,1> $rendermode 0=Default, use multiselect (deprecated). 1=Emulate multiselect (recommended)
* @param int<0,1> $nolink 1=Do not add html links
* @return string String with categories
@ -10149,7 +10149,7 @@ class Form
if ($rendermode == 1) {
$toprint = array();
foreach ($categories as $c) {
$ways = $c->print_all_ways(' &gt;&gt; ', ($nolink ? 'none' : ''), 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
$ways = $c->print_all_ways('auto', ($nolink ? 'none' : ''), 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
foreach ($ways as $way) {
$color = $c->color;
$sfortag = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($color ? ' style="background: #' . $color . ';"' : ' style="background: #bbb"') . '>';

View file

@ -1326,7 +1326,7 @@ class FormSetupItem
if ($result < 0) {
$this->setErrors($c->errors);
}
$ways = $c->print_all_ways(' &gt;&gt; ', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
$ways = $c->print_all_ways('auto', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
$toprint = array();
foreach ($ways as $way) {
$toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '</li>';

View file

@ -280,7 +280,7 @@ print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sort
if (!empty($catid)) {
print "<div id='ways'>";
$c = new Categorie($db);
$ways = $c->print_all_ways(' &gt; ', 'fourn/product/list.php');
$ways = $c->print_all_ways('auto', 'fourn/product/list.php');
print " &gt; ".$ways[0]."<br>\n";
print "</div><br>";
}

View file

@ -984,7 +984,7 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
if (!empty($catid)) {
print "<div id='ways'>";
$c = new Categorie($db);
$ways = $c->print_all_ways(' &gt; ', 'product/list.php');
$ways = $c->print_all_ways('auto', 'product/list.php');
print " &gt; ".$ways[0]."<br>\n";
print "</div><br>";
}

View file

@ -414,7 +414,7 @@ if ($resql) {
print "<div id='ways'>";
$c = new Categorie($db);
$c->fetch($search_categ);
$ways = $c->print_all_ways(' &gt; ', 'product/reassort.php');
$ways = $c->print_all_ways('auto', 'product/reassort.php');
print " &gt; ".$ways[0]."<br>\n";
print "</div><br>";
}

View file

@ -564,7 +564,7 @@ if ($search_categ > 0) {
print "<div id='ways'>";
$c = new Categorie($db);
$c->fetch($search_categ);
$ways = $c->print_all_ways(' &gt; ', 'product/reassortlot.php');
$ways = $c->print_all_ways('auto', 'product/reassortlot.php');
print " &gt; ".$ways[0]."<br>\n";
print "</div><br>";
}

View file

@ -1301,7 +1301,7 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
if (!empty($search_categ_cus) || !empty($search_categ_sup)) {
print "<div id='ways'>";
$c = new Categorie($db);
$ways = $c->print_all_ways(' &gt; ', 'societe/list.php');
$ways = $c->print_all_ways('auto', 'societe/list.php');
print " &gt; ".$ways[0]."<br>\n";
print "</div><br>";
}

View file

@ -708,7 +708,7 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
if (!empty($catid)) {
print "<div id='ways'>";
$c = new Categorie($db);
$ways = $c->print_all_ways(' &gt; ', 'user/list.php');
$ways = $c->print_all_ways('auto', 'user/list.php');
print " &gt; ".$ways[0]."<br>\n";
print "</div><br>";
}