1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Lack of Interest New ControllerHelper Request

Discussion in 'Closed Suggestions' started by xf_phantom, Aug 20, 2013.

  1. xf_phantom

    xf_phantom Well-Known Member

    PHP:
    'addOnOptions' => $this->_getAddOnModel()->getAddOnOptionsListIfAvailable(),
           
    'addOnSelected' => (isset($entry['addon_id']) ? $entry['addon_id'] : $addOnModel->getDefaultAddOnId())
    is being used very often in admin controllers

    I would request to move this to a own controllerhelper. Then it would become reusable and we would need less code if we would want to use it in our own controllers:cool:


    e.g. something like following code would be enough
    PHP:
    <?php

    class Dev_ControllerHelper_AddOn extends XenForo_ControllerHelper_Abstract{

      
    /**
      * @param null $selectedAddonId
      * @param bool $includeCustomOptions
      * @param bool $includeXenForoOptions
      * @return array
      */
      
    public function getDefaultViewParams($selectedAddonId null$includeCustomOptions true$includeXenForoOptions true){
      
    /** @var XenForo_Model_AddOn $addOnModel */
      
    $addOnModel $this->_controller->getModelFromCache('XenForo_Model_AddOn');
      
    $viewParams = array(
      
    'addOnOptions' => $addOnModel->getAddOnOptionsListIfAvailable($includeCustomOptions,$includeXenForoOptions),
      
    'addOnSelected' => (isset($selectedAddonId) ? $selectedAddonId $addOnModel->getDefaultAddOnId())
      );

      return 
    $viewParams;
      }
    }


    // usage in controller:
    $viewParams += $this->getHelper('Dev_ControllerHelper_AddOn')->getDefaultViewParams();


    $viewParams += $this->getHelper('Dev_ControllerHelper_AddOn')->getDefaultViewParams($template['addon_id']);

     
    Last edited: Aug 20, 2013

Share This Page