Skip to content

Commit

Permalink
Add a timestamp data event
Browse files Browse the repository at this point in the history
  • Loading branch information
GwendolenLynch committed Aug 18, 2015
1 parent e605b0a commit abc1326
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ The default events that can be used to get field data are:
- random_string
- server_value
- session_value
- timestamp_formatted

#### Examples

Expand Down Expand Up @@ -226,6 +227,19 @@ Set the `testkey` field value to the value for the session variable named "testk
key: testkey
```

Set the `sent_on` field value to the current date and/or time as formatted.

```yaml
sent_on:
type: hidden
options:
label: false
event:
name: timestamp
params:
format: '%F %T'
```

#### Extending Available Events

Should you want to provide your own extension with a data event, you can specify
Expand Down
1 change: 1 addition & 0 deletions src/Event/BoltFormsEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ final class BoltFormsEvents
const DATA_RANDOM_STRING = 'boltforms.random_string';
const DATA_SERVER_VALUE = 'boltforms.server_value';
const DATA_SESSION_VALUE = 'boltforms.session_value';
const DATA_TIMESTAMP = 'boltforms.timestamp';

private function __construct()
{
Expand Down
16 changes: 16 additions & 0 deletions src/Subscriber/BoltFormsCustomDataSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ public function sessionValue(BoltFormsCustomDataEvent $event)
$event->setData($this->app['session']->get($params['key']));
}

/**
* Fetch the current (formatted) timestamp.
*
* @param BoltFormsCustomDataEvent $event
*/
public function timestamp(BoltFormsCustomDataEvent $event)
{
$params = $event->getParameters();
if (!isset($params['format'])) {
return;
}

$event->setData(strftime($params['format']));
}

/**
* Attempt get the next sequence from a table, if specified.
*
Expand Down Expand Up @@ -153,6 +168,7 @@ public static function getSubscribedEvents()
BoltFormsEvents::DATA_RANDOM_STRING => 'randomString',
BoltFormsEvents::DATA_SERVER_VALUE => 'serverValue',
BoltFormsEvents::DATA_SESSION_VALUE => 'sessionValue',
BoltFormsEvents::DATA_TIMESTAMP => 'timeStamp',
);
}
}

0 comments on commit abc1326

Please sign in to comment.