Skip to content

Commit 58abf2c

Browse files
author
Mykola Silin
authored
Merge branch '4.3.0-develop' into 1026-change-overwrite-templates-feature
2 parents fb7224b + ed59dc9 commit 58abf2c

File tree

37 files changed

+717
-194
lines changed

37 files changed

+717
-194
lines changed

resources/META-INF/plugin.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@
133133
<action id="MagentoInjectConstructorArgumentAction.Menu" class="com.magento.idea.magento2plugin.actions.generation.InjectConstructorArgumentAction">
134134
<add-to-group group-id="EditorPopupMenu"/>
135135
</action>
136+
<action id="MagentoCompareTemplate.Menu" class="com.magento.idea.magento2plugin.actions.comparator.CompareTemplateAction">
137+
<add-to-group group-id="EditorPopupMenu"/>
138+
</action>
136139

137140
<action id="CopyMagentoPath"
138141
class="com.magento.idea.magento2plugin.actions.CopyMagentoPath"

resources/fileTemplates/internal/Magento CLI Command Class.php.ft

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use Symfony\Component\Console\Output\OutputInterface;
1212
class ${NAME} extends Command
1313
{
1414
/**
15-
* @inheritDoc
15+
* Initialization of the command.
1616
*/
1717
protected function configure()
1818
{
@@ -22,7 +22,7 @@ class ${NAME} extends Command
2222
}
2323

2424
/**
25-
* CLI command description
25+
* CLI command description.
2626
*
2727
* @param InputInterface $input
2828
* @param OutputInterface $output

resources/fileTemplates/internal/Magento Collection Class.php.ft

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implemen
1717
protected $_eventPrefix = '${DB_NAME}_collection';
1818

1919
/**
20-
* @inheritdoc
20+
* Initialize collection model.
2121
*/
2222
protected function _construct()
2323
{

resources/fileTemplates/internal/Magento Data Model.php.ft

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ${NAME} #if (${EXTENDS})extends ${EXTENDS} #end #if (${IMPLEMENTS} && $has
1919
{
2020
#if (${PROPERTIES} && !$hasInterface)
2121
/**
22-
* String constants for property names
22+
* String constants for property names.
2323
*/
2424
#set ($properties = ${PROPERTIES})
2525
#foreach ($property in $properties.split(","))
@@ -41,17 +41,11 @@ class ${NAME} #if (${EXTENDS})extends ${EXTENDS} #end #if (${IMPLEMENTS} && $has
4141
#if(!($foreach.first))
4242

4343
#end
44-
#if ($hasInterface)
45-
/**
46-
* @inheritDoc
47-
*/
48-
#else
4944
/**
5045
* Getter for $propertyUpperCamel.
5146
*
5247
* @return $propertyType|null
5348
*/
54-
#end
5549
public function get$propertyUpperCamel(): ?$propertyType
5650
{
5751
#if($propertyType == 'string')
@@ -62,19 +56,13 @@ class ${NAME} #if (${EXTENDS})extends ${EXTENDS} #end #if (${IMPLEMENTS} && $has
6256
#end
6357
}
6458

65-
#if ($hasInterface)
66-
/**
67-
* @inheritDoc
68-
*/
69-
#else
7059
/**
7160
* Setter for $propertyUpperCamel.
7261
*
7362
* @param $propertyType|null $$propertyLowerCamel
7463
*
7564
* @return void
7665
*/
77-
#end
7866
public function set$propertyUpperCamel(?$propertyType $$propertyLowerCamel): void
7967
{
8068
$this->setData(self::$propertyUpperSnake, $$propertyLowerCamel);

resources/fileTemplates/internal/Magento Entity Search Results.php.ft

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@ use $use;
1414
class ${CLASS_NAME} extends ${PARENT_CLASS_NAME} implements ${INTERFACE_NAME}
1515
{
1616
/**
17-
* @inheritDoc
17+
* Set items list.
18+
*
19+
* @param array $items
20+
*
21+
* @return ${INTERFACE_NAME}
1822
*/
1923
public function setItems(array $items): ${INTERFACE_NAME}
2024
{
2125
return parent::setItems($items);
2226
}
2327

2428
/**
25-
* @inheritDoc
29+
* Get items list.
30+
*
31+
* @return array
2632
*/
2733
public function getItems(): array
2834
{

resources/fileTemplates/internal/Magento Grid Ui Component Action Column Class.php.ft

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ class ${CLASS_NAME} extends ${PARENT_CLASS}
2020

2121
/**
2222
* Url paths.
23-
* #@+
2423
*/
2524
private const EDIT_URL_PATH = '${EDIT_URL_PATH}';
2625
private const DELETE_URL_PATH = '${DELETE_URL_PATH}';
27-
/** #@- */
2826

2927
/**
3028
* @var ${URL}
@@ -55,7 +53,11 @@ class ${CLASS_NAME} extends ${PARENT_CLASS}
5553
}
5654

5755
/**
58-
* @inheritDoc
56+
* Prepare data source.
57+
*
58+
* @param array $dataSource
59+
*
60+
* @return array
5961
*/
6062
public function prepareDataSource(array $dataSource): array
6163
{

resources/fileTemplates/internal/Magento Model Class.php.ft

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implemen
1717
protected $_eventPrefix = '${DB_NAME}_model';
1818

1919
/**
20-
* @inheritdoc
20+
* Initialize magento model.
21+
*
22+
* @return void
2123
*/
2224
protected function _construct()
2325
{

resources/fileTemplates/internal/Magento Resource Model Class.php.ft

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ${NAME}#if (${EXTENDS}) extends ${EXTENDS}#end#if (${IMPLEMENTS}) implemen
1717
protected $_eventPrefix = '${DB_NAME}_resource_model';
1818

1919
/**
20-
* @inheritdoc
20+
* Initialize resource model.
2121
*/
2222
protected function _construct()
2323
{

resources/fileTemplates/internal/Magento UI Component Custom Data Provider Class.php.ft

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ class ${CLASS_NAME} extends ${EXTENDS}
7676
}
7777

7878
/**
79-
* @inheritDoc
79+
* Returns searching result.
80+
*
81+
* @return ${SEARCH_RESULT_FACTORY}
8082
*/
8183
public function getSearchResult()
8284
{
@@ -119,7 +121,9 @@ class ${CLASS_NAME} extends ${EXTENDS}
119121
}
120122
#else
121123
/**
122-
* @inheritDoc
124+
* Get data.
125+
*
126+
* @return array
123127
*/
124128
public function getData()
125129
{
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.comparator;
7+
8+
import com.intellij.diff.DiffDialogHints;
9+
import com.intellij.diff.DiffManager;
10+
import com.intellij.diff.chains.DiffRequestChain;
11+
import com.intellij.openapi.actionSystem.AnAction;
12+
import com.intellij.openapi.actionSystem.AnActionEvent;
13+
import com.intellij.openapi.actionSystem.PlatformDataKeys;
14+
import com.intellij.openapi.project.Project;
15+
import com.intellij.openapi.vfs.VfsUtil;
16+
import com.intellij.openapi.vfs.VirtualFile;
17+
import com.intellij.psi.PsiDirectory;
18+
import com.intellij.psi.PsiFile;
19+
import com.magento.idea.magento2plugin.MagentoIcons;
20+
import com.magento.idea.magento2plugin.actions.comparator.util.DiffRequestChainUtil;
21+
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
22+
import com.magento.idea.magento2plugin.magento.packages.Areas;
23+
import com.magento.idea.magento2plugin.project.Settings;
24+
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
25+
import com.magento.idea.magento2plugin.util.magento.area.AreaResolverUtil;
26+
import java.nio.file.Path;
27+
import org.apache.commons.lang3.StringUtils;
28+
import org.jetbrains.annotations.NotNull;
29+
import org.jetbrains.annotations.Nullable;
30+
31+
public class CompareTemplateAction extends AnAction {
32+
33+
public static final String ACTION_NAME = "Compare overridden template with the original one";
34+
public static final String ACTION_DESCRIPTION = "The Magento 2 overridden template comparing";
35+
36+
private static final String PHTML_EXTENSION = "phtml";
37+
protected VirtualFile selectedFile;
38+
protected VirtualFile originalFile;
39+
40+
/**
41+
* Compare template action constructor.
42+
*/
43+
public CompareTemplateAction() {
44+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
45+
}
46+
47+
/**
48+
* Updates the state of action.
49+
*
50+
* @param event AnActionEvent
51+
*/
52+
@SuppressWarnings("PMD.NPathComplexity")
53+
@Override
54+
public void update(final @NotNull AnActionEvent event) {
55+
setStatus(event, false);
56+
final Project project = event.getData(PlatformDataKeys.PROJECT);
57+
58+
if (project == null) {
59+
return;
60+
}
61+
62+
if (!Settings.isEnabled(project)) {
63+
return;
64+
}
65+
final PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
66+
67+
if (psiFile == null) {
68+
return;
69+
}
70+
final VirtualFile targetFileCandidate = psiFile.getVirtualFile();
71+
72+
if (targetFileCandidate == null) {
73+
return;
74+
}
75+
76+
if (!PHTML_EXTENSION.equals(targetFileCandidate.getExtension())) {
77+
return;
78+
}
79+
final Areas area = AreaResolverUtil.getForFileInCustomTheme(targetFileCandidate);
80+
81+
if (area == null) {
82+
return;
83+
}
84+
final String originalModuleName = getOriginalModuleName(project, psiFile);
85+
86+
final PsiDirectory originalModuleDirectory =
87+
new ModuleIndex(project).getModuleDirectoryByModuleName(originalModuleName);
88+
89+
if (originalModuleDirectory == null) {
90+
return;
91+
}
92+
final String originalFilePath = originalModuleDirectory.getVirtualFile().getPath()
93+
+ "/view/"
94+
+ area
95+
+ StringUtils.substringAfter(targetFileCandidate.getPath(), originalModuleName);
96+
97+
final VirtualFile origFileCandidate = VfsUtil.findFile(Path.of(originalFilePath), false);
98+
99+
if (origFileCandidate == null) {
100+
return;
101+
}
102+
selectedFile = targetFileCandidate;
103+
originalFile = origFileCandidate;
104+
this.setStatus(event, true);
105+
}
106+
107+
@Override
108+
public void actionPerformed(final @NotNull AnActionEvent event) {
109+
final Project project = event.getProject();
110+
111+
if (project == null || selectedFile == null || originalFile == null) {
112+
return;
113+
}
114+
final DiffRequestChain chain = DiffRequestChainUtil.createMutableChain(
115+
project,
116+
selectedFile,
117+
originalFile
118+
);
119+
120+
if (chain == null) {
121+
return;
122+
}
123+
DiffManager.getInstance().showDiff(
124+
project,
125+
chain,
126+
DiffDialogHints.DEFAULT
127+
);
128+
}
129+
130+
private @Nullable String getOriginalModuleName(
131+
final @NotNull Project project,
132+
final @NotNull PsiFile psiFile
133+
) {
134+
final PsiDirectory directory = psiFile.getContainingDirectory();
135+
136+
return GetModuleNameByDirectoryUtil.execute(directory, project);
137+
}
138+
139+
private void setStatus(final AnActionEvent event, final boolean status) {
140+
event.getPresentation().setVisible(status);
141+
event.getPresentation().setEnabled(status);
142+
}
143+
}

0 commit comments

Comments
 (0)