Skip to content

See Tag Only On Active Itemtypes#221

Merged
stonebuzz merged 5 commits intopluginsGLPI:mainfrom
tsmr:SeeTagOnlyOnActiveItemtypes
Dec 26, 2024
Merged

See Tag Only On Active Itemtypes#221
stonebuzz merged 5 commits intopluginsGLPI:mainfrom
tsmr:SeeTagOnlyOnActiveItemtypes

Conversation

@tsmr
Copy link
Contributor

@tsmr tsmr commented Dec 19, 2024

  • [X ] I have performed a self-review of my code.
  • [X ] I have added tests (when available) that prove my fix is effective or that my feature works.

Description

By design you will see Tag dropdown on all objects, but in fact you nee to display the dropdown only on itemtypes with active tag

Copy link
Contributor

@stonebuzz stonebuzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @tsmr

if I remember correctly, if a tag is not linked to a specific itemtype, it means it is available for all objects in GLPI !

Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com>
@stonebuzz
Copy link
Contributor

@tsmr

can you try this

public static function canItemtype($itemtype = '')
{
    if (empty($itemtype) || !class_exists($itemtype) || in_array($itemtype, self::getBlacklistItemtype())) {
        return false;
    }

    $tags = new self();
    $types_menu = [];
    $use_global_tag = false;

    foreach ($tags->find(['is_active' => 1]) as $tag) {
        if (!empty($tag['type_menu'])) {
            $types_menu = array_merge($types_menu, json_decode($tag['type_menu']));
        } else {
            $use_global_tag = true;
        }
    }

    return $use_global_tag || in_array($itemtype, $types_menu);
}

@tsmr tsmr requested a review from stonebuzz December 21, 2024 11:42
@stonebuzz stonebuzz merged commit d002f1c into pluginsGLPI:main Dec 26, 2024
3 checks passed
@tsmr tsmr deleted the SeeTagOnlyOnActiveItemtypes branch December 30, 2024 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants