function KeyBase::buildKeyColumns
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Database/SchemaDefinition/KeyBase.php \Drupal\Core\Database\SchemaDefinition\KeyBase::buildKeyColumns()
Builds an array of KeyColumn objects from a mixed list of columns.
Parameters
list<KeyColumn|string|array{0:string, 1:int}> $rawColumns: A mix of key column specifiers, being KeyColumn objects, strings naming columns, or arrays of two elements, column name and length, specifying a prefix of the named column.
bool $limitedLengthAllowed: Defines if limited length columns are allowed.
Return value
list<KeyColumn> The normalized list of KeyColumn objects.
2 calls to KeyBase::buildKeyColumns()
- ForeignKey::__construct in core/
lib/ Drupal/ Core/ Database/ SchemaDefinition/ ForeignKey.php - Constructor.
- KeyBase::__construct in core/
lib/ Drupal/ Core/ Database/ SchemaDefinition/ KeyBase.php - Constructor.
File
-
core/
lib/ Drupal/ Core/ Database/ SchemaDefinition/ KeyBase.php, line 52
Class
- KeyBase
- Base class for table keys (primary, unique, index).
Namespace
Drupal\Core\Database\SchemaDefinitionCode
protected function buildKeyColumns(array $rawColumns, bool $limitedLengthAllowed) : array {
$columns = [];
foreach ($rawColumns as $rawColumn) {
if ($rawColumn instanceof KeyColumn) {
if (!$limitedLengthAllowed && $rawColumn->length !== NULL) {
throw new SchemaDefinitionException('Limited length columns not allowed in this context');
}
$columns[] = $rawColumn;
}
elseif (is_array($rawColumn)) {
if (!$limitedLengthAllowed) {
throw new SchemaDefinitionException('Limited length columns not allowed in this context');
}
$columns[] = new KeyColumn($rawColumn[0], $rawColumn[1]);
}
elseif (is_string($rawColumn)) {
$columns[] = new KeyColumn($rawColumn);
}
else {
throw new SchemaDefinitionException("Key columns should be defined as an array of KeyColumn objects, or strings indicating the column name, or arrays with column name and limited length");
}
}
return $columns;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.