:: Version 3.2.0 ::
Optional relationship on Portal
In this tutorial, we will see how to make an n:n relationship dynamically optional, based on Service Subcategories.
Let say that you want to request the user to select some Application Solutions when creating a UserRequest in the Portal, but only for some services subcategories, for the others, you don't want the user to be bothered with that.
-
Add a field
with_as
(enum yes/no) on the Service Subcategory, to store if the n:n relation “Application Solutions” must be prompted to the User -
Create an
applicationsolutions_list
LinkedSetIndirect on the UserRequest class and make it dependent ofservicesubcategory_id
-
Create an ExternalField
with_as
on User Request, to get the equivalent field fromservicesubcategory_id
-
Modify the Portal creation and modify forms for Ticket, to add
applicationsolutions_list
-
Overwrite UserRequest::GetAttributeFlags() to hide
applicationsolutions_list
when applicable
provides more details of each steps
Test the
behavior on Console ?
- Class UserRequest
-
public function GetInitialStateAttributeFlags($sAttCode, &$aReasons = array()) { if (($sAttCode == 'applicationsolutions_list') && \ContextTag::Check(\ContextTag::TAG_PORTAL) && $this->Get('with_as') =='no') { return(OPT_ATT_HIDDEN | parent::GetInitialStateAttributeFlags($sAttCode, $aReasons)); } return parent::GetInitialStateAttributeFlags($sAttCode, $aReasons); } public function GetAttributeFlags($sAttCode, &$aReasons = array(), $sTargetState = '') { if (($sAttCode == 'applicationsolutions_list') && \ContextTag::Check(\ContextTag::TAG_PORTAL) && $this->Get('with_as') =='no') { return(OPT_ATT_HIDDEN | parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState)); } return parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState); }
3_2_0/customization/portal_howto_dynamic_link.txt · Last
modified: 2024/08/13 09:54 (external edit)