N°3208 - Quick create: Fix error when choosing a class from another page than UI.php

This commit is contained in:
Molkobain
2021-01-26 20:15:25 +01:00
parent 0922baee7b
commit 8fba402016

View File

@@ -23,6 +23,7 @@ namespace Combodo\iTop\Application\UI\Base\Component\QuickCreate;
use Combodo\iTop\Application\UI\Base\UIBlock;
use MetaModel;
use UserRights;
use utils;
/**
* Class QuickCreate
@@ -49,6 +50,8 @@ class QuickCreate extends UIBlock
// Specific constants
public const DEFAULT_ENDPOINT_REL_URL = 'pages/UI.php';
/** @var string $sEndpoint Absolute endpoint URL of the creation form */
protected $sEndpoint;
/** @var array $aAvailableClasses */
protected $aAvailableClasses;
/** @var array $aLastClasses */
@@ -72,6 +75,7 @@ class QuickCreate extends UIBlock
public function __construct(array $aLastClasses = [], ?string $sId = null)
{
parent::__construct($sId);
$this->SetEndpoint(static::DEFAULT_ENDPOINT_REL_URL);
$this->aAvailableClasses = $this->FilterAvailableClasses(UserRights::GetAllowedClasses(UR_ACTION_CREATE, array('bizmodel'), true));
$this->aLastClasses = $aLastClasses;
$this->iMaxAutocompleteResults = (int) MetaModel::GetConfig()->Get('quick_create.max_autocomplete_results');
@@ -79,6 +83,34 @@ class QuickCreate extends UIBlock
$this->iMaxHistoryResults = (int) MetaModel::GetConfig()->Get('quick_create.max_history_results');
}
/**
* Set the creation form endpoint URL.
* If $bRelativeUrl is true, then $sEndpoint will be complete with the app_root_url
*
* @param string $sEndpoint URL to the endpoint
* @param bool $bRelativeUrl Whether or not the $sEndpoint parameter is a relative URL
*
* @return $this
* @throws \Exception
*/
public function SetEndpoint(string $sEndpoint, bool $bRelativeUrl = true)
{
$this->sEndpoint = (($bRelativeUrl) ? utils::GetAbsoluteUrlAppRoot() : '').$sEndpoint;
return $this;
}
/**
* Return the absolute URL of the creation form
*
* @return string
* @throws \Exception
*/
public function GetEndpoint()
{
return $this->sEndpoint;
}
/**
* Return the available classes (to create) for the current user
*