1111import com .jetbrains .php .lang .psi .elements .PhpClass ;
1212import fr .adrienbrault .idea .symfony2plugin .Symfony2Icons ;
1313import fr .adrienbrault .idea .symfony2plugin .Symfony2ProjectComponent ;
14+ import fr .adrienbrault .idea .symfony2plugin .doctrine .EntityHelper ;
1415import fr .adrienbrault .idea .symfony2plugin .util .PhpElementsUtil ;
1516import fr .adrienbrault .idea .symfony2plugin .util .controller .ControllerIndex ;
1617import fr .adrienbrault .idea .symfony2plugin .util .yaml .YamlHelper ;
@@ -37,6 +38,7 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNu
3738 for (PsiElement psiElement : psiElements ) {
3839 attachRouteActions (lineMarkerInfos , psiElement );
3940 attachEntityClass (lineMarkerInfos , psiElement );
41+ attachRelationClass (lineMarkerInfos , psiElement );
4042 }
4143
4244 }
@@ -119,4 +121,53 @@ public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) {
119121 return null ;
120122 }
121123
124+ /**
125+ * Set linemarker for targetEntity in possible yaml entity files
126+ *
127+ * foo:
128+ * targetEntity: Class
129+ */
130+ private void attachRelationClass (Collection <LineMarkerInfo > lineMarkerInfos , PsiElement psiElement ) {
131+
132+ if (!(psiElement instanceof YAMLKeyValue )) {
133+ return ;
134+ }
135+
136+ String keyText = ((YAMLKeyValue ) psiElement ).getKeyText ().toLowerCase ();
137+ if (!keyText .equals ("targetentity" )) {
138+ return ;
139+ }
140+
141+ String valueText = ((YAMLKeyValue ) psiElement ).getValueText ();
142+ if (StringUtils .isBlank (valueText )) {
143+ return ;
144+ }
145+
146+ PsiFile containingFile = psiElement .getContainingFile ();
147+ String fileName = containingFile .getName ();
148+ if (!(fileName .endsWith ("orm.yml" ) || fileName .endsWith ("odm.yml" ) || fileName .endsWith ("mongodb.yml" ))) {
149+ return ;
150+ }
151+
152+ PhpClass phpClass = PhpElementsUtil .getClass (psiElement .getProject (), EntityHelper .getYamlOrmClass (containingFile , valueText ));
153+ if (phpClass != null ) {
154+ PsiFile psiFile = EntityHelper .getModelConfigFile (phpClass );
155+ if (psiFile != null ) {
156+
157+ NavigationGutterIconBuilder <PsiElement > builder = NavigationGutterIconBuilder .create (Symfony2Icons .DOCTRINE_LINE_MARKER ).
158+ setTargets (psiFile ).
159+ setTooltipText ("Navigate to file" );
160+
161+ // get relation key
162+ PsiElement parent = psiElement .getParent ();
163+ if (parent != null ) {
164+ PsiElement parent1 = parent .getParent ();
165+ if (parent1 != null ) {
166+ lineMarkerInfos .add (builder .createLineMarkerInfo (parent1 ));
167+ }
168+ }
169+ }
170+ }
171+ }
172+
122173}
0 commit comments