Development with eZ Publish and PhpStorm



I have always been a bit lazy. My teachers would scold me for always choosing the shortest route. I remember my teacher in woodworking-class complaining that I was more interested in tooling than the class itself. This was after I had turned the lathe into a sander to complete my work faster. While he wasn’t entirely wrong, I also believe I was onto something: Channeling my laziness into becoming more efficient. Sometimes this would easily turn into procrastination. Spending 5 hours to automate a 15 minute one-time job comes to mind, but there was also rewards to be had.

The eZ-plugin I created for PhpStorm has saved me a some hours of work, but then again I have probably spent over a 100 hours creating it. Luckily my motivation for creating it exceeds personal efficiency. Brushing up on my Java skills and learning a new framework has been a lot of fun.

Most of all I’m hoping it will make developing with eZ more enjoyable and efficient for other developers.

A little side note before we begin: If you are unfamiliar with the excellent Symfony2-plugin for Phpstorm, you should start there. The eZ-plugin is a natural extension of the Symfony2-plugin and sometimes also relies directly on it.

So why should you try it?

I have always been a firm believer that keeping the required mental-context for working on a project as small as possible, will make a developer more efficient. This leaves “room” to actually focus on the problem at hand instead of mentally crawling through code to find the exact name of a class or field, constantly scanning for syntax-errors etc...


Installation


Click “Browse repositories”


Search for “ez”, select plugin, install and restart PhpStorm.
Install the required bundle: composer require flageolett/ezcompletionbundle:1.0.*
Register said bundle with the kernel.


The plugin is disabled by default. I will tell you why later.
Replace “ezpublish/console” with “app/console” if you are using eZ-Platform.
Also enter the environment you will be using.
Uncheck “Disable for project”



Imagine seeing a message similar to this every time you open a non eZ-project. This is why the plugin is disabled by default.


No problem.
No problem.
No Problem.
No problem.
Chat is disabled for 1 second.

Solution: configure your interpreter: PhpStorm docs


This is actually where some of the fun begins. Interpreters in PhpStorm can be remote.
The eZ-plugin thus makes it possible for you to clear cache on a remote server without having to manually log in. You also have access to assetic.



After you have properly configured your interpreter, you can attempt to fetch the eZ-completions.



After fetching completions for the first time, you will also be able to configure the content-language in the plugin-settings. If you leave it blank, the default content-language will be used.

Now the real fun finally begins.

Examples of all available completions can be found in the following locations:

“vendor/flageolett/ezcompletionbundle/Examples”,
“vendor/flageolett/ezcompletionbundle/Resources/config”,
“vendor/flageolett/ezcompletionbundle/Resources/views/examples”.

Lets begin with a simple code-example:
As you can see, I’m about to initiate an intention for the variable “$content”.


@ContentType is very similar to @var, and may be put anywhere @var or @param is applicable.


Select your favourite content-type.
Lo and behold, PhpStorm knows the names of our fields.
The extra completions are completely transparent and does not mess with any other code-completions.

Your eyes do not deceive you. PhpStorm now also know the type of the field.

Make note of that eZ-completions are always requested within literals. This prevents every single symbol from showing up. If the completed value is numeric, the literals will be removed upon insertion. Clever huh?
Amongst other things there are also completions for criteria

I find completions for the config-resolver most time-saving.
eZ-completions are also searchable just like the regular ones.

While the @ContentType annotation should be in direct proximity to the variable in PHP, it can be placed anywhere within the current file in twig.
Field-completions in twig are also really helpful.
What’s that? You’re tired of all the @ContentType in your code?
Notice the match-type “folder” which is configured here.

In twig, the plugin is able to autodetect the content-type based on the yml-rules.
Look mom! No @ContentType

Setting up template-rules has never been easier.

Similar completions are available for “template” and “match” as well.

While the eZ-plugin will work just fine without the Symfony2-plugin, this is some of the functionality which will not. Also you would be missing out on a lot of other great stuff.

I really hope this blog post has piqued your interest and that you will give it a try.
Feel free to contact me on community-slack (@whitefire) should you have any questions. Feature-suggestions and contributions to the project are more than most welcome. Everything is of course open-source.


Comments