Merge pull request #4258 from tractorcow/pulls/4.0/fix-extra-args

API Formalise new additional arguments
This commit is contained in:
Daniel Hensby 2015-06-12 00:55:45 +01:00
commit 4e9f37c516
6 changed files with 24 additions and 15 deletions

View File

@ -332,11 +332,15 @@ class File extends DataObject {
/**
* @return boolean
*/
public function canCreate($member = null) {
if(!$member) $member = Member::currentUser();
public function canCreate($member = null, $context = array()) {
if(!$member) {
$member = Member::currentUser();
}
$result = $this->extendedCan('canCreate', $member);
if($result !== null) return $result;
$result = $this->extendedCan('canCreate', $member, $context);
if($result !== null) {
return $result;
}
return $this->canEdit($member);
}

View File

@ -24,8 +24,9 @@ abstract class DataExtension extends Extension {
* Edit the given query object to support queries for this extension
*
* @param SQLSelect $query Query to augment.
* @param DataQuery $dataQuery Container DataQuery for this SQLQuery
*/
public function augmentSQL(SQLSelect $query) {
public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) {
}
/**

View File

@ -2823,12 +2823,13 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
* else return $normalValue;
* </code>
*
* @param String $methodName Method on the same object, e.g. {@link canEdit()}
* @param string $methodName Method on the same object, e.g. {@link canEdit()}
* @param Member|int $member
* @param array $context Optional context
* @return boolean|null
*/
public function extendedCan($methodName, $member) {
$results = $this->extend($methodName, $member);
public function extendedCan($methodName, $member, $context = array()) {
$results = $this->extend($methodName, $member, $context);
if($results && is_array($results)) {
// Remove NULLs
$results = array_filter($results, function($v) {return !is_null($v);});
@ -2876,13 +2877,13 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
}
/**
* @todo Should canCreate be a static method?
*
* @param Member $member
* @param array $context Additional context-specific data which might
* affect whether (or where) this object could be created.
* @return boolean
*/
public function canCreate($member = null) {
$extended = $this->extendedCan(__FUNCTION__, $member);
public function canCreate($member = null, $context = array()) {
$extended = $this->extendedCan(__FUNCTION__, $member, $context);
if($extended !== null) {
return $extended;
}

View File

@ -183,7 +183,10 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
/**
* Augment the the SQLSelect that is created by the DataQuery
* @todo Should this all go into VersionedDataQuery?
*
* @param SQLSelect $query
* @param DataQuery $dataQuery
* @throws InvalidArgumentException
*/
public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) {
if(!$dataQuery || !$dataQuery->getQueryParam('Versioned.mode')) {

View File

@ -87,7 +87,7 @@ class PermissionRole extends DataObject {
return Permission::check('APPLY_ROLES', 'any', $member);
}
public function canCreate($member = null) {
public function canCreate($member = null, $context = array()) {
return Permission::check('APPLY_ROLES', 'any', $member);
}

View File

@ -42,7 +42,7 @@ class PermissionRoleCode extends DataObject {
return $result;
}
public function canCreate($member = null) {
public function canCreate($member = null, $context = array()) {
return Permission::check('APPLY_ROLES', 'any', $member);
}