Skip to content
Snippets Groups Projects

Issue #3357117: Implode does not work for arrays

All threads resolved!
Merged Jürgen Haas requested to merge issue/eca_tamper-3357117:3357117-implode-does-not into 1.0.x
All threads resolved!
Files
2
@@ -2,7 +2,12 @@
namespace Drupal\eca_tamper\Plugin\Action;
use Drupal\Core\Field\EntityReferenceFieldItemListInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TypedData\ComplexDataDefinitionInterface;
use Drupal\Core\TypedData\ComplexDataInterface;
use Drupal\Core\TypedData\ListInterface;
use Drupal\eca\Plugin\Action\ConfigurableActionBase;
use Drupal\eca_tamper\Plugin\TamperTrait;
use Drupal\tamper\Exception\SkipTamperDataException;
@@ -50,7 +55,37 @@ class Tamper extends ConfigurableActionBase {
$this->tokenServices->replaceClear($this->configuration[$key]);
}
$tamperPlugin->setConfiguration($config);
$data = $this->tokenServices->replaceClear($this->configuration['eca_data']);
if (empty($tamperPlugin->getPluginDefinition()['handle_multiples'])) {
$data = $this->tokenServices->replaceClear($this->configuration['eca_data']);
}
else {
$data = $this->tokenServices->getOrReplace($this->configuration['eca_data']);
if ($data instanceof ComplexDataInterface) {
$data = $data->toArray();
}
elseif ($data instanceof ListInterface) {
$item_definition = $data->getItemDefinition();
$main_property = $item_definition instanceof ComplexDataDefinitionInterface ? $item_definition->getMainPropertyName() : NULL;
$data = $data->getValue() ?? [];
array_walk($data, static function (&$item) use ($main_property) {
if (isset($main_property) && is_array($item)) {
$item = $item[$main_property];
}
elseif (is_scalar($item)) {
// Nothing to do.
}
else {
$item = NULL;
}
});
$data = array_filter($data, static function ($item) {
return NULL !== $item;
});
}
if (!is_array($data)) {
$data = [$data];
}
}
// @todo We may want to call the validate and submit functions for the
// tamper plugin so that they can update configuration based on final values
// like e.g. required for the KeywordFilter plugin.
Loading