Skip to content

Commit

Permalink
distinguish single massive actions
Browse files Browse the repository at this point in the history
  • Loading branch information
cconard96 committed Dec 7, 2024
1 parent 103a18c commit df2fbeb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/MassiveAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class MassiveAction
*/
private $current_itemtype;

private $from_single_item = false;

/**
* Constructor of massive actions.
* There is three stages and each one have its own objectives:
Expand All @@ -192,6 +194,8 @@ public function __construct(array $POST, array $GET, $stage, ?int $items_id = nu
/** @var array $CFG_GLPI */
global $CFG_GLPI;

$this->from_single_item = $GET['_from_single_item'] ?? false;

if (!empty($POST)) {
if (!isset($POST['is_deleted'])) {
$POST['is_deleted'] = 0;
Expand Down Expand Up @@ -1923,4 +1927,12 @@ public function itemDone($itemtype, $id, $result)

$this->updateProgressBars();
}

/**
* @return bool True if massive actions are running from a single item context such as the item's form.
*/
public function isFromSingleItem(): bool
{
return $this->from_single_item;
}
}
2 changes: 1 addition & 1 deletion src/Unmanaged.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public static function processMassiveActionsForOneItemtype(
$itemtype = $_POST['itemtype'];
$new_asset_id = $unmanaged->convert($id, $itemtype);
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
if (count($ids) === 1) {
if ($ma->isFromSingleItem()) {
$ma->setRedirect($itemtype::getFormURLWithID($new_asset_id));
} else {
$ma->setRedirect($item::getSearchURL());
Expand Down
2 changes: 1 addition & 1 deletion templates/components/form/header_content.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

{% if item.canEdit(item.fields['id']) %}
<form name="massaction_{{ rand }}" id="massaction_{{ rand }}" method="post"
action="{{ path('/front/massiveaction.php') }}" data-submit-once>
action="{{ path('/front/massiveaction.php') }}?_from_single_item=1" data-submit-once>
<div id="massive_container_{{ rand }}"></div>
<input type="hidden" name="_glpi_csrf_token" value="{{ csrf_token() }}" />
</form>
Expand Down
2 changes: 1 addition & 1 deletion templates/components/itilobject/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
{% endfor %}

<form name="massaction_{{ rand }}" id="massaction_{{ rand }}" method="post"
action="{{ path('/front/massiveaction.php') }}" data-submit-once>
action="{{ path('/front/massiveaction.php') }}?_from_single_item=1" data-submit-once>
<div id="massive_container_{{ rand }}"></div>
<input type="hidden" name="_glpi_csrf_token" value="{{ csrf_token() }}" />
</form>
Expand Down

0 comments on commit df2fbeb

Please sign in to comment.