• 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

xf_phantom

Well-known member
#1
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: