protected function add(array $values)
    {
        $values =
            $this->dispatchBeforeOperationEvent(
                '\RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Event\Content\Block\BeforeBlockAddingEvent',
                BlockEvents::BEFORE_ADD_BLOCK,
                $values,
                'exception_block_adding_aborted'
            );

        $this->validator->checkEmptyParams($values);
        $requiredParameters = array("PageId" => "", "LanguageId" => "", "SlotName" => "");
        $this->validator->checkRequiredParamsExists($requiredParameters, $values);

        // When the Content is null the dafault text is inserted
        if (!array_key_exists('Content', $values)) {
            $defaults = $this->getDefaultValue();
            if (!is_array($defaults)) {
                $exception = array(
                    'message' => 'exception_method_returns_invalid_value',
                    'parameters' => array(
                        '%className%' => get_class($this),
                    ),
                );
                throw new General\InvalidArgumentTypeException(json_encode($exception));
            }

            $mergedValues = array_merge($values, $defaults);
            $availableOptions = array(
                'Content' => '',
                'InternalJavascript' => '',
                'ExternalJavascript' => '',
                'InternalStylesheet' => '',
                'ExternalStylesheet' => '',
            );
            $this->validator->checkOnceValidParamExists($availableOptions, $mergedValues);
            $values = $mergedValues;
        }

        try {
            $this->blockRepository->startTransaction();

            // Saves the content
            if (null === $this->alBlock) {
                $className = $this->blockRepository->getRepositoryObjectClassName();
                $this->alBlock = new $className();
            }

            $values = $this->checkCreatedAt($values);
            $result = $this->blockRepository
                    ->setRepositoryObject($this->alBlock)
                    ->save($values);
            if (false !== $result) {
                $this->blockRepository->commit();
                $this->eventsHandler
                     ->createEvent(BlockEvents::AFTER_ADD_BLOCK, '\RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Event\Content\Block\AfterBlockAddedEvent', array($this))
                     ->dispatch();

                return $result;
            }

            $this->blockRepository->rollBack();

            return $result;
        } catch (\Exception $e) {
            if (isset($this->blockRepository) && $this->blockRepository !== null) {
                $this->blockRepository->rollBack();
            }

            throw $e;
        }
    }
protected function add(array $values)
    {
        $values =
            $this->dispatchBeforeOperationEvent(
                '\RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Event\Content\Block\BeforeBlockAddingEvent',
                BlockEvents::BEFORE_ADD_BLOCK,
                $values,
                'exception_block_adding_aborted'
            );

        $this->validator->checkEmptyParams($values);
        $requiredParameters = array("PageId" => "", "LanguageId" => "", "SlotName" => "");
        $this->validator->checkRequiredParamsExists($requiredParameters, $values);

        // When the Content is null the dafault text is inserted
        if (!array_key_exists('Content', $values)) {
            $defaults = $this->getDefaultValue();
            if (!is_array($defaults)) {
                $exception = array(
                    'message' => 'exception_method_returns_invalid_value',
                    'parameters' => array(
                        '%className%' => get_class($this),
                    ),
                );
                throw new General\InvalidArgumentTypeException(json_encode($exception));
            }

            $mergedValues = array_merge($values, $defaults);
            $availableOptions = array(
                'Content' => '',
                'InternalJavascript' => '',
                'ExternalJavascript' => '',
                'InternalStylesheet' => '',
                'ExternalStylesheet' => '',
            );
            $this->validator->checkOnceValidParamExists($availableOptions, $mergedValues);
            $values = $mergedValues;
        }

        try {
            $this->blockRepository->startTransaction();

            // Saves the content
            if (null === $this->alBlock) {
                $className = $this->blockRepository->getRepositoryObjectClassName();
                $this->alBlock = new $className();
            }

            $values = $this->checkCreatedAt($values);
            $result = $this->blockRepository
                    ->setRepositoryObject($this->alBlock)
                    ->save($values);
            if (false !== $result) {
                $this->blockRepository->commit();
                $this->eventsHandler
                     ->createEvent(BlockEvents::AFTER_ADD_BLOCK, '\RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Event\Content\Block\AfterBlockAddedEvent', array($this))
                     ->dispatch();

                return $result;
            }

            $this->blockRepository->rollBack();

            return $result;
        } catch (\Exception $e) {
            if (isset($this->blockRepository) && $this->blockRepository !== null) {
                $this->blockRepository->rollBack();
            }

            throw $e;
        }
    }
protected function add ( array $ values ) { $ values = $ this -> dispatchBeforeOperationEvent ( '\RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Event\Content\Block\BeforeBlockAddingEvent' , BlockEvents :: BEFORE_ADD_BLOCK , $ values , 'exception_block_adding_aborted' ) ; $ this -> validator -> checkEmptyParams ( $ values ) ; $ requiredParameters = array ( "PageId" => "" , "LanguageId" => "" , "SlotName" => "" ) ; $ this -> validator -> checkRequiredParamsExists ( $ requiredParameters , $ values ) ; // When the Content is null the dafault text is inserted if ( ! array_key_exists ( 'Content' , $ values ) ) { $ defaults = $ this -> getDefaultValue ( ) ; if ( ! is_array ( $ defaults ) ) { $ exception = array ( 'message' => 'exception_method_returns_invalid_value' , 'parameters' => array ( '%className%' => get_class ( $ this ) , ) , ) ; throw new General \ InvalidArgumentTypeException ( json_encode ( $ exception ) ) ; } $ mergedValues = array_merge ( $ values , $ defaults ) ; $ availableOptions = array ( 'Content' => '' , 'InternalJavascript' => '' , 'ExternalJavascript' => '' , 'InternalStylesheet' => '' , 'ExternalStylesheet' => '' , ) ; $ this -> validator -> checkOnceValidParamExists ( $ availableOptions , $ mergedValues ) ; $ values = $ mergedValues ; } try { $ this -> blockRepository -> startTransaction ( ) ; // Saves the content if ( null === $ this -> alBlock ) { $ className = $ this -> blockRepository -> getRepositoryObjectClassName ( ) ; $ this -> alBlock = new $ className ( ) ; } $ values = $ this -> checkCreatedAt ( $ values ) ; $ result = $ this -> blockRepository -> setRepositoryObject ( $ this -> alBlock ) -> save ( $ values ) ; if ( false !== $ result ) { $ this -> blockRepository -> commit ( ) ; $ this -> eventsHandler -> createEvent ( BlockEvents :: AFTER_ADD_BLOCK , '\RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Event\Content\Block\AfterBlockAddedEvent' , array ( $ this ) ) -> dispatch ( ) ; return $ result ; } $ this -> blockRepository -> rollBack ( ) ; return $ result ; } catch ( \ Exception $ e ) { if ( isset ( $ this -> blockRepository ) && $ this -> blockRepository !== null ) { $ this -> blockRepository -> rollBack ( ) ; } throw $ e ; } }
Adds a new block to the Block table

@param  array                        $values An array where keys are the BlockField definition and values are the values to add
@return boolean
@throws InvalidArgumentTypeException
@throws \Exception

@api
Adds a new block to the Block table