Skip to content

Commit

Permalink
Duplicate action
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Dec 28, 2023
1 parent dab62b0 commit d523c56
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/elements/ExportElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ public function canSave(User $user): bool
return true;
}

/**
* @inheritDoc
*/
public function canDuplicate(User $user): bool
{
return true;
}

/**
* @inheritDoc
*/
Expand All @@ -140,21 +148,23 @@ public function scenarios()
*/
public function validate($attributeNames = null, $clearErrors = true): bool
{

if ($this->scenario == 'step1') {
$settings = $this->getSettings();
if (!$settings['group']) {
$this->addError("group", "Group cannot be blank");
}
}
return parent::validate();

}


public function getGroupLabel()
{
$elementSettings = Exporter::getInstance()->elements->getElementTypeSettings($this->elementType);
$settings = $this->getSettings();
$group = array_filter($elementSettings['group']['items'], function($group) use ($settings) {
$group = array_filter($elementSettings['group']['items'], function ($group) use ($settings) {
if ($group->id == $settings['group']) {
return true;
}
Expand All @@ -179,11 +189,6 @@ protected static function defineTableAttributes(): array
];
}

public static function find(): ElementQueryInterface
{
return new ExportElementQuery(static::class);
}

protected static function defineSources(string $context = null): array
{
return [
Expand All @@ -195,6 +200,11 @@ protected static function defineSources(string $context = null): array
];
}

public static function find(): ElementQueryInterface
{
return new ExportElementQuery(static::class);
}

public function getUiLabel(): string
{
return $this->name;
Expand Down Expand Up @@ -228,7 +238,7 @@ public function getSupportedFields(Element $element): array
$supportedFields = Exporter::getInstance()->fields->getAvailableFieldTypes();
$elementFields = $element->fieldLayout->getCustomFields();

return array_filter($elementFields, function($field) {
return array_filter($elementFields, function ($field) {
// TODO How to handle unsupported fields here?
return true;

Expand Down Expand Up @@ -318,7 +328,7 @@ public function afterDelete(): void
{
if (!$this->propagating) {
Db::delete(ExportRecord::tableName(), [
'id' => $this->id, ]
'id' => $this->id,]
);
}
parent::afterDelete();
Expand Down

0 comments on commit d523c56

Please sign in to comment.