Skip to content

Commit

Permalink
Start field processor abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
Mosnar committed Jul 22, 2019
1 parent 46f19e2 commit 94a3113
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/base/AbstractFieldProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace venveo\bulkedit\base;

use craft\base\Element;
use craft\base\Field;
use craft\base\FieldInterface;

abstract class AbstractFieldProcessor implements FieldProcessorInterface
{
public static function performMerge(Element $element, Field $field, $value): void
{

}

public static function performReplacement(Element $element, Field $field, $value): void
{

}

public static function performSubtraction(Element $element, Field $field, $value): void
{

}

/**
* @param FieldInterface $field
* @return bool
*/
public static function supportsField(FieldInterface $field): bool
{
foreach (self::getSupportedFields() as $fieldType) {
if ($field instanceof $fieldType) {
return true;
}
}
return false;
}
}
25 changes: 25 additions & 0 deletions src/base/FieldProcessorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace venveo\bulkedit\base;

use craft\base\Element;
use craft\base\Field;

interface FieldProcessorInterface
{
/**
* An array of class names for supported fields
* @return array
*/
public static function getSupportedFields(): array;

/**
* Returns the supported strategies for this field type
* @return array
*/
public static function getSupportedStrategies(): array;

public static function performReplacement(Element $element, Field $field, $value): void;
public static function performSubtraction(Element $element, Field $field, $value): void;
public static function performMerge(Element $element, Field $field, $value): void;
}
68 changes: 68 additions & 0 deletions src/fields/processors/PlainTextProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace venveo\bulkedit\fields\processors;

use craft\base\Element;
use craft\base\Field;
use craft\fields\Checkboxes;
use craft\fields\Color;
use craft\fields\Date;
use craft\fields\Dropdown;
use craft\fields\Email;
use craft\fields\Lightswitch;
use craft\fields\MultiSelect;
use craft\fields\Number;
use craft\fields\PlainText;
use craft\fields\RadioButtons;
use craft\fields\Table;
use craft\redactor\Field as RedactorField;
use craft\fields\Url;
use venveo\bulkedit\base\AbstractFieldProcessor;
use venveo\bulkedit\services\BulkEdit;

class PlainTextProcessor extends AbstractFieldProcessor
{

/**
* The fully qualified class name for the element this processor works on
* @return array
*/
public static function getSupportedFields(): array
{
$fields = [
PlainText::class,
Number::class,
Color::class,
Checkboxes::class,
Dropdown::class,
Date::class,
Table::class,
RadioButtons::class,
Lightswitch::class,
Url::class,
Email::class,
MultiSelect::class
];

if (\Craft::$app->plugins->isPluginInstalled('redactor')) {
$fields[] = RedactorField::class;
}

return $fields;
}

/**
* Returns the supported strategies for this field type
* @return array
*/
public static function getSupportedStrategies(): array
{
return [BulkEdit::STRATEGY_REPLACE];
}


public static function performReplacement(Element $element, Field $field, $value): void
{

}
}

0 comments on commit 94a3113

Please sign in to comment.