-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added AssetAdmin fixes, applied EditForm fix to CMSMain
- Loading branch information
1 parent
338cf2f
commit c0b057a
Showing
6 changed files
with
306 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
/** | ||
* An extension which loads the required EditForm scripts for CMSMain (workaround for a bug in 3.4.0 + Secure Assets). | ||
*/ | ||
class CMSMainEditFormExtension extends LeftAndMainExtension | ||
{ | ||
/** | ||
* Extension init() method, called by LeftAndMain init() method. | ||
*/ | ||
public function init() | ||
{ | ||
if (defined('CMS_DIR')) { | ||
Requirements::javascript(CMS_DIR . '/javascript/CMSMain.EditForm.js'); | ||
} | ||
|
||
if ($this->isAssetAdmin() && $this->hasSecureAssets()) { | ||
Requirements::javascript(MODERNO_ADMIN_DIR . '/javascript/AssetAdmin.EditForm.js'); | ||
} | ||
} | ||
|
||
/** | ||
* Updates the edit form object from AssetAdmin to provide a workaround for a bug in Secure Assets. | ||
* | ||
* @param Form $form | ||
*/ | ||
public function updateEditForm($form) | ||
{ | ||
if ($this->isAssetAdmin() && $this->hasSecureAssets()) { | ||
|
||
if (($record = $form->getRecord()) && $record instanceof Folder) { | ||
|
||
if ($field = $form->Fields()->dataFieldByName('ViewerGroups')) { | ||
|
||
// Create Form Object: | ||
|
||
$dummy = Form::create( | ||
$this->owner, | ||
'EditForm', | ||
FieldList::create(), | ||
FieldList::create() | ||
); | ||
|
||
// Populate Form Data: | ||
|
||
$dummy->loadDataFrom($record); | ||
|
||
// Define Form Action (allows ViewerGroups field to work in asset EditForm): | ||
|
||
$dummy->setFormAction( | ||
sprintf( | ||
'%s/field/File/item/%d/ItemEditForm', | ||
$form->FormAction(), | ||
$record->ID | ||
) | ||
); | ||
|
||
// Update Field Object: | ||
|
||
$field->setForm($dummy); | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
} | ||
|
||
/** | ||
* Answers true if the extended object is AssetAdmin. | ||
* | ||
* @return boolean | ||
*/ | ||
private function isAssetAdmin() | ||
{ | ||
return ($this->owner->class == 'AssetAdmin'); | ||
} | ||
|
||
/** | ||
* Answers true if the File class has the Secure Assets extension applied. | ||
* | ||
* @return boolean | ||
*/ | ||
private function hasSecureAssets() | ||
{ | ||
return Object::has_extension('File', 'SecureFileExtension'); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.