This repository has been archived by the owner on Aug 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fields): upgrade to new fields API
- Loading branch information
1 parent
0117d25
commit ad09845
Showing
2 changed files
with
67 additions
and
26 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,54 @@ | ||
<?php | ||
|
||
namespace hypeJunction\Attachments; | ||
|
||
use Elgg\Request; | ||
use ElggEntity; | ||
use hypeJunction\Fields\Field; | ||
use Symfony\Component\HttpFoundation\ParameterBag; | ||
|
||
class AttachmentsField extends Field { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function raw(Request $request, ElggEntity $entity) { | ||
return elgg_get_uploaded_files($this->name); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function validate($value) { | ||
parent::validate($value); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function save(ElggEntity $entity, ParameterBag $parameters) { | ||
return hypeapps_attach_uploaded_files($entity, 'attachments', [ | ||
'access_id' => $entity->access_id, | ||
'container_guid' => $entity->guid, | ||
'origin' => 'cms', | ||
]); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function retrieve(ElggEntity $entity) { | ||
return hypeapps_get_attachments($entity); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isVisible(ElggEntity $entity, $context = null) { | ||
if (!hypeapps_allow_attachments($entity->type, $entity->subtype)) { | ||
return false; | ||
} | ||
|
||
return parent::isVisible($entity, $context); // TODO: Change the autogenerated stub | ||
} | ||
} |