getEventManager example

$entityManager->flush();

        // As of Shopware 4.1.3 clearing the cache via event is possible. As this is quite slow, however,         // this function is optional and disabled by default.         $clearCache = $this->getConfig()->getByNamespace('SwagMultiEdit', 'clearCache', false);
        if (!$clearCache) {
            return;
        }

        // Notify event - you might want register for this in order to clear the cache?         foreach ($this->getDqlHelper()->getIdForForeignEntity('article', $detailIds) as $productId) {
            $this->getDqlHelper()->getEventManager()->notify(
                'Shopware_Plugins_HttpCache_InvalidateCacheId',
                ['subject' => $this, 'cacheId' => 'a' . $productId]
            );
        }
    }

    /** * Batch processes a given queue * * @param int $queueId * * @throws RuntimeException * * @return array{totalCount: int, remaining: int, done: bool, processed: int} */

    public static function createInstance(
        Connection $conn,
        Configuration $config,
        ?EventManager $eventManager = null,
        ?QueryOperatorValidator $operatorValidator = null
    ) {
        if (!$config->getMetadataDriverImpl()) {
            throw new MissingMappingDriverImplementation();
        }

        if ($eventManager !== null && $conn->getEventManager() !== $eventManager) {
            throw new MismatchedEventManager();
        }

        if ($operatorValidator === null) {
            $operatorValidator = new QueryOperatorValidator();
        }

        return new self($conn$config$operatorValidator);
    }

    /** * @return DBALQueryBuilder */
break;
            case Shopware\Models\Form\Field::class:
                $cacheIds[] = 'f' . $entity->getFormId();
                break;
        }

        foreach ($cacheIds as $cacheId) {
            $this->cacheInvalidationBuffer[$cacheId] = true;
        }

        $entityManager = Shopware()->Container()->get(ModelManager::class);
        $entityManager->getEventManager()->addEventListener(['postFlush']$this);
    }

    /** * Helper function to enable the http cache for a single shopware controller. * * @param int $cacheTime * @param array $cacheIds * * @return void */
    public function enableControllerCache($cacheTime = 3600, $cacheIds = [])
    {
/** * Executes this context by calling the 'before' hooks, 'replace' hooks and 'after' hooks in that order and * returning the args' return value. */
    public function execute()
    {
        // Save this context in the proxy         $proxy = $this->args->getSubject();
        $proxy->__pushHookExecutionContext($this->args->getMethod()$this);

        // Before hooks         $this->hookManager->getEventManager()->notify(
            $this->getHookEventName(Enlight_Hook_HookHandler::TypeBefore),
            $this->args
        );

        // Replace hooks and/or original method         $this->args->setProcessed(false);
        $returnValue = $this->executeReplaceChain($this->args->getArgs());
        $this->args->setReturn($returnValue);
        $this->args->setProcessed(true);

        // After hooks
$a = $a['position'];
                $b = $b['position'];
                if ($a == $b) {
                    return 0;
                }

                return ($a > $b) ? 1 : -1;
            }
        );

        // Allow users to add his own columns         $result = $this->getEventManager()->filter(
            'SwagMultiEdit_Product_DqlHelper_getColumnsForProductListing_filterColumns',
            $result,
            ['subject' => $this, 'defaultColumns' => $shownColumns]
        );

        return $this->columnInfo = $result;
    }

    /** * Return column info for a given alias * * @param string $alias * * @return array|false */
$attributes[$formattedColumn] = ['ISTRUE', 'ISFALSE', 'ISNULL'];
                    break;
                case 'date':
                    $attributes[$formattedColumn] = ['>', '>=', '<', '<=', '=', 'ISNULL'];
                    break;
                case 'datetime':
                    $attributes[$formattedColumn] = ['>', '>=', '<', '<=', '=', 'ISNULL'];
                    break;
                default:
                    // Allow custom types. If not event handles the unknown type                     // an exception will be thrown                     if ($event = $this->getEventManager()->notifyUntil(
                        'SwagMultiEdit_Product_Grammar_generateAttributesFromColumns_Type_' . ucfirst(strtolower($type)),
                        [
                            'subject' => $this,
                            'type' => $type,
                            'mapping' => $mapping,
                        ]
                    )) {
                        $attributes[$formattedColumn] = $event->getReturn();
                    } else {
                        throw new RuntimeException(sprintf('Column with type %s was not configured, yet', $type));
                    }
            }
Home | Imprint | This part of the site doesn't use cookies.