protected function _getDetailForm(File $file) { $form = $this->get('form')->setName('file')->setMethod('POST')->setAction($this->generateUrl('ms.cp.file_manager.edit', array('fileID' => $file->id)))->setDefaultValues(array('tags' => implode(', ', $file->getTags()), 'alt_text' => $file->altText)); $form->add('tags', 'textarea', $this->trans('ms.file_manager.detail.labels.tags')); $form->add('alt_text', 'text', $this->trans('ms.file_manager.detail.labels.alt-text')); return $form; }
/** * Update a file in the database. * * Only alt text and tags are updated. * * @param File $file The file with updated properties * * @return File|false The updated instance returned from the edit event */ public function save(File $file) { $file->authorship->update(new DateTimeImmutable(), $this->_currentUser->id); $this->_query->run(' UPDATE file SET updated_at = :updatedAt?i, updated_by = :updatedBy?in, alt_text = :altText?s WHERE file_id = :fileID?i ', array('updatedAt' => $file->authorship->updatedAt()->getTimestamp(), 'updatedBy' => $file->authorship->updatedBy(), 'altText' => $file->altText, 'fileID' => $file->id)); // Delete all the tags and then add the new ones in if ($tags = $file->getTags()) { $this->_query->run(' DELETE FROM file_tag WHERE file_id = ?i ', $file->id); $inserts = array(); $values = ''; end($tags); $lastKey = key($tags); foreach ($tags as $k => $tagName) { $values .= '(?i, ?s)' . ($lastKey == $k ? '' : ','); $inserts[] = $file->id; $inserts[] = $tagName; } $this->_query->run(' INSERT INTO file_tag (file_id, tag_name) VALUES ' . $values, $inserts); } // Initiate the event file $event = new Event($file); // Dispatch the file edited event $this->_eventDispatcher->dispatch(Event::EDIT, $event); return $event->getFile(); }
public function getTags() { if ($this->_loaded) { return parent::getTags(); } $tags = $this->_tagLoader->getByFile($this); if ($tags !== false) { $this->_tags = $this->_tags + $tags; } $this->_loaded = true; return parent::getTags(); }