Frontend\Core\Engine\Base\Block::execute PHP Method

execute() public method

Execute the action If a javascript file with the name of the module or action exists it will be loaded.
public execute ( )
    public function execute()
    {
        // build path to the module
        $frontendModulePath = FRONTEND_MODULES_PATH . '/' . $this->getModule();
        // build URL to the module
        $frontendModuleURL = '/src/Frontend/Modules/' . $this->getModule() . '/Js';
        // add javascript file with same name as module (if the file exists)
        if (is_file($frontendModulePath . '/Js/' . $this->getModule() . '.js')) {
            $this->header->addJS($frontendModuleURL . '/' . $this->getModule() . '.js', true, true, Header::PRIORITY_GROUP_MODULE);
        }
        // add javascript file with same name as the action (if the file exists)
        if (is_file($frontendModulePath . '/Js/' . $this->getAction() . '.js')) {
            $this->header->addJS($frontendModuleURL . '/' . $this->getAction() . '.js', true, true, Header::PRIORITY_GROUP_MODULE);
        }
    }

Usage Example

Esempio n. 1
0
 /**
  * Execute the extra
  *
  * @return void
  */
 public function execute()
 {
     parent::execute();
     // Define email from the subscribe widget
     $email = $this->getEmail();
     // Create the form
     $form = $this->createForm($this->get('mailmotor.form.subscription'), new Subscription($email, FRONTEND_LANGUAGE));
     $form->handleRequest($this->get('request'));
     if (!$form->isValid()) {
         $this->tpl->assign('form', $form->createView());
         if ($form->isSubmitted()) {
             $this->tpl->assign('mailmotorSubscribeHasFormError', true);
         }
         $this->loadTemplate();
         $this->parse();
         return;
     }
     $redirectLink = FrontendNavigation::getURLForBlock('Mailmotor', 'Subscribe') . '?subscribed=true';
     /** @var Subscription $subscription */
     $subscription = $form->getData();
     try {
         // The command bus will handle the unsubscription
         $this->get('command_bus')->handle($subscription);
     } catch (NotImplementedException $e) {
         // fallback for when no mail-engine is chosen in the Backend
         $this->get('event_dispatcher')->dispatch(NotImplementedSubscribedEvent::EVENT_NAME, new NotImplementedSubscribedEvent($subscription));
         $redirectLink .= '&double-opt-in=false';
     }
     $redirectLink .= '#mailmotorSubscribeForm';
     return $this->redirect($redirectLink);
 }
All Usage Examples Of Frontend\Core\Engine\Base\Block::execute