public function onBeforeEditSeoCommit(BeforeEditSeoCommitEvent $event)
    {
        if ($event->isAborted()) {
            return;
        }

        $values = $event->getValues();
        if (!is_array($values)) {
            throw new InvalidArgumentException('exception_invalid_value_array_required');
        }

        if (array_key_exists("oldPermalink", $values)) {
            $result = true;
            $alBlocks = $this->blockRepository->fromContent($values["oldPermalink"]);
            if (count($alBlocks) > 0) {
                try {
                    $this->blockRepository->startTransaction();
                    foreach ($alBlocks as $alBlock) {
                        $htmlContent = preg_replace('/' . $values["oldPermalink"] . '/s', $values["Permalink"], $alBlock->getContent());
                        $blockManager = $this->blocksFactory->createBlockManager($alBlock);
                        $value = array('Content' => $htmlContent);
                        $result = $blockManager->save($value);
                        if (!$result) {
                            break;
                        }
                    }

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

                        return;
                    }

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

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

                    throw $e;
                }
            }
        }
    }
public function onBeforeEditSeoCommit(BeforeEditSeoCommitEvent $event)
    {
        if ($event->isAborted()) {
            return;
        }

        $values = $event->getValues();
        if (!is_array($values)) {
            throw new InvalidArgumentException('exception_invalid_value_array_required');
        }

        if (array_key_exists("oldPermalink", $values)) {
            $result = true;
            $alBlocks = $this->blockRepository->fromContent($values["oldPermalink"]);
            if (count($alBlocks) > 0) {
                try {
                    $this->blockRepository->startTransaction();
                    foreach ($alBlocks as $alBlock) {
                        $htmlContent = preg_replace('/' . $values["oldPermalink"] . '/s', $values["Permalink"], $alBlock->getContent());
                        $blockManager = $this->blocksFactory->createBlockManager($alBlock);
                        $value = array('Content' => $htmlContent);
                        $result = $blockManager->save($value);
                        if (!$result) {
                            break;
                        }
                    }

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

                        return;
                    }

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

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

                    throw $e;
                }
            }
        }
    }
public function onBeforeEditSeoCommit ( BeforeEditSeoCommitEvent $ event ) { if ( $ event -> isAborted ( ) ) { return ; } $ values = $ event -> getValues ( ) ; if ( ! is_array ( $ values ) ) { throw new InvalidArgumentException ( 'exception_invalid_value_array_required' ) ; } if ( array_key_exists ( "oldPermalink" , $ values ) ) { $ result = true ; $ alBlocks = $ this -> blockRepository -> fromContent ( $ values [ "oldPermalink" ] ) ; if ( count ( $ alBlocks ) > 0 ) { try { $ this -> blockRepository -> startTransaction ( ) ; foreach ( $ alBlocks as $ alBlock ) { $ htmlContent = preg_replace ( '/' . $ values [ "oldPermalink" ] . '/s' , $ values [ "Permalink" ] , $ alBlock -> getContent ( ) ) ; $ blockManager = $ this -> blocksFactory -> createBlockManager ( $ alBlock ) ; $ value = array ( 'Content' => $ htmlContent ) ; $ result = $ blockManager -> save ( $ value ) ; if ( ! $ result ) { break ; } } if ( false !== $ result ) { $ this -> blockRepository -> commit ( ) ; return ; } $ this -> blockRepository -> rollBack ( ) ; $ event -> abort ( ) ; } catch ( \ Exception $ e ) { $ event -> abort ( ) ; if ( isset ( $ this -> blockRepository ) && $ this -> blockRepository !== null ) { $ this -> blockRepository -> rollBack ( ) ; } throw $ e ; } } } }
Adds the page attributes when a new page is added, for each language of the site

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

@api
Adds the page attributes when a new page is added for each language of the site