diff --git a/packages/plugin/src/Elements/Event.php b/packages/plugin/src/Elements/Event.php index 8e856c1..4fa1310 100644 --- a/packages/plugin/src/Elements/Event.php +++ b/packages/plugin/src/Elements/Event.php @@ -19,7 +19,6 @@ use craft\i18n\Locale; use craft\models\FieldLayout; use craft\models\FieldLayoutTab; -use craft\web\UploadedFile; use Illuminate\Support\Collection; use RRule\RRule; use Solspace\Calendar\Calendar; @@ -146,8 +145,6 @@ class Event extends Element implements \JsonSerializable /** @var Event[] */ private $occurrenceCache = []; - private ?string $_fieldParamNamePrefix = null; - /** * Event constructor. */ @@ -1323,6 +1320,11 @@ public function diffInDays(self $event): int return DateHelper::carbonDiffInDays($this->getStartDate(), $event->getStartDate()); } + public function canDuplicate(User $user): bool + { + return $this->isEditable($this); + } + public function canDelete(User $user): bool { return $this->isEditable($this); @@ -1615,65 +1617,37 @@ public static function actions(string $source): array return $event->actions; } - public function setFieldValuesFromRequest(string $paramNamespace = ''): void + public function attributes(): array { - $this->setFieldParamNamespace($paramNamespace); + $names = parent::attributes(); + $names[] = 'authorId'; + $names[] = 'author'; - if (isset($this->_fieldParamNamePrefix)) { - $values = \Craft::$app->getRequest()->getBodyParam($paramNamespace, []); - } else { - $values = \Craft::$app->getRequest()->getBodyParams(); + // Hide Author from Craft Solo + if (\Craft::Solo === \Craft::$app->getEdition()) { + unset($names['authorId'], $names['author']); } - // Run through this multiple times, in case any fields become visible as a result of other field value changes - $processedFields = []; - do { - $processedAnyFields = false; - foreach ($this->fieldLayoutFields(true) as $field) { - // Have we already processed this field? - if (isset($processedFields[$field->id])) { - continue; - } + return $names; + } - $processedFields[$field->id] = true; - $processedAnyFields = true; - - // Do we have any post data for this field? - if (isset($values[$field->handle])) { - $value = $values[$field->handle]; - } elseif ( - isset($this->_fieldParamNamePrefix) - && UploadedFile::getInstancesByName("{$this->_fieldParamNamePrefix}.{$field->handle}") - ) { - // A file was uploaded for this field - $value = null; - } else { - continue; - } + public function extraFields(): array + { + $names = parent::extraFields(); + $names[] = 'authorId'; + $names[] = 'author'; - // Add in additional support for other field types - if ($field instanceof \benf\neo\Field) { - if (!empty($values[$field->handle]['blocks']) && \is_array($values[$field->handle]['blocks'])) { - $index = 0; - $blocks = []; - foreach ($values[$field->handle]['blocks'] as $block) { - $blocks['new'.$index] = $block; - ++$index; - } - $this->setFieldValues([$field->handle => $blocks]); - } else { - $this->setFieldValues([$field->handle => '']); - } - } else { - $this->setFieldValueFromRequest($field->handle, $value); - } - } - } while ($processedAnyFields); + // Hide Author from Craft Solo + if (\Craft::Solo === \Craft::$app->getEdition()) { + unset($names['authorId'], $names['author']); + } + + return $names; } - public function setFieldParamNamespace(string $namespace): void + protected static function prepElementQueryForTableAttribute(ElementQueryInterface $elementQuery, string $attribute): void { - $this->_fieldParamNamePrefix = '' !== $namespace ? $namespace : null; + parent::prepElementQueryForTableAttribute($elementQuery, $attribute); } protected static function defineSources(string $context = null): array diff --git a/packages/plugin/src/templates/events/_edit.html b/packages/plugin/src/templates/events/_edit.html index 0ed4e8f..f2dbb2c 100644 --- a/packages/plugin/src/templates/events/_edit.html +++ b/packages/plugin/src/templates/events/_edit.html @@ -4,6 +4,7 @@ {% set calendarHandle = calendar.handle|default %} {% set selectedSubnavItem = 'events' %} {% set saveShortcutRedirect = continueEditingUrl %} +{% set elementType = 'Solspace\\Calendar\\Elements\\Event' %} {% set crumbs = [ { label: craft.calendar.name, url: url('calendar') }, @@ -58,31 +59,19 @@