public function __construct(Gadget $gadget, $options = array(), $CSRFSecret = null)
 {
     $this->gadget = $gadget;
     parent::__construct(array(), $options, $CSRFSecret);
     $config = Doctrine::getTable('Gadget')->getGadgetConfigListByType($options['type']);
     if (empty($config[$gadget->getName()]['config'])) {
         throw new RuntimeException('The gadget has not registered or it doesn\'t have any configuration items.');
     }
     $gadgetConfig = $config[$gadget->getName()]['config'];
     foreach ($gadgetConfig as $key => $value) {
         $this->setWidget($key, opFormItemGenerator::generateWidget($value));
         $this->setValidator($key, opFormItemGenerator::generateValidator($value));
         $config = Doctrine::getTable('GadgetConfig')->retrieveByGadgetIdAndName($gadget->getId(), $key);
         if ($config) {
             $this->setDefault($key, $config->getValue());
         }
     }
     $this->widgetSchema->setNameFormat('gadget_config[%s]');
 }
Example #2
0
 /**
  * @param $gadget Gadget
  *
  * @return bool
  */
 private function isNeeded(Gadget $gadget)
 {
     global $wgUser;
     return ($this->neededIds === false || isset($this->neededIds[$gadget->getName()])) && (!$this->listAllowed || $gadget->isAllowed($wgUser)) && (!$this->listEnabled || $gadget->isEnabled($wgUser));
 }