7958 Posts in 1402 Topics by 946 members
|Go to End|
3 September 2010 at 7:41am
I'm writing a Media Module that leverages DOM and Uploadify. The module has a MediaAlbumPage which calls a ManyManyFileDataObjectManager in its getCMSFields routine to manage videos. For simplicities sake; The ManyManyFileDataObjectManager is set to display all Videos and the checkbox to show "Related Only" is left unchecked.
When I upload a video through the add button at top of the DOM field, the video is shown in the list upon completion, but the checkbox relating it to the current MediaAlbumPage is left empty.
Is there a simple solution to auto-relate files through the ManyManyFileDataObjectManager (e.g. auto-check the box in the DOM to relate the asset)?
I see there's a trick in the ImageGallery Module that handles this by calling a class extending FileDataObjectManager instead of FileDataObjectManager itself, and injecting the ID of the parent gallery through the getUploadifyFields and getUploadFields method -- but was wondering if there's a different way to go w/o having to write a custom DOM class.
3 September 2010 at 8:39am
Yeah, I posted a tutorial on that somewhere in this forum..
3 September 2010 at 10:23am Last edited: 3 September 2010 10:30am
hmmm.. still searching but will post here when I find it!
Thought I had something in: http://silverstripe.org/archive/show/65501#post65501
($relationAutoSetting) ... but it does not work as expected
3 September 2010 at 10:36am Last edited: 3 September 2010 10:37am
I believe I found it;
Will play around & see if I can come up w/ an elegant patch -- maybe favor the ImageGallery module approach.
3 September 2010 at 12:39pm
Below is a proposed patch to FileDataObjectManager to handle this automatically if you set the autoRelateUploads property on your ManyManyFileDataObjectManager or HasManyFileDataObjectMany to boolean: true or string: name of relation.
--- www/dataobject_manager/code/FileDataObjectManager.php (revision 14)
+++ www/dataobject_manager/code/FileDataObjectManager.php (working copy)
@@ -41,6 +41,21 @@
public $uploadifyField = "MultipleFileUploadField";
+ // [start] bb: patch - auto relate uploaded asset (1 of 2)
+ * false: [default] do not attempt to auto-relate uploads
+ * true: use plural name of uploaded class for relation component
+ * String: specify has_many or many_many relationship name
+ * @example
+ * $DOM = new ManyManyFileDataObjectManager;
+ * $DOM->autoRelateUploads = true;
+ * @example
+ * $DOM = new HasManyFileDataObjectManager;
+ * $DOM->autoRelateUploads = 'Videos';
+ public $autoRelateUploads = false;
+ // [end] bb: patch - auto relate uploaded asset (1 of 2)
public function __construct($controller, $name = null, $sourceClass = null, $fileFieldName = null, $fieldList = null, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "")
@@ -413,6 +428,21 @@
$dataobject_ids = $obj->ID;
+ // [start] bb: patch - auto relate uploaded asset (2 of 2)
+ if($this->autoRelateUploads && property_exists($this, 'RelationType'))
+ $parent = DataObject::get_by_id($this->controllerClassName, $this->controllerID);
+ $relationName = (is_string($this->autoRelateUploads)) ?
+ $this->autoRelateUploads : $object->plural_name();
+ $func = ($this->RelationType == 'ManyMany') ?
+ 'getManyManyComponents' : 'getComponents';
+ $relations = $parent->$func($relationName);
+ // [end] bb: patch - auto relate uploaded asset (2 of 2)
$_POST['uploaded_files'] = $dataobject_ids;
NOTE: this must be applied against version of DOM that include & use Uploadify
|Go to Top|