From cf0e14a5e431755c3c4e65b88b553b94b0a388b0 Mon Sep 17 00:00:00 2001
From: Vinciane <vinciane.bizet@maarch.org>
Date: Mon, 4 Mar 2019 17:06:37 +0100
Subject: [PATCH] FIX #9511 Add template_target in checkEntities

---
 src/app/template/models/TemplateModelAbstract.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/app/template/models/TemplateModelAbstract.php b/src/app/template/models/TemplateModelAbstract.php
index f1511d7067c..3d4639c050a 100755
--- a/src/app/template/models/TemplateModelAbstract.php
+++ b/src/app/template/models/TemplateModelAbstract.php
@@ -241,8 +241,8 @@ abstract class TemplateModelAbstract
         'select'    => ['ta.value_field', 'e.entity_label'],
         'table'     => ['templates t','templates_association ta', 'entities e'],
         'left_join' => ['ta.template_id = t.template_id', 'e.entity_id = ta.value_field'],
-        'where'     => empty($data['template_id']) ? ['t.template_attachment_type = ?', 'value_field in (?)'] : ['t.template_attachment_type = ?', 'value_field in (?)', 't.template_id != (?)' ],
-        'data'      => empty($data['template_id']) ? [$data['template_attachment_type'], $data['entities']]   : [$data['template_attachment_type'], $data['entities'], $data['template_id']],
+        'where'     => empty($data['template_id']) ? ['t.template_target = ?', 't.template_attachment_type = ?', 'value_field in (?)'] : ['t.template_target = ?', 't.template_attachment_type = ?', 'value_field in (?)', 't.template_id != (?)' ],
+        'data'      => empty($data['template_id']) ? [$data['template_target'], $data['template_attachment_type'], $data['entities']]   : [$data['template_target'], $data['template_attachment_type'], $data['entities'], $data['template_id']],
         'groupBy'   => ['ta.value_field', 'e.entity_label']
         ]);       
         
-- 
GitLab