@@ -54,6 +54,9 @@ abstract class PluginFormcreatorTargetBase extends CommonDBTM implements PluginF
5454
5555 protected $ form = null ;
5656
57+ /** @var boolean $skipCreateActors Flag to disable creation of actors after creation of the item */
58+ protected $ skipCreateActors = false ;
59+
5760 abstract public function export ($ remove_uuid = false );
5861
5962 abstract public function save (PluginFormcreatorFormAnswer $ formanswer );
@@ -1134,7 +1137,11 @@ protected function showActorsSettings() {
11341137 $ itemActor = $ this ->getItem_Actor ();
11351138 $ itemActorTable = $ itemActor ::getTable ();
11361139 $ fk = self ::getForeignKeyField ();
1137- $ actors = ['requester ' => [], 'observer ' => [], 'assigned ' => []];
1140+ $ actors = [
1141+ PluginFormcreatorTarget_Actor::ACTOR_ROLE_REQUESTER => [],
1142+ PluginFormcreatorTarget_Actor::ACTOR_ROLE_OBSERVER => [],
1143+ PluginFormcreatorTarget_Actor::ACTOR_ROLE_ASSIGNED => [],
1144+ ];
11381145 $ result = $ DB ->request ([
11391146 'SELECT ' => ['id ' , 'actor_role ' , 'actor_type ' , 'actor_value ' , 'use_notification ' ],
11401147 'FROM ' => $ itemActorTable ,
@@ -1195,7 +1202,7 @@ protected function showActorsSettings() {
11951202
11961203 // => Add requester form
11971204 echo '<form name="form_target" id="form_add_requester" method="post" style="display:none" action=" '
1198- . $ CFG_GLPI [ ' root_doc ' ] . '/plugins/formcreator/front/targetchange.form.php "> ' ;
1205+ . static :: getFormURL () . '"> ' ;
11991206
12001207 $ dropdownItems = ['' => Dropdown::EMPTY_VALUE ] + $ itemActor ::getEnumActorType ();
12011208 unset($ dropdownItems ['supplier ' ]);
@@ -1287,7 +1294,7 @@ protected function showActorsSettings() {
12871294 Html::closeForm ();
12881295
12891296 // => List of saved requesters
1290- foreach ($ actors [' requester ' ] as $ id => $ values ) {
1297+ foreach ($ actors [PluginFormcreatorTarget_Actor:: ACTOR_ROLE_REQUESTER ] as $ id => $ values ) {
12911298 echo '<div> ' ;
12921299 switch ($ values ['actor_type ' ]) {
12931300 case PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR :
@@ -1337,7 +1344,7 @@ protected function showActorsSettings() {
13371344
13381345 // => Add observer form
13391346 echo '<form name="form_target" id="form_add_watcher" method="post" style="display:none" action=" '
1340- . $ CFG_GLPI [ ' root_doc ' ] . '/plugins/formcreator/front/targetchange.form.php "> ' ;
1347+ . static :: getFormURL () . '"> ' ;
13411348
13421349 $ dropdownItems = ['' => Dropdown::EMPTY_VALUE ] + $ itemActor ::getEnumActorType ();
13431350 unset($ dropdownItems ['supplier ' ]);
@@ -1426,7 +1433,7 @@ protected function showActorsSettings() {
14261433 Html::closeForm ();
14271434
14281435 // => List of saved observers
1429- foreach ($ actors [' observer ' ] as $ id => $ values ) {
1436+ foreach ($ actors [PluginFormcreatorTarget_Actor:: ACTOR_ROLE_OBSERVER ] as $ id => $ values ) {
14301437 echo '<div> ' ;
14311438 switch ($ values ['actor_type ' ]) {
14321439 case PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR :
@@ -1476,7 +1483,7 @@ protected function showActorsSettings() {
14761483
14771484 // => Add assigned to form
14781485 echo '<form name="form_target" id="form_add_assigned" method="post" style="display:none" action=" '
1479- . $ CFG_GLPI [ ' root_doc ' ] . '/plugins/formcreator/front/targetchange.form.php "> ' ;
1486+ . static :: getFormURL () . '"> ' ;
14801487
14811488 $ dropdownItems = ['' => Dropdown::EMPTY_VALUE ] + $ itemActor ::getEnumActorType ();
14821489 Dropdown::showFromArray (
@@ -1589,7 +1596,7 @@ protected function showActorsSettings() {
15891596 Html::closeForm ();
15901597
15911598 // => List of saved assigned to
1592- foreach ($ actors [' assigned ' ] as $ id => $ values ) {
1599+ foreach ($ actors [PluginFormcreatorTarget_Actor:: ACTOR_ROLE_ASSIGNED ] as $ id => $ values ) {
15931600 echo '<div> ' ;
15941601 switch ($ values ['actor_type ' ]) {
15951602 case PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR :
@@ -1811,6 +1818,17 @@ protected function setTargetDueDate($data, PluginFormcreatorFormAnswer $formansw
18111818 return $ data ;
18121819 }
18131820
1821+ public function prepareInputForAdd ($ input ) {
1822+ if (isset ($ input ['_skip_create_actors ' ]) && $ input ['_skip_create_actors ' ]) {
1823+ $ this ->skipCreateActors = true ;
1824+ }
1825+ // generate a unique id
1826+ if (!isset ($ input ['uuid ' ])
1827+ || empty ($ input ['uuid ' ])) {
1828+ $ input ['uuid ' ] = plugin_formcreator_getUuid ();
1829+ }
1830+ }
1831+
18141832 public function prepareInputForUpdate ($ input ) {
18151833 global $ DB ;
18161834
@@ -1842,6 +1860,26 @@ public function prepareInputForUpdate($input) {
18421860 return $ input ;
18431861 }
18441862
1863+ public function post_addItem () {
1864+ if (!$ this ->skipCreateActors ) {
1865+ $ target_actor = $ this ->getItem_Actor ();
1866+ $ myFk = self ::getForeignKeyField ();
1867+ $ target_actor ->add ([
1868+ $ myFk => $ this ->getID (),
1869+ 'actor_role ' => PluginFormcreatorTarget_Actor::ACTOR_ROLE_REQUESTER ,
1870+ 'actor_type ' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_CREATOR ,
1871+ 'use_notification ' => '1 ' ,
1872+ ]);
1873+ $ target_actor = $ this ->getItem_Actor ();
1874+ $ target_actor ->add ([
1875+ $ myFk => $ this ->getID (),
1876+ 'actor_role ' => PluginFormcreatorTarget_Actor::ACTOR_ROLE_OBSERVER ,
1877+ 'actor_type ' => PluginFormcreatorTarget_Actor::ACTOR_TYPE_VALIDATOR ,
1878+ 'use_notification ' => '1 ' ,
1879+ ]);
1880+ }
1881+ }
1882+
18451883 protected static function getDeleteImage ($ id ) {
18461884 global $ CFG_GLPI ;
18471885
0 commit comments