Skip to content

Commit

Permalink
Merge pull request #564 from creative-commoners/pulls/7/valid
Browse files Browse the repository at this point in the history
API Rename validator classes
  • Loading branch information
GuySartorelli authored Dec 10, 2024
2 parents 18f9dd6 + 1096f36 commit dc602fd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/DataObjects/WorkflowAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\Validation\RequiredFieldsValidator;
use SilverStripe\Forms\TabSet;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataObject;
Expand Down Expand Up @@ -273,7 +273,7 @@ public function getCMSFields()

public function getValidator()
{
return new RequiredFields('Title');
return new RequiredFieldsValidator('Title');
}

public function summaryFields()
Expand Down
6 changes: 3 additions & 3 deletions src/DataObjects/WorkflowTransition.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Security\Security;
use Symbiote\AdvancedWorkflow\Forms\AWRequiredFields;
use Symbiote\AdvancedWorkflow\Forms\AWRequiredFieldsValidator;

/**
* A workflow transition.
Expand Down Expand Up @@ -177,7 +177,7 @@ public function fieldLabels($includerelations = true)

public function getValidator()
{
$required = new AWRequiredFields('Title', 'ActionID', 'NextActionID');
$required = new AWRequiredFieldsValidator('Title', 'ActionID', 'NextActionID');
$required->setCaller($this);
return $required;
}
Expand Down Expand Up @@ -275,7 +275,7 @@ public function getAssignedMembers()
*
* @param array $data
* @return array
* @see {@link AWRequiredFields}
* @see {@link AWRequiredFieldsValidator}
*/
public function extendedRequiredFieldsNotSame($data = null)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Extensions/WorkflowEmbargoExpiryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use SilverStripe\Security\Permission;
use SilverStripe\View\Requirements;
use SilverStripe\Versioned\Versioned;
use Symbiote\AdvancedWorkflow\Forms\AWRequiredFields;
use Symbiote\AdvancedWorkflow\Forms\AWRequiredFieldsValidator;
use Symbiote\AdvancedWorkflow\Jobs\WorkflowPublishTargetJob;
use Symbiote\AdvancedWorkflow\Services\WorkflowService;
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor;
Expand Down Expand Up @@ -430,14 +430,14 @@ public function getIntroMessage($key)
*/
public function getCMSValidator()
{
$required = new AWRequiredFields();
$required = new AWRequiredFieldsValidator();
$required->setCaller($this);
return $required;
}

/**
* This is called in the AWRequiredFields class, this validates whether an Embargo and Expiry are not equal and that
* Embargo is before Expiry, returning the appropriate message when it fails.
* This is called in the AWRequiredFieldsValidator class, this validates whether an Embargo and Expiry are
* not equal and that Embargo is before Expiry, returning the appropriate message when it fails.
*
* @param $data
* @return array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,21 @@

namespace Symbiote\AdvancedWorkflow\Forms;

use SilverStripe\Forms\RequiredFields;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\Validation\RequiredFieldsValidator;

/**
* Extends RequiredFields so we can prevent DO writes in AW's controller(s) without needing to catch Exceptions
* Extends RequiredFieldsValidator so we can prevent DO writes in AW's controller(s) without needing to catch Exceptions
* from DO->validate() all over the place.
* Note specifically $this->getExtendedValidationRoutines() - anti-pattern anyone?
*
* @author Russell Michell russell@silverstripe.com
* @package advancedworkflow
*
* @deprecated 5.4.0 Will be renamed to Symbiote\AdvancedWorkflow\Forms\AWRequiredFieldsValidator
*/
class AWRequiredFields extends RequiredFields
class AWRequiredFieldsValidator extends RequiredFieldsValidator
{
protected $data = array();
protected static $caller;

public function __construct()
{
$message = 'Will be renamed to Symbiote\\AdvancedWorkflow\\Forms\\AWRequiredFieldsValidator';
Deprecation::noticeWithNoReplacment('5.4.0', $message, Deprecation::SCOPE_CLASS);
parent::__construct(...func_get_args());
}

public function php($data)
{
$valid = parent::php($data);
Expand Down Expand Up @@ -60,12 +50,12 @@ public function php($data)

/**
* Allows for the addition of an arbitrary no. additional, dedicated and "extended" validation methods on classes
* that call AWRequiredFields.
* that call AWRequiredFieldsValidator.
* To add specific validation methods to a caller:
*
* 1). Write each checking method using this naming prototype: public function extendedRequiredFieldsXXX(). All
* methods so named will be called.
* 2). Call AWRequiredFields->setCaller($this)
* 2). Call AWRequiredFieldsValidator->setCaller($this)
*
* Each extended method thus called, should return an array of a specific format. (See: static
* $extendedMethodReturn on the caller)
Expand Down Expand Up @@ -115,11 +105,11 @@ protected function getData()

public function setCaller($caller)
{
AWRequiredFields::$caller = $caller;
AWRequiredFieldsValidator::$caller = $caller;
}

public function getCaller()
{
return AWRequiredFields::$caller;
return AWRequiredFieldsValidator::$caller;
}
}

0 comments on commit dc602fd

Please sign in to comment.