Commit 4cd7df6a authored by catch's avatar catch
Browse files

Issue #3177545 by alexpott, andypost:...

Issue #3177545 by alexpott, andypost: \Drupal\field\Entity\FieldStorageConfig::getCardinality() needs to be more type safe
parent 63a34880
......@@ -632,11 +632,11 @@ public function getCardinality() {
/** @var \Drupal\Core\Field\FieldTypePluginManager $field_type_manager */
$field_type_manager = \Drupal::service('plugin.manager.field.field_type');
$definition = $field_type_manager->getDefinition($this->getType());
$enforced_cardinality = isset($definition['cardinality']) ? $definition['cardinality'] : NULL;
$enforced_cardinality = isset($definition['cardinality']) ? (int) $definition['cardinality'] : NULL;
// Enforced cardinality is a positive integer or -1.
if ($enforced_cardinality !== NULL && $enforced_cardinality < 1 && $enforced_cardinality !== FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
throw new FieldException("Invalid enforced cardinality '$enforced_cardinality'. Allowed values: a positive integer or -1.");
throw new FieldException("Invalid enforced cardinality '{$definition['cardinality']}'. Allowed values: a positive integer or -1.");
}
return $enforced_cardinality ?: $this->cardinality;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment