You are here

public static function MapperHelper::getMaxValues in Feeds Paragraphs 8

Gets the maximum values for a field.

Gets the maximum values a field can hold, or the user choice of the maximum values.

Parameters

FieldConfigInterface $target: The target field.

Return value

int The maximum values

File

src/Utility/MapperHelper.php, line 264

Class

MapperHelper

Namespace

Drupal\feeds_para_mapper\Utility

Code

public static function getMaxValues(FieldConfigInterface $target, $configuration = null) {
  $res = NULL;
  $cardinality = (int) $target
    ->getFieldStorageDefinition()
    ->getCardinality();
  if (isset($configuration['max_values'])) {
    $unlimited = $cardinality === -1;
    $max_values = (int) $configuration['max_values'];
    $valid = $max_values >= -1 && $max_values !== 0;
    if ($max_values <= $cardinality && $valid || $unlimited && -1 <= $max_values && $valid) {
      $res = $max_values;
    }
    else {
      $res = $cardinality;
    }
  }
  else {
    $res = $cardinality;
  }
  return $res;
}