Exemplo n.º 1
0
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->addFieldToTab('Root.Main', DropdownField::create('VideoID', 'Select video', EmbeddedObject::get()->map("ID", "Title")));
     $fields->addFieldToTab('Root.Main', EmbeddedObjectField::create('AddVideo', 'Video from oEmbed URL'));
     return $fields;
 }
 public function update(SS_HTTPRequest $request)
 {
     if (!SecurityToken::inst()->checkRequest($request)) {
         return '';
     }
     $url = $request->postVar('URL');
     if (strlen($url)) {
         $info = Oembed::get_oembed_from_url($url);
         $info = Embed\Embed::create($url);
         if ($info) {
             $object = EmbeddedObject::create();
             $object->setFromEmbed($info);
             $this->object = $object;
             // needed to make sure the check in FieldHolder works out
             $object->ID = -1;
             return $this->FieldHolder();
         } else {
             $this->message = _t('EmbeddedObjectField.ERROR', 'Could not look up provided URL: ' . Convert::raw2xml($url));
             return $this->FieldHolder();
         }
     } else {
         $this->object = null;
         return $this->FieldHolder();
     }
 }
 public function update(SS_HTTPRequest $request)
 {
     if (!SecurityToken::inst()->checkRequest($request)) {
         return '';
     }
     $url = $request->postVar('URL');
     if (strlen($url)) {
         $info = Oembed::get_oembed_from_url($url);
         if ($info && $info->exists()) {
             $object = EmbeddedObject::create();
             $object->Title = $info->title;
             $object->SourceURL = $url;
             $object->Width = $info->width;
             $object->Height = $info->height;
             $object->ThumbURL = $info->thumbnail_url;
             $object->Description = $info->description ? $info->description : $info->title;
             $object->Type = $info->type;
             $object->EmbedHTML = $info->forTemplate();
             $this->object = $object;
             // needed to make sure the check in FieldHolder works out
             $object->ID = -1;
             return $this->FieldHolder();
         } else {
             $this->message = _t('EmbeddedObjectField.ERROR', 'Could not look up provided URL: ' . Convert::raw2xml($url));
             return $this->FieldHolder();
         }
     } else {
         $this->object = null;
         return $this->FieldHolder();
     }
 }