Skip to content

Commit

Permalink
Merge pull request #9 from DestinationCore/updates/craft-4
Browse files Browse the repository at this point in the history
Craft 4
  • Loading branch information
TraffordFewster authored May 5, 2023
2 parents 40e7c57 + 96b3707 commit 3c354dd
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# COMPOSER
/vendor
composer.lock

# BUILD FILES
/bower_components/*
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## 2.0.0 - 2023-05-05
### Added
- Craft 4 Support

## 1.5.0 - 2023-02-15
### Added
- CP notice when a date has been added to exceptions.
Expand Down
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "unionco/calendarize",
"description": "A calendar field type providing functionality for recurrence.",
"version": "1.5.0",
"version": "2.0.0",
"type": "craft-plugin",
"keywords": [
"craft",
Expand All @@ -22,10 +22,10 @@
}
],
"require": {
"craftcms/cms": "^3.0",
"craftcms/cms": "^4.0",
"ext-intl": "*",
"rlanvin/php-rrule": "^1.6",
"nesbot/carbon": "^2.59"
"nesbot/carbon": "^2.66"
},
"autoload": {
"psr-4": {
Expand All @@ -38,5 +38,11 @@
"documentationUrl": "https://github.com/unionco/calendarize/blob/master/README.md",
"changelogUrl": "https://raw.githubusercontent.com/unionco/calendarize/master/CHANGELOG.md",
"class": "unionco\\calendarize\\Calendarize"
},
"config": {
"allow-plugins": {
"yiisoft/yii2-composer": true,
"craftcms/plugin-installer": true
}
}
}
15 changes: 8 additions & 7 deletions src/Calendarize.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Craft;
use craft\base\Element;
use craft\base\Model;
use craft\base\Plugin;
use craft\elements\Entry;
use craft\elements\db\ElementQuery;
Expand Down Expand Up @@ -55,22 +56,22 @@ class Calendarize extends Plugin
/**
* @var boolean
*/
public $hasCpSettings = true;
public bool $hasCpSettings = true;

/**
* @var boolean
*/
public $hasCpSection = false;
public bool $hasCpSection = false;

/**
* @var string
*/
public $changelogUrl = "https://raw.githubusercontent.com/unionco/calendarize/master/CHANGELOG.md";
public ?string $changelogUrl = "https://raw.githubusercontent.com/unionco/calendarize/master/CHANGELOG.md";

/**
* @var string
*/
public $schemaVersion = '1.3.0';
public string $schemaVersion = '1.3.0';

// Public Methods
// =========================================================================
Expand Down Expand Up @@ -162,7 +163,7 @@ function (Event $event) {
);
}

public function afterInstall()
public function afterInstall(): void
{
parent::afterInstall();
}
Expand All @@ -173,15 +174,15 @@ public function afterInstall()
/**
* @inheritdoc
*/
protected function createSettingsModel()
protected function createSettingsModel(): Model
{
return new Settings();
}

/**
* @inheritdoc
*/
protected function settingsHtml(): string
protected function settingsHtml(): ?string
{
return Craft::$app->view->renderTemplate(
'calendarize/settings',
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class DefaultController extends Controller
// =========================================================================

/**
* @var bool|array Allows anonymous access to this controller's actions.
* @var array|int|bool Allows anonymous access to this controller's actions.
* The actions must be in 'kebab-case'
* @access protected
*/
protected $allowAnonymous = ['make-ics', 'make-section-ics'];
protected array|int|bool $allowAnonymous = ['make-ics', 'make-section-ics'];

// Public Methods
// =========================================================================
Expand Down
16 changes: 8 additions & 8 deletions src/fields/CalendarizeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static function hasContentColumn(): bool
/**
* @inheritdoc
*/
public function rules()
public function rules(): array
{
$rules = parent::rules();
return $rules;
Expand All @@ -129,31 +129,31 @@ public function getElementValidationRules(): array
/**
* @inheritdoc
*/
public function normalizeValue($value, ElementInterface $element = null)
public function normalizeValue(mixed $value, ElementInterface $element = null): mixed
{
return Calendarize::$plugin->calendar->getField($this, $element, $value);
}

/**
* @inheritdoc
*/
public function modifyElementsQuery(ElementQueryInterface $query, $value)
public function modifyElementsQuery(ElementQueryInterface $query, mixed $value): void
{
// For whatever reason, this function can be
// run BEFORE Calendarize has been initialized
if (!Calendarize::$plugin) {
return null;
return;
}

Calendarize::$plugin->calendar->modifyElementsQuery($this, $query, $value);

return null;
return;
}

/**
* @inheritdoc
*/
public function afterElementSave(ElementInterface $element, bool $isNew)
public function afterElementSave(ElementInterface $element, bool $isNew): void
{
Calendarize::$plugin->calendar->saveField($this, $element);
parent::afterElementSave($element, $isNew);
Expand All @@ -162,7 +162,7 @@ public function afterElementSave(ElementInterface $element, bool $isNew)
/**
* @inheritdoc
*/
public function getTableAttributeHtml($value, ElementInterface $element): string
public function getTableAttributeHtml(mixed $value, ElementInterface $element): string
{
if (empty($value->startDate) && empty($value->endDate)) {
return '-';
Expand All @@ -181,7 +181,7 @@ public function getTableAttributeHtml($value, ElementInterface $element): string
/**
* @inheritdoc
*/
public function getInputHtml($value, ElementInterface $element = null): string
public function getInputHtml(mixed $value, ElementInterface $element = null): string
{
// Register our asset bundle
$view = Craft::$app->getView();
Expand Down
4 changes: 2 additions & 2 deletions src/models/CalendarizeModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ public function getCalendarIcsUrl($options = [])
/**
* @inheritdoc
*/
public function rules()
public function rules(): array
{
parent::rules();
return parent::rules();
}

// Private Methods
Expand Down
2 changes: 1 addition & 1 deletion src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Settings extends Model
/**
* @inheritdoc
*/
public function rules()
public function rules(): array
{
return [
[['allowTimeChanges'], 'boolean'],
Expand Down
4 changes: 2 additions & 2 deletions src/services/CalendarizeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function after($date, $criteria = [], $order = 'asc', $unique = false)
$allOccurrences = [];

foreach ($entries as $key => $entry) {
$fields = $entry->getFieldLayout()->getFields();
$fields = $entry->getFieldLayout()->getCustomFields();
$fieldIndex = array_search(CalendarizeField::class, array_map(function ($field) {
return get_class($field);
}, $fields));
Expand Down Expand Up @@ -172,7 +172,7 @@ public function between($start, $end, $criteria = [], $order = 'asc', $unique =
$allOccurrences = [];

foreach ($entries as $key => $entry) {
$fields = $entry->getFieldLayout()->getFields();
$fields = $entry->getFieldLayout()->getCustomFields();
$fieldIndex = array_search(CalendarizeField::class, array_map(function ($field) {
return get_class($field);
}, $fields));
Expand Down

0 comments on commit 3c354dd

Please sign in to comment.