-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from Firesphere/master
Many code-technical improvements.
- Loading branch information
Showing
11 changed files
with
242 additions
and
166 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 |
---|---|---|
@@ -1,22 +1,64 @@ | ||
<?php | ||
|
||
|
||
/** | ||
* Class Annotatable | ||
* | ||
* Annotate the provided DataObjects for autocompletion purposes. | ||
* Start annotation, if skipannotation is not set and the annotator is enabled. | ||
* | ||
* @property DataObject|Annotatable owner | ||
*/ | ||
class Annotatable extends DataExtension | ||
{ | ||
|
||
/** | ||
* @var DataObjectAnnotator | ||
*/ | ||
protected $annotator; | ||
|
||
/** | ||
* @var AnnotatePermissionChecker | ||
*/ | ||
protected $permissionChecker; | ||
|
||
public function __construct() { | ||
parent::__construct(); | ||
$this->annotator = Injector::inst()->get('DataObjectAnnotator'); | ||
$this->permissionChecker = Injector::inst()->get('AnnotatePermissionChecker'); | ||
|
||
} | ||
/** | ||
* This is the base function on which annotations are started. | ||
* | ||
* @todo rewrite this. It's not actually a requireDefaultRecords. But it's the only place to hook into the build-process to start the annotation process. | ||
* @return bool | ||
*/ | ||
public function requireDefaultRecords() | ||
{ | ||
if (!Config::inst()->get('DataObjectAnnotator', 'enabled') || isset($_GET['skipannotation'])) { | ||
|
||
/** @var SS_HTTPRequest|NullHTTPRequest $request */ | ||
$request = Controller::curr()->getRequest(); | ||
$skipAnnotation = $request->getVar('skipannotation'); | ||
if ($skipAnnotation !== null || !Config::inst()->get('DataObjectAnnotator', 'enabled')) { | ||
return false; | ||
} | ||
|
||
/* @var $annotator DataObjectAnnotator */ | ||
$annotator = DataObjectAnnotator::create(); | ||
$annotator->annotateDataObject($this->owner->ClassName); | ||
/* Annotate the current Class, if annotatable */ | ||
if ($this->permissionChecker->classNameIsAllowed($this->owner->ClassName)) { | ||
$this->annotator->annotateDataObject($this->owner->ClassName); | ||
} | ||
|
||
if ($extensions = Config::inst()->get($this->owner->ClassName, 'extensions', Config::UNINHERITED)) { | ||
foreach($extensions as $extension) { | ||
$annotator->annotateDataObject($extension); | ||
/** @var array $extensions */ | ||
$extensions = Config::inst()->get($this->owner->ClassName, 'extensions', Config::UNINHERITED); | ||
/* Annotate the extensions for this Class, if annotatable */ | ||
if ($extensions) { | ||
foreach ($extensions as $extension) { | ||
if ($this->permissionChecker->classNameIsAllowed($extension)) { | ||
$this->annotator->annotateDataObject($extension); | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
Oops, something went wrong.