Skip to content

Commit

Permalink
Fixed segments in Craft 3.7.0 and above
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Aug 5, 2021
1 parent a2ea98b commit fc1e4ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Campaign

## 1.20.2 - 2021-08-05
### Fixed
- Fixed a bug in which segments were not working with fields created in Craft 3.7.0 and above ([#241](https://github.com/putyourlightson/craft-campaign/issues/241)).

## 1.20.1 - 2021-07-27
### Fixed
- Fixed a bug in which the mime type of a CSV file was not recognised in PHP 8.0 when importing ([#240](https://github.com/putyourlightson/craft-campaign/issues/240)).
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": "putyourlightson/craft-campaign",
"description": "Send and manage email campaigns, contacts and mailing lists.",
"version": "1.20.1",
"version": "1.20.2",
"type": "craft-plugin",
"homepage": "https://putyourlightson.com/plugins/campaign",
"license": "proprietary",
Expand Down
10 changes: 9 additions & 1 deletion src/helpers/SegmentHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use craft\fields\PlainText;
use craft\fields\RadioButtons;
use craft\fields\Url;
use craft\helpers\ElementHelper;
use putyourlightson\campaign\Campaign;
use putyourlightson\campaign\events\RegisterSegmentAvailableFieldsEvent;
use putyourlightson\campaign\events\RegisterSegmentFieldOperatorsEvent;
Expand Down Expand Up @@ -139,9 +140,16 @@ public static function getAvailableFields(): array
$fieldType = get_class($field);

if (!empty($supportedFields[$fieldType])) {
$fieldColumnPrefix = $field->columnPrefix ?? Craft::$app->getContent()->fieldColumnPrefix;
$fieldColumn = $fieldColumnPrefix.$field->handle;

if (version_compare(Craft::$app->version, '3.7.0', '>=')) {
$fieldColumn = ElementHelper::fieldColumnFromField($field);
}

$availableFields[] = [
'type' => $fieldType,
'handle' => 'field_'.$field->handle,
'handle' => $fieldColumn,
'name' => $field->name,
'options' => ($field instanceof BaseOptionsField ? $field->options : null),
];
Expand Down

0 comments on commit fc1e4ed

Please sign in to comment.