-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed merge strategies and finish basic abstraction
- Loading branch information
Showing
7 changed files
with
239 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace venveo\bulkedit\fields\processors; | ||
|
||
use craft\base\Element; | ||
use craft\base\Field; | ||
use craft\base\FieldInterface; | ||
use craft\fields\BaseRelationField; | ||
use venveo\bulkedit\base\AbstractFieldProcessor; | ||
use venveo\bulkedit\services\BulkEdit; | ||
|
||
class RelationFieldProcessor extends AbstractFieldProcessor | ||
{ | ||
|
||
/** | ||
* The fully qualified class name for the element this processor works on | ||
* @return array | ||
*/ | ||
public static function getSupportedFields(): array | ||
{ | ||
$fields = [ | ||
BaseRelationField::class | ||
]; | ||
|
||
return $fields; | ||
} | ||
|
||
/** | ||
* Returns the supported strategies for this field type | ||
* @return array | ||
*/ | ||
public static function getSupportedStrategies(): array | ||
{ | ||
return [BulkEdit::STRATEGY_REPLACE, BulkEdit::STRATEGY_SUBTRACT, BulkEdit::STRATEGY_MERGE]; | ||
} | ||
|
||
public static function performSubtraction(Element $element, Field $field, $value): void | ||
{ | ||
$fieldHandle = $field->handle; | ||
$originalValue = $element->getFieldValue($fieldHandle); | ||
$ids = $originalValue->ids(); | ||
$ids = array_diff($ids, $value); | ||
$element->setFieldValue($fieldHandle, $ids); | ||
} | ||
|
||
public static function performMerge(Element $element, Field $field, $value): void | ||
{ | ||
$originalValue = $element->getFieldValue($field->handle); | ||
$fieldHandle = $field->handle; | ||
$ids = $originalValue->ids(); | ||
$ids = array_merge($ids, $value); | ||
$element->setFieldValue($fieldHandle, $ids); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.