Backend\Modules\ContentBlocks\Actions\Add::execute PHP Method

execute() public method

Execute the action
public execute ( )
    public function execute()
    {
        parent::execute();
        $form = $this->createForm(new ContentBlockType($this->get('fork.settings')->get('Core', 'theme', 'core')));
        $form->handleRequest($this->get('request'));
        if (!$form->isValid()) {
            $this->tpl->assign('form', $form->createView());
            $this->parse();
            $this->display();
            return;
        }
        /** @var CreateContentBlock $createContentBlock */
        $createContentBlock = $form->getData();
        $createContentBlock->userId = Authentication::getUser()->getUserId();
        // The command bus will handle the saving of the content block in the database.
        $this->get('command_bus')->handle($createContentBlock);
        $this->get('event_dispatcher')->dispatch(ContentBlockCreated::EVENT_NAME, new ContentBlockCreated($createContentBlock->contentBlock));
        return $this->redirect(BackendModel::createURLForAction('Index', null, null, ['report' => 'added', 'var' => $createContentBlock->title]));
    }