Adds the page's seo attributes when a new page is added, for each language of
the site

@param  BeforeAddPageCommitEvent $event
@return boolean
@throws InvalidArgumentException
@throws \Exception

@api
485452
public function onBeforeAddPageCommit(BeforeAddPageCommitEvent $event)
    {
        if ($event->isAborted()) {
            return;
        }

        $pageManager = $event->getContentManager();
        $pageRepository = $pageManager->getPageRepository();
        $values = $event->getValues();

        if (!is_array($values)) {
            throw new InvalidArgumentException('exception_invalid_value_array_required');
        }

        try {
            $languages = $this->languageRepository->activeLanguages();
            if (count($languages)) {
                $result = true;
                $idPage = $pageManager->get()->getId();
                $this->seoManager->getSeoRepository()->setConnection($pageRepository->getConnection());
                $pageRepository->startTransaction();
                foreach ($languages as $alLanguage) {
                    $seoManagerValues = array_merge($values, array('PageId' => $idPage, 'LanguageId' => $alLanguage->getId(), 'CreatedAt'       => date("Y-m-d H:i:s")));
                    if (!$alLanguage->getMainLanguage() && array_key_exists('Permalink', $seoManagerValues)) $seoManagerValues['Permalink'] = $alLanguage->getLanguageName() . '-' . $seoManagerValues['Permalink'];
                    $this->seoManager->set(null);
                    $result = $this->seoManager->save($seoManagerValues);

                    if (false === $result) break;
                }

                if (false !== $result) {
                    $pageRepository->commit();

                    return;
                }

                $pageRepository->rollBack();
                $event->abort();
            }
        } catch (\Exception $e) {
            $event->abort();

            if (isset($pageRepository) && $pageRepository !== null) {
                $pageRepository->rollBack();
            }

            throw $e;
        }
    }
425273
public function beforeAction($event)
    {
        if (in_array($event->action->id, $this->actions) || in_array('*', $this->actions)) {
            $sender = $event->sender;
            $command = $sender->id . '/' . $sender->action->id . $this->getActionParams();
            $this->schedule = new CronScheduleModel();
            $this->schedule->startCronSchedule($command);
            $this->setupApplicationErrorHandlers();
        }
    }
1270451
public function preUpdate(PreUpdateEventArgs $event)
    {
        $entity = $event->getEntity();
        if ($entity instanceof CategorizableInterface) {
            $this
                ->categoryIntegrityFixer
                ->fixCategoriesIntegrity($entity);
        }
    }
1116964
private function getBeforeEvent(BeforeEvent $event)
    {
        $request = $event->getRequest();

        if ('api.embed.ly' === $request->getHost()) {
            $requestQuery = $request->getQuery();

            $requestQuery->setEncodingType(false);
            $requestQuery->set('key', $this->apiKey);

            $request->setQuery($requestQuery);
        }
    }
453667
public function beforeApiRequestSend($event)
    {
        $request = $event->request;
        $data = $request->getData();
        $data['openid'] = $this->getOpenid();
        $request->setData($data);

        parent::beforeApiRequestSend($event);
    }
1118595
public function beforeFilter(\Cake\Event\Event $event)
    {
        parent::beforeFilter($event);

        $this->Auth->allow([]);
    }
771056
public function preAdd(Event $e)
    {
        $form = $e->getParam('form');
        /* @var $inputFilter \UthandoUser\InputFilter\UserInputFilter */
        $inputFilter = $form->getInputFilter();
        $inputFilter->addEmailNoRecordExists();
    }
214472
public function beforePaginate(Event $event)
    {
        $method = 'contain';
        if (method_exists($event->getSubject()->query, 'getContain')) {
            $method = 'getContain';
        }
        $contained = $event->getSubject()->query->$method();

        if (!empty($contained)) {
            return;
        }

        $models = $this->models();
        if (empty($models)) {
            return;
        }

        $event->getSubject()->query->contain(array_keys($models));
    }
180289
public function onContent(ContentEvent $event)
    {
        $content = null;
        $event->clearModules();
        $this->start('precontent_module');
        $this->eventDispatcher->dispatch('edemy_precontent_module', $event);
        var_dump('preContentModule: ' . $this->stop('precontent_module')->getDuration());

        $this->start('routeContent');
        $this->eventDispatcher->dispatch($event->getRoute(), $event);
        var_dump('routeContent ' . $event->getRoute() . ': ' . $this->stop('routeContent')->getDuration());

        //die(var_dump($event));
        if($event->isPropagationStopped()) {

            return false;
        }
        $this->start('postcontent_module');
        $this->eventDispatcher->dispatch('edemy_postcontent_module', $event);
        var_dump('postContentModule: ' . $this->stop('postcontent_module')->getDuration());
        $event->setContent(
            $this->render("snippets/join", array(
                'modules' => $event->getModules()
            ))
        );

        return true;
    }
1012513
public function onPageRendering(BeforePageRenderingEvent $event)
    {
        $response = $event->getResponse();

        $slotContents = $this->renderSlotContents();
        
        if (!is_array($slotContents)) {
            throw new \InvalidArgumentException('"renderSlotContents" method must return an array');
        }

        foreach ($slotContents as $slotContent) {
            $this->renderSlot($response, $slotContent);
        }

        $event->setResponse($response);
    }
689479
public function onBuildKernelWebHandler(PreBuildKernelWebHandlerEvent $event)
    {
        $siteAccess = $this->container->get('ezpublish.siteaccess');
        $request = $event->getRequest();
        $uriPart = [];

        // Convert matching type
        switch ($siteAccess->matchingType) {
            case 'default':
                $legacyAccessType = eZSiteAccess::TYPE_DEFAULT;
                break;

            case 'env':
                $legacyAccessType = eZSiteAccess::TYPE_SERVER_VAR;
                break;

            case 'uri:map':
            case 'uri:element':
            case 'uri:text':
            case 'uri:regexp':
                $legacyAccessType = eZSiteAccess::TYPE_URI;
                break;

            case 'host:map':
            case 'host:element':
            case 'host:text':
            case 'host:regexp':
                $legacyAccessType = eZSiteAccess::TYPE_HTTP_HOST;
                break;

            case 'port':
                $legacyAccessType = eZSiteAccess::TYPE_PORT;
                break;

            default:
                $legacyAccessType = eZSiteAccess::TYPE_CUSTOM;
        }

        // uri_part
        $pathinfo = str_replace($request->attributes->get('viewParametersString'), '', rawurldecode($request->getPathInfo()));
        $fragmentPathInfo = implode('/', $this->getFragmentPathItems());
        if ($fragmentPathInfo !== '_fragment') {
            $semanticPathinfo = $fragmentPathInfo;
        } else {
            $semanticPathinfo = $request->attributes->get('semanticPathinfo', $pathinfo);
        }

        $pos = mb_strrpos($pathinfo, $semanticPathinfo);
        if ($legacyAccessType !== eZSiteAccess::TYPE_DEFAULT && $pathinfo != $semanticPathinfo && $pos !== false) {
            if ($pos === 0) {
                $pos = mb_strlen($pathinfo) + 1;
            }
            $uriPart = mb_substr($pathinfo, 1, $pos - 1);
            $uriPart = explode('/', $uriPart);
        }

        // Handle host_uri match
        if ($siteAccess->matcher instanceof CompoundInterface) {
            $subMatchers = $siteAccess->matcher->getSubMatchers();
            if (!$subMatchers) {
                throw new \RuntimeException('Compound matcher used but not submatchers found.');
            }

            if (\count($subMatchers) == 2 && isset($subMatchers['Map\Host']) && isset($subMatchers['Map\URI'])) {
                $legacyAccessType = eZSiteAccess::TYPE_HTTP_HOST_URI;
                $uriPart = [$subMatchers['Map\URI']->getMapKey()];
            }
        }

        $event->getParameters()->set(
            'siteaccess',
            [
                'name' => $siteAccess->name,
                'type' => $legacyAccessType,
                'uri_part' => $uriPart,
            ]
        );
    }
1364162
public function addLocale(MvcEvent $event)
    {
        $locale = $this->siteService->getCurrentSite()->getLocale();

        $this->localeService->setLocale($locale);

        return null;
    }
44692
public function beforeApiRequestSend($event)
    {
        $accessToken = $this->getAccessToken();
        if (!is_object($accessToken) || !$accessToken->getIsValid()) {
            throw new Exception('Invalid access token.');
        }

        $this->applyAccessTokenToRequest($event->request, $accessToken);
    }
195576
public function onBefore(BeforeEvent $event)
    {
        $now       = new \DateTime;
        $createdAt = $now->format($this->getDateFormat());
        $request   = $event->getRequest();
        $nonce     = call_user_func($this->getNonce(), $request);
        $password  = $this->passwordProcessor ? call_user_func($this->passwordProcessor, $this->password) : $this->password;
        $digest    = call_user_func($this->getDigest(), $nonce, $createdAt, $password);

        $request->setHeader('Authorization', 'WSSE profile="UsernameToken"');
        $request->setHeader(
            'X-WSSE',
            $this->createWsseHeader(
                $this->username,
                $digest,
                $nonce,
                $createdAt
            )
        );
    }
857105
public function beforeSend($event = null)
    {
        if (isset($this->stream)) {
            return;
        }
        if (isset($this->controller) && $this->task) {
            if ($this->isInstructable) {
                $this->format = static::FORMAT_JSON;
                $this->data = $this->generateInstructions();
            } else {
                $this->handleFlashStatus();
                if ($this->redirect) {
                    $this->redirect($this->redirect);
                } elseif ($this->refresh) {
                    $this->refresh();
                } else {
                    if (is_null($this->content)) {
                        $this->content = $this->renderContent(true);
                    }
                }
            }
        }
    }
826789
public function onPreContentView(PreContentViewEvent $event): void
    {
        $currentRequest = $this->requestStack->getCurrentRequest();
        if (!$currentRequest instanceof Request) {
            return;
        }

        $view = $currentRequest->attributes->get('view');
        if (!$view instanceof ContentValueView) {
            return;
        }

        if ($currentRequest->attributes->get('viewType') !== 'full') {
            return;
        }

        $content = $view->getSiteContent();
        if (!$content->hasField('css_class') || $content->getField('css_class')->isEmpty()) {
            return;
        }

        $fieldValue = $content->getField('css_class')->value;
        if (!$fieldValue instanceof TextLineValue) {
            return;
        }

        $event->getContentView()->addParameters(
            [
                'page_css_class' => trim($fieldValue->text),
            ]
        );
    }
9143
public function beforeRender(Event $event)
    {
        $this->_beforeRender($event);
        $this->loadModel('Content.ContentTypes');
        $this->Breadcrumb->push('/admin/content/types');
        $contentType = $this->ContentTypes
            ->find()
            ->where(['slug' => $this->request->query['type']])
            ->first();

        switch ($this->request->action) {
            case 'index':
                $this->Breadcrumb
                    ->push('/admin/content/manage')
                    ->push(__d('content', 'Content Types'), '/admin/content/types')
                    ->push(__d('content', 'Type "{0}"', $contentType->name), '/admin/content/types/edit/' . $contentType->slug)
                    ->push(__d('content', 'Fields'), ['plugin' => 'Content', 'controller' => 'fields', 'action' => 'index', 'prefix' => 'admin']);
                break;

            case 'configure':
                $this->Breadcrumb
                    ->push('/admin/content/manage')
                    ->push(__d('content', 'Content Types'), '/admin/content/types')
                    ->push(__d('content', 'Type "{0}"', $contentType->name), '/admin/content/types/edit/' . $contentType->slug)
                    ->push(__d('content', 'Fields'), ['plugin' => 'Content', 'controller' => 'fields', 'action' => 'index', 'prefix' => 'admin'])
                    ->push(__d('content', 'Configure Field "{0}"', $this->viewVars['instance']->label), '#');
                break;

            case 'attach':
                $this->Breadcrumb
                    ->push('/admin/content/manage')
                    ->push(__d('content', 'Content Types'), '/admin/content/types')
                    ->push(__d('content', 'Type "{0}"', $contentType->name), '/admin/content/types/edit/' . $contentType->slug)
                    ->push(__d('content', 'Attach New Field'), '');
                break;

            case 'viewModeList':
                $this->Breadcrumb
                    ->push('/admin/content/manage')
                    ->push(__d('content', 'Content Types'), '/admin/content/types')
                    ->push(__d('content', 'Type "{0}"', $contentType->name), '/admin/content/types/edit/' . $contentType->slug)
                    ->push(__d('content', 'View Mode "{0}"', $this->viewVars['viewModeInfo']['name']), '');
                break;

            case 'viewModeEdit':
                $this->Breadcrumb
                    ->push('/admin/content/manage')
                    ->push(__d('content', 'Content Types'), '/admin/content/types')
                    ->push(__d('content', 'Type "{0}"', $contentType->name), '/admin/content/types/edit/' . $contentType->slug)
                    ->push(__d('content', 'View Mode "{0}"', $this->viewVars['viewModeInfo']['name']), ['plugin' => 'Content', 'controller' => 'fields', 'action' => 'view_mode_list', 'prefix' => 'admin', $this->viewVars['viewMode']])
                    ->push(__d('content', 'Field: {0}', $this->viewVars['instance']->label), '');
                break;
        }
    }