Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ENHANCEMENT: Added validation on Embargo extension to show message wh…

…en an embargo date already exists on a content-object (Issue #47)
  • Loading branch information...
commit 27962c671f071a60d7caa4b9168ae01f4b397618 1 parent db3a3d9
@phptek phptek authored
Showing with 87 additions and 10 deletions.
  1. +78 −8 code/extensions/WorkflowEmbargoExpiryExtension.php
  2. +9 −2 lang/en.yml
View
86 code/extensions/WorkflowEmbargoExpiryExtension.php
@@ -31,6 +31,17 @@ class WorkflowEmbargoExpiryExtension extends DataExtension {
* @var WorkflowService
*/
public $workflowService;
+
+ /**
+ *
+ * @var array $extendedMethodReturn A basic extended validation routine method return format
+ */
+ public static $extendedMethodReturn = array(
+ 'fieldName' =>null,
+ 'fieldField'=>null,
+ 'fieldMsg' =>null,
+ 'fieldValid'=>true
+ );
/**
* @param FieldList $fields
@@ -52,22 +63,26 @@ public function updateCMSFields(FieldList $fields) {
if ($effective) {
$fields->addFieldsToTab('Root.PublishingSchedule', array(
- new HeaderField('PublishDateHeader', _t('REQUESTED_PUBLISH_DATE_H3', 'Expiry and Embargo'), 3),
+ new HeaderField('PublishDateHeader', _t('WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_H3', 'Expiry and Embargo'), 3),
new LiteralField('PublishDateIntro', $this->getIntroMessage('PublishDateIntro')),
- $dt = new Datetimefield('DesiredPublishDate', _t('AdvancedWorkflow.REQUESTED_PUBLISH_DATE', 'Requested publish date and time')),
- $ut = new Datetimefield('DesiredUnPublishDate', _t('AdvancedWorkflow.REQUESTED_UNPUBLISH_DATE', 'Requested un-publish date and time')),
- Datetimefield::create('PublishOnDate', _t('AdvancedWorkflow.PUBLISH_ON', 'Publish date and time'))->setDisabled(true),
- Datetimefield::create('UnPublishOnDate', _t('AdvancedWorkflow.UNPUBLISH_ON', 'Un-publish date and time'))->setDisabled(true),
+ $dt = new Datetimefield('DesiredPublishDate', _t('WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE', 'Requested publish date')),
+ $ut = new Datetimefield('DesiredUnPublishDate', _t('WorkflowEmbargoExpiryExtension.REQUESTED_UNPUBLISH_DATE', 'Requested un-publish date')),
+ Datetimefield::create('PublishOnDate', _t('WorkflowEmbargoExpiryExtension.PUBLISH_ON', 'Scheduled publish date'))->setDisabled(true),
+ Datetimefield::create('UnPublishOnDate', _t('WorkflowEmbargoExpiryExtension.UNPUBLISH_ON', 'Scheduled un-publish date'))->setDisabled(true),
+ // Readonly fields do not store any value, so add a hidden-field and set its value to the current PublishOnDate so we can perform some validation
+ $uth = new HiddenField('PublishOnDateOwner')
));
} else {
$fields->addFieldsToTab('Root.PublishingSchedule', array(
- $dt = new Datetimefield('PublishOnDate', _t('AdvancedWorkflow.PUBLISH_ON', 'Publish date and time')),
- $ut = new Datetimefield('UnPublishOnDate', _t('AdvancedWorkflow.UNPUBLISH_ON', 'Un-publish date and time')),
+ $dt = new Datetimefield('PublishOnDate', _t('WorkflowEmbargoExpiryExtension.PUBLISH_ON', 'Scheduled publish date')),
+ $ut = new Datetimefield('UnPublishOnDate', _t('WorkflowEmbargoExpiryExtension.UNPUBLISH_ON', 'Scheduled un-publish date')),
));
}
$dt->getDateField()->setConfig('showcalendar', true);
$ut->getDateField()->setConfig('showcalendar', true);
+ // Set a value to our hidden field
+ $uth->setValue($this->owner->PublishOnDate);
// Enable a jQuery-UI timepicker widget
if(self::$showTimePicker) {
@@ -157,4 +172,59 @@ public function getIntroMessage($key) {
$msg = $curr->customise($msg)->renderWith('embargoIntro');
return $msg;
}
-}
+
+ /*
+ * Validate
+ */
+ public function getCMSValidator() {
+ $required = new AWRequiredFields();
+ $required->setCaller($this);
+ return $required;
+ }
+
+ /*
+ * Use AWRequiredFields to peform validation at the DataExtension level. Granted, having to add self::$extendedMethodReturn everywhere you want custom validation
+ * is rubbish, but it works and does what it intends. If a better way is found to implement validation on a DataExtension, without access to Form,
+ * feel-free to re-open issues/47 and comment with a link to your own Gist! :-)
+ *
+ * @param array $data
+ * @return array
+ */
+ public function extendedRequiredFieldsCheckEmbargoDates($data = null) {
+ $desiredEmbargo = strtotime($data['DesiredPublishDate']);
+ $scheduledEmbargo = strtotime($data['PublishOnDateOwner']);
+ $desiredExpiry = strtotime($data['DesiredUnPublishDate']);
+ $msg = '';
+ if(strlen($data['DesiredPublishDate']) && $scheduledEmbargo > time()) {
+ $scheduledEmbargo = date('d/m/Y H:i',$scheduledEmbargo);
+ $msg = _t(
+ 'WorkflowEmbargoExpiryExtension.EMBARGO_ERROR_PT1',
+ "This content is already under embargo, expiring at: ")
+ .$scheduledEmbargo.
+ _t(
+ 'WorkflowEmbargoExpiryExtension.EMBARGO_ERROR_PT2',
+ ' please wait until this date has passed, before applying a new embargo date.'
+ );
+ self::$extendedMethodReturn['fieldName'] = 'DesiredPublishDate';
+ }
+ if(strlen($data['DesiredPublishDate']) && $desiredEmbargo < time()) {
+ $msg = _t(
+ 'EMBARGO_DSIRD_ERROR',
+ "This date has already passed, please enter a valid future date."
+ );
+ self::$extendedMethodReturn['fieldName'] = 'DesiredPublishDate';
+ }
+ if(strlen($data['DesiredUnPublishDate']) && $desiredExpiry < time()) {
+ $msg = _t(
+ 'EMBARGO_DSIRD_ERROR',
+ "This date has already passed, please enter a valid future date."
+ );
+ self::$extendedMethodReturn['fieldName'] = 'DesiredUnPublishDate';
+ }
+ if(strlen($msg)>0) {
+ self::$extendedMethodReturn['fieldValid'] = false;
+ self::$extendedMethodReturn['fieldMsg'] = $msg;
+ }
+ return self::$extendedMethodReturn;
+ }
+}
View
11 lang/en.yml
@@ -25,7 +25,14 @@ en:
GridFieldTitleAssignedYour: Your pending items
GridFieldTitleSubmittedYour: Your submitted items
WorkflowEmbargoExpiryExtension:
+ REQUESTED_PUBLISH_DATE: Requested publish date
+ REQUESTED_UNPUBLISH_DATE: Requested un-publish date
+ PUBLISH_ON: Scheduled publish date
+ UNPUBLISH_ON: Scheduled un-publish date
REQUESTED_PUBLISH_DATE_H3: Expiry and Embargo
REQUESTED_PUBLISH_DATE_INTRO: Enter a date and/or time to specify embargo and expiry dates.
- WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_INTRO_BULLET_1: These settings won't take effect until any approval actions are run
- WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_INTRO_BULLET_2: If an embargo is already set, adding a new one prior to that date's passing will overwrite it
+ REQUESTED_PUBLISH_DATE_INTRO_BULLET_1: These settings won't take effect until any approval actions are run
+ REQUESTED_PUBLISH_DATE_INTRO_BULLET_2: If an embargo is already set, adding a new one prior to that date's passing will overwrite it
+ EMBARGO_SCHED_ERROR_PT1: 'This content is already under embargo, expiring at:'
+ EMBARGO_SCHED_ERROR_PT2: please wait until this date has passed, before applying a new embargo date.
+ EMBARGO_DSIRD_ERROR: This date has already passed, please enter a valid future date.
Please sign in to comment.
Something went wrong with that request. Please try again.