-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separated common parts into AbstractFinisher class
- Loading branch information
Felix Gradinaru
committed
Apr 24, 2018
1 parent
0d8c0cc
commit 01a2d5b
Showing
7 changed files
with
131 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
namespace GradinaruFelix\Pipedrive; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Form\Core\Model\AbstractFinisher as NeosFormAbstractFinisher; | ||
use Neos\Form\Exception\FinisherException; | ||
use GradinaruFelix\Pipedrive\Utility\Api as PipedriveApi; | ||
|
||
abstract class AbstractFinisher extends NeosFormAbstractFinisher | ||
{ | ||
|
||
const OMITTED_OPTIONS = array( | ||
'testMode', | ||
'identifier', | ||
); | ||
|
||
|
||
|
||
protected function getIdentifier() { | ||
$scope = $this->scope; | ||
$customIdentifier = $this->parseOption('identifier'); | ||
|
||
if($customIdentifier) { | ||
$identifier = "Pipedrive." . $customIdentifier; | ||
} else { | ||
$identifier = "Pipedrive." . $scope . "Finisher"; | ||
} | ||
|
||
return $identifier; | ||
} | ||
|
||
/** | ||
* Runs the API request for the given data | ||
* | ||
* @return bool | ||
* @throws FinisherException | ||
*/ | ||
protected function callAPI($data) { | ||
$apiUtility = new PipedriveApi($this->apiEndpoint); | ||
$apiUtility->setData($data); | ||
|
||
$formState = $this->finisherContext->getFormRuntime()->getFormState(); | ||
|
||
$response = $apiUtility->execute(); | ||
|
||
if($response->data->id) { | ||
$formState->setFormValue($this->getIdentifier() . ".ID", $response->data->id); | ||
return true; | ||
} else { | ||
throw new FinisherException("Something went wrong while calling the API!"); | ||
return false; | ||
} | ||
} | ||
|
||
} |
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
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
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