Ejemplo n.º 1
0
 /**
  * @param \NetteAddons\Model\Addon
  * @return AddonForm
  */
 public function setAddon(Addon $addon)
 {
     $this->addon = $addon;
     if (!is_null($addon->repositoryHosting)) {
         if (is_null($addon->id)) {
             $this->removeComponent($this['repository']);
         }
         if ($addon->defaultLicense) {
             $this->removeComponent($this['defaultLicense']);
         }
     }
     if ($addon->composerFullName) {
         $this->removeComponent($this['composerFullName']);
     }
     $license = $addon->defaultLicense;
     if (is_string($license)) {
         if ($license === 'NOLICENSE') {
             $license = array();
         } else {
             $license = array_map('trim', explode(',', $license));
         }
     }
     if ($key = array_search('NOLICENSE', $license)) {
         unset($license[$key]);
     }
     $tagItems = $this['tags']->getItems();
     $tags = array();
     foreach ($addon->getTagsIds() as $id) {
         if (!isset($tagItems[$id])) {
             $tag = $this->tags->find($id);
             if ($tag) {
                 $tagItems[$tag->id] = $tag->name;
             }
         }
         if (isset($tagItems[$id])) {
             $tags[] = $id;
         }
     }
     $this['tags']->setItems($tagItems)->setDefaultValue($tags);
     $this->setDefaults(array('name' => $addon->name, 'shortDescription' => $addon->shortDescription, 'description' => $addon->description, 'descriptionFormat' => $addon->descriptionFormat, 'defaultLicense' => $license, 'repository' => $addon->repository, 'demo' => $addon->demo));
     return $this;
 }