Skip to content

events.xml event with exclude param #1684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
michsk opened this issue Aug 15, 2015 · 4 comments
Closed

events.xml event with exclude param #1684

michsk opened this issue Aug 15, 2015 · 4 comments
Labels
Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed

Comments

@michsk
Copy link

michsk commented Aug 15, 2015

I would like to hook on the event core_collection_abstract_load_before. But in my observer i would like to inject the \Magento\Backend\Model\Auth, so i can get the logged in admin. This gives problems because Somewhere in the injecting process of Auth, we try to inject the StoreManager which itself again tries to load a collection of stores. This breaks the whole process and means i will have to manually define all the events that use load_before, but than with the event_prefix.

Defining an except in the <event> tag would result in less work. We could even make it accept a list?

    <event name="core_collection_abstract_load_before" exclude="store_collection_load_before">
        <observer name="foo_bar_event_prefixed_collection_load_before" instance="Foo\Bar\Model\Observer" method="coreCollectionLoadBefore" />
    </event>

Or is maybe something already possible?

@michsk michsk changed the title events.xml event with except param events.xml event with exclude param Aug 15, 2015
@michsk
Copy link
Author

michsk commented Aug 16, 2015

This comes down to not being able to use core_collection_abstract_load_before and injecting a session related class in the observer. Keep getting Store Manager has been initialized not properly. What could be another way to check in my observer if a admin is loggedin and get the admin user.

@michsk
Copy link
Author

michsk commented Aug 18, 2015

Ok. So i wanted to observer core_collection_abstract_load_before and inject \Magento\Backend\Model\Auth in my observer. But since we listen to a very generic event, this become problematic when magento was loading websites, groups, stores and config (magento loads config to get session related settings).

This is how i overcome this issue and am able to use the observer as generic as posible:

<?php
namespace Ms\User\Model;

class InvokerPlugin
{
    public function beforeDispatch(
        \Magento\Framework\Event\Invoker\InvokerDefault $subject,
        array $configuration,
        \Magento\Framework\Event\Observer $observer
    ) {
        if ($configuration['instance'] !== 'Ms\User\Model\Observer') {
            return [$configuration, $observer];
        }

        $c = $observer->getCollection();

        switch (true) {
            case $c instanceof \Magento\Store\Model\Resource\Website\Collection:
            case $c instanceof \Magento\Store\Model\Resource\Group\Collection:
            case $c instanceof \Magento\Store\Model\Resource\Store\Collection:
            case $c instanceof \Magento\Store\Model\Resource\Config\Collection\Scoped:
                $configuration['disabled'] = true;
                return [$configuration, $observer];
                break;
        }
}

Excluding the store related collection because of Store Manager has been initialized not properly and the config because of a Circular dependency LogicException. My question remains tough. What would be a good way to handle this situation. Why i dont want to call all the observer with there event_name prefixed is because not all collections have a event_name which would not call my observer. The way i handled it now has a hacky taste to it, tough working nice. We could ofcourse solve this with excluding events, tough that would give the same issue, what if you want to exclude an event that does not have a event_name.

@michsk
Copy link
Author

michsk commented Aug 21, 2015

Gues i wasn't the only one with this problem; 'Magento\Store\Model\Resource\Website\Collection::getLoadDefault to the rescue.

@michsk michsk closed this as completed Aug 21, 2015
okorshenko pushed a commit that referenced this issue Nov 8, 2017
Public Pull Requests

#11725 #9768: Admin dashboard Most Viewed Products Tab only gives default attribute set's products by @RomaKis

Fixed Public Issues

#9768 Admin dashboard Most Viewed Products Tab only gives default attribute set's products
yolouiese added a commit to yolouiese/magento2 that referenced this issue Aug 5, 2020
yolouiese added a commit to yolouiese/magento2 that referenced this issue Aug 6, 2020
@magento-engcom-team
Copy link
Contributor

@magento-engcom-team magento-engcom-team added Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Aug 15, 2020
magento-engcom-team added a commit that referenced this issue Aug 15, 2020
 - Merge Pull Request #29398 from yolouiese/magento2:1684-login-error-message-contains-html-tags
 - Merged commits:
   1. deb001c
   2. b5550cc
   3. cc94133
   4. 2d0bbad
   5. 811c4ad
   6. 88923fa
   7. 07dd895
   8. ad3da2d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed
Projects
None yet
Development

No branches or pull requests

3 participants