Skip to content

Commit bfc66df

Browse files
committed
add linemarker for doctrine yaml relation
1 parent 8e827e2 commit bfc66df

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/fr/adrienbrault/idea/symfony2plugin/doctrine/EntityHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public static void attachYamlFieldTypeName(String keyName, DoctrineModelField do
188188

189189
}
190190

191-
private static String getYamlOrmClass(PsiFile yamlFile, String className) {
191+
public static String getYamlOrmClass(PsiFile yamlFile, String className) {
192192

193193
// force global namespace not need to search for class
194194
if(className.startsWith("\\")) {

src/fr/adrienbrault/idea/symfony2plugin/routing/YamlLineMarkerProvider.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.jetbrains.php.lang.psi.elements.PhpClass;
1212
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
1313
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
14+
import fr.adrienbrault.idea.symfony2plugin.doctrine.EntityHelper;
1415
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
1516
import fr.adrienbrault.idea.symfony2plugin.util.controller.ControllerIndex;
1617
import 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

Comments
 (0)