Repository URL to install this package:
|
Version:
2.0.2 ▾
|
<?php
namespace Drupal\custom_forms\Plugin\CustomForms\FieldMapping;
use Drupal\Core\Plugin\PluginBase;
use Drupal\custom_forms\CustomFormItem;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class CustomFormsFieldMappingBase
*
* All mapping plugins must extend from this class.
*
* @package Drupal\custom_forms\Plugin\CustomForms\FieldMapping
*/
abstract class CustomFormsFieldMappingBase extends PluginBase implements CustomFormsFieldMappingInterface {
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition
);
}
/**
* {@inheritdoc}
*/
public function allowsMultiple() : bool {
return (bool) ($this->pluginDefinition['allow_multiple'] ?? FALSE);
}
/**
* {@inheritdoc}
*/
abstract public function getMappingIds(CustomFormItem $item, array $mapping_ids, $hide_sensitive = TRUE) : array;
/**
* {@inheritdoc}
*/
abstract public function mapValue(array $values, array $mapped_values, CustomFormItem $item, $hide_sensitive = TRUE) : array;
/**
* {@inheritdoc}
*/
public function isSensitive() : bool {
if (!empty($this->pluginDefinition['is_sensitive'])) {
return $this->pluginDefinition['is_sensitive'];
}
return FALSE;
}
/**
* @param string $needle
* @param array $array
*
* @return int
*/
protected function countMappings($needle, array $array) : int {
$result = [];
foreach($array as $key => $value){
if(strpos($key, $needle) === 0){
$result[$key] = $value;
}
}
return count($result);
}
}