enriquepiatti / Magicento

PHPStorm plugin for Magento developers
115 stars 35 forks source link

[Magicento2] Add new action - create observer for event #248

Closed Koc closed 7 years ago

Koc commented 7 years ago

Also there is no autocomplete for classes

<!-- /fronted/events.xml -->
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="layout_render_before_catalog_category_view">
        <observer name="brouzie_satin" instance="NO AUTOCOMPLETE OF CLASS NAME HERE" />
    </event>
</config>
enriquepiatti commented 7 years ago

There is an intention to create observers: Create Observer intention. Use ALT+ENTER when cursor is over some eventname string in dispatch method and select Create Observer. ->dispatch('[ALT+ENTER HERE]') I'm working on better autocomplete for XML files too

Koc commented 7 years ago

IMHO this is not intuitive behavior. Some actions available on alt+m, some on ctrl+enter. Also sometimes is impossible generate observer for events like

$this->eventManager->dispatch('layout_render_before_' . $this->request->getFullActionName());

Better to be consistent: add new action alt+m - create observer (below search events) with event name field wich autocompletes events

enriquepiatti commented 7 years ago

@Koc is consistent with the way PhpStorm works. PhpStorm uses intention actions (ALT+ENTER shortcut) to create code depending on the element under current cursor position, PhpStorm allows to create a method, property, class etc in this way, and Magicento is adding things like observers, dependencies, plugins etc. Magicento tries to extend all the normal shortcuts from PhpStorm, that's why you can use CTRL+SPACE for autocomplete, or CTRL+B to jump to some element etc. ALT+M is a special shortcut for things that are not compatible with any other shortcut from PhpStorm, like creating a new Module, Controller, Grids, Execute PHP actions (template hints, etc), or jump to other files based con current file (not current element), etc. I highly recommend to read the changelog from Magicento, all the features are explained there, I know it's boring but is the only way you can get the major benefits from the plugin (and you can be always up to date with features just reading the new changelog when you update)

enriquepiatti commented 7 years ago

regarding to that event, is really hard to guess what is the full event name when it's dynamic like in that case

Koc commented 7 years ago

Generated class namespace duplicates Observer subnamespace

<?php

namespace Brouzie\PrimaryCategory\Observer\Observer; // observer twice

use Magento\Framework\Event\ObserverInterface;

class CatalogProductCollectionLoadAfter implements ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        // ...
    }
}
enriquepiatti commented 7 years ago

fixed in 1.6.0