Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
novicell/custom_forms / src / Plugin / CustomForms / FieldMapping / CustomFormsFieldMappingBase.php
Size: Mime:
<?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);
  }
}