Skip to content

Commit

Permalink
v2.0.0-beta.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kjmartens committed Feb 2, 2018
1 parent eab31e8 commit 0927383
Show file tree
Hide file tree
Showing 16 changed files with 263 additions and 45 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Solspace Freeform Changelog

## 2.0.0-beta.6 - 2018-02-02
### Added
- Added a 'Use Double Opt-in?' setting for MailChimp integrations.
- Added `onBeforeSubmit` and `onAfterSubmit` events.
- Added an optional `renderSingleInput` method to render single Checkbox fields' input without an additional hidden input.

### Changed
- Changed Mailing List fieldtype `renderInput` to now only output the input field (without a label).

### Fixed
- Fixed a bug where the chart on Submissions list page inside CP was sometimes not displaying new submissions based on timezone.
- Fixed a bug where permissions weren't allowing Admins to change status of submission(s).

## 2.0.0-beta.5 - 2018-01-31
### Fixed
- Fixed a bug where the Freeform 1.x to 2.x (Craft 2.x to 3.x) migration path could error in some cases.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "solspace/craft3-freeform",
"description": "The most intuitive and powerful form builder for Craft.",
"version": "2.0.0-beta.5",
"version": "2.0.0-beta.6",
"type": "craft-plugin",
"minimum-stability": "dev",
"authors": [
Expand Down
20 changes: 10 additions & 10 deletions src/Controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public function actionGetSubmissionData(): Response

$startDate = new Carbon($startDateParam, 'UTC');
$endDate = new Carbon($endDateParam, 'UTC');
$endDate->modify('+1 day');
$endDate->setTime(23, 59,59);

$intervalUnit = ChartHelper::getRunChartIntervalUnit($startDate, $endDate);

Expand Down Expand Up @@ -422,19 +422,19 @@ public function actionFinishTutorial(): Response
}

/**
* @param Query $query
* @param \DateTime $startDate
* @param \DateTime $endDate
* @param string $dateColumn
* @param array $options
* @param Query $query
* @param Carbon $startDate
* @param Carbon $endDate
* @param string $dateColumn
* @param array $options
*
* @return array
* @throws Exception
*/
private function getRunChartDataFromQuery(
Query $query,
\DateTime $startDate,
\DateTime $endDate,
Carbon $startDate,
Carbon $endDate,
string $dateColumn,
array $options = []
): array {
Expand Down Expand Up @@ -524,8 +524,8 @@ private function getRunChartDataFromQuery(
// Prepare the query
$condition = ['and', "{$dateColumnSql} >= :startDate", "{$dateColumnSql} < :endDate"];
$params = [
':startDate' => Db::prepareDateForDb($startDate),
':endDate' => Db::prepareDateForDb($endDate),
':startDate' => $startDate->toDateTimeString(),
':endDate' => $endDate->toDateTimeString(),
];
$orderBy = ['date' => SORT_ASC];

Expand Down
7 changes: 6 additions & 1 deletion src/Elements/Actions/SetSubmissionStatusAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,23 @@ public function performAction(ElementQueryInterface $query): bool
$failCount = 0;

static $allowedFormIds;
static $isAdmin;

if (null === $allowedFormIds) {
$allowedFormIds = PermissionHelper::getNestedPermissionIds(Freeform::PERMISSION_SUBMISSIONS_MANAGE);
}

if (null === $isAdmin) {
$isAdmin = PermissionHelper::isAdmin();
}

foreach ($submissions as $submission) {
// Skip if there's nothing to change
if ((int) $submission->statusId === (int) $this->statusId) {
continue;
}

if (!\in_array($submission->formId, $allowedFormIds, false)) {
if (!$isAdmin && !\in_array($submission->formId, $allowedFormIds, false)) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Elements/Submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ public function getCpEditUrl()
$allowedFormIds = PermissionHelper::getNestedPermissionIds(Freeform::PERMISSION_SUBMISSIONS_MANAGE);
}

if (!\in_array($this->formId, $allowedFormIds, false)) {
if (!PermissionHelper::isAdmin() && !\in_array($this->formId, $allowedFormIds, false)) {
return false;
}

Expand Down
44 changes: 44 additions & 0 deletions src/Events/Forms/AfterSubmitEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Solspace\Freeform\Events\Forms;

use Solspace\Freeform\Elements\Submission;
use Solspace\Freeform\Library\Composer\Components\Form;
use yii\base\Event;

class AfterSubmitEvent extends Event
{
/** @var Form */
private $form;

/** @var Submission */
private $submission;

/**
* @param Form $form
* @param Submission|null $submission
*/
public function __construct(Form $form, Submission $submission = null)
{
$this->form = $form;
$this->submission = $submission;

parent::__construct();
}

/**
* @return Form
*/
public function getForm(): Form
{
return $this->form;
}

/**
* @return Submission|null
*/
public function getSubmission()
{
return $this->submission;
}
}
30 changes: 30 additions & 0 deletions src/Events/Forms/BeforeSubmitEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Solspace\Freeform\Events\Forms;

use craft\events\CancelableEvent;
use Solspace\Freeform\Library\Composer\Components\Form;

class BeforeSubmitEvent extends CancelableEvent
{
/** @var Form */
private $form;

/**
* @param Form $form
*/
public function __construct(Form $form)
{
$this->form = $form;

parent::__construct();
}

/**
* @return Form
*/
public function getForm(): Form
{
return $this->form;
}
}
18 changes: 9 additions & 9 deletions src/Freeform.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ class Freeform extends Plugin
const VERSION_CACHE_TIMESTAMP_KEY = 'freeform_version_timestamp';
const VERSION_CACHE_TTL = 86400; // 24-hours

const PERMISSION_FORMS_ACCESS = 'freeform-formsAccess';
const PERMISSION_FORMS_MANAGE = 'freeform-formsManage';
const PERMISSION_FIELDS_ACCESS = 'freeform-fieldsAccess';
const PERMISSION_FIELDS_MANAGE = 'freeform-fieldsManage';
const PERMISSION_SETTINGS_ACCESS = 'freeform-settingsAccess';
const PERMISSION_SUBMISSIONS_ACCESS = 'freeform-submissionsAccess';
const PERMISSION_SUBMISSIONS_MANAGE = 'freeform-submissionsManage';
const PERMISSION_NOTIFICATIONS_ACCESS = 'freeform-notificationsAccess';
const PERMISSION_NOTIFICATIONS_MANAGE = 'freeform-notificationsManage';
const PERMISSION_FORMS_ACCESS = 'freeform-formsAccess';
const PERMISSION_FORMS_MANAGE = 'freeform-formsManage';
const PERMISSION_FIELDS_ACCESS = 'freeform-fieldsAccess';
const PERMISSION_FIELDS_MANAGE = 'freeform-fieldsManage';
const PERMISSION_SETTINGS_ACCESS = 'freeform-settingsAccess';
const PERMISSION_SUBMISSIONS_ACCESS = 'freeform-submissionsAccess';
const PERMISSION_SUBMISSIONS_MANAGE = 'freeform-submissionsManage';
const PERMISSION_NOTIFICATIONS_ACCESS = 'freeform-notificationsAccess';
const PERMISSION_NOTIFICATIONS_MANAGE = 'freeform-notificationsManage';

const EVENT_REGISTER_SUBNAV_ITEMS = 'registerSubnavItems';

Expand Down
53 changes: 45 additions & 8 deletions src/Library/Composer/Components/AbstractField.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ abstract class AbstractField implements FieldInterface, \JsonSerializable
/** @var bool */
protected $required = false;

/** @var array */
protected $errors;

/** @var CustomFieldAttributes */
protected $customAttributes;

/** @var int */
protected $pageIndex;

/** @var array */
protected $errors;

/** @var array */
private $inputClasses;

Expand Down Expand Up @@ -298,18 +298,22 @@ public function isInputOnly(): bool
*/
public function isValid(): bool
{
$this->errors = $this->validate();
$this->addErrors($this->validate());

return empty($this->errors);
}

/**
* Returns an array of error messages
*
* @return array|null
* @return array
*/
public function getErrors()
public function getErrors(): array
{
if (null === $this->errors) {
$this->errors = [];
}

return $this->errors;
}

Expand All @@ -323,6 +327,39 @@ public function hasErrors(): bool
return !empty($errors);
}

/**
* @param array|null $errors
*
* @return $this
*/
public function addErrors(array $errors = null): AbstractField
{
if (empty($errors)) {
return $this;
}

$existingErrors = $this->getErrors();
$existingErrors = array_merge($existingErrors, $errors);

$existingErrors = array_unique($existingErrors);

$this->errors = $existingErrors;

return $this;
}

/**
* @param string $error
*
* @return $this
*/
public function addError(string $error): AbstractField
{
$this->addErrors([$error]);

return $this;
}

/**
* Return the field TYPE
*
Expand Down Expand Up @@ -639,7 +676,7 @@ protected function onAfterInputHtml(): string
*/
protected function validate(): array
{
$errors = [];
$errors = $this->getErrors();

if ($this instanceof ObscureValueInterface) {
$value = $this->getActualValue($this->getValue());
Expand Down Expand Up @@ -700,7 +737,7 @@ protected function translate(string $string = null, array $variables = []): stri
*
* @return \Twig_Markup
*/
private function renderRaw($output): \Twig_Markup
protected function renderRaw($output): \Twig_Markup
{
return Template::raw($output);
}
Expand Down
25 changes: 21 additions & 4 deletions src/Library/Composer/Components/Fields/CheckboxField.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,27 @@ public function setIsCheckedByPost(bool $isChecked)
public function getInputHtml(): string
{
$attributes = $this->getCustomAttributes();
$output = '';

$output .= '<input '
$output = '<input '
. $this->getAttributeString('name', $this->getHandle())
. $this->getAttributeString('type', FieldInterface::TYPE_HIDDEN)
. $this->getAttributeString('value', '', false)
. $attributes->getInputAttributesAsString()
. '/>';

$output .= '<input '
$output .= $this->getSingleInputHtml();

return $output;
}

/**
* @return string
*/
public function getSingleInputHtml(): string
{
$attributes = $this->getCustomAttributes();

return '<input '
. $this->getAttributeString('name', $this->getHandle())
. $this->getAttributeString('type', $this->getType())
. $this->getAttributeString('id', $this->getIdAttribute())
Expand All @@ -103,8 +114,14 @@ public function getInputHtml(): string
. $attributes->getInputAttributesAsString()
. ($this->isChecked() ? 'checked ' : '')
. '/>';
}

return $output;
/**
* @return \Twig_Markup
*/
public function renderSingleInput(): \Twig_Markup
{
return $this->renderRaw($this->getSingleInputHtml());
}

/**
Expand Down
Loading

0 comments on commit 0927383

Please sign in to comment.