mirror of
https://github.com/getgrav/grav.git
synced 2026-03-04 03:21:33 +01:00
Fixed FlexIndex keys being lost when FlexCollection gets loaded
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
1. [](#bugfix)
|
||||
* Fixed validation for select field type with selectize
|
||||
* Fixed `Flex[class]::getType()` to return the same value in every class
|
||||
* Fixed `FlexIndex` keys being lost when `FlexCollection` gets loaded
|
||||
|
||||
# v1.6.0-rc.2
|
||||
## 02/07/2019
|
||||
|
||||
@@ -59,11 +59,15 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
|
||||
/**
|
||||
* @param array $entries
|
||||
* @param FlexDirectory $directory
|
||||
* @param string $keyField
|
||||
* @return static
|
||||
*/
|
||||
public static function createFromArray(array $entries, FlexDirectory $directory) : FlexCollectionInterface
|
||||
public static function createFromArray(array $entries, FlexDirectory $directory, string $keyField = null) : FlexCollectionInterface
|
||||
{
|
||||
return new static($entries, $directory);
|
||||
$instance = new static($entries, $directory);
|
||||
$instance->setKeyField($keyField);
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -399,26 +399,28 @@ class FlexDirectory implements FlexAuthorizeInterface
|
||||
|
||||
/**
|
||||
* @param array $entries
|
||||
* @param string $keyField
|
||||
* @return FlexCollectionInterface
|
||||
*/
|
||||
public function createCollection(array $entries): FlexCollectionInterface
|
||||
public function createCollection(array $entries, string $keyField = null): FlexCollectionInterface
|
||||
{
|
||||
/** @var string|FlexCollectionInterface $className */
|
||||
$className = $this->collectionClassName ?: $this->getCollectionClass();
|
||||
|
||||
return $className::createFromArray($entries, $this);
|
||||
return $className::createFromArray($entries, $this, $keyField);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $entries
|
||||
* @param string $keyField
|
||||
* @return FlexCollectionInterface
|
||||
*/
|
||||
public function createIndex(array $entries): FlexCollectionInterface
|
||||
public function createIndex(array $entries, string $keyField = null): FlexCollectionInterface
|
||||
{
|
||||
/** @var string|FlexIndexInterface $className */
|
||||
$className = $this->indexClassName ?: $this->getIndexClass();
|
||||
|
||||
return $className::createFromArray($entries, $this);
|
||||
return $className::createFromArray($entries, $this, $keyField);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -461,11 +463,12 @@ class FlexDirectory implements FlexAuthorizeInterface
|
||||
|
||||
/**
|
||||
* @param array $entries
|
||||
* @param string $keyField
|
||||
* @return FlexCollectionInterface
|
||||
*/
|
||||
public function loadCollection(array $entries): FlexCollectionInterface
|
||||
public function loadCollection(array $entries, string $keyField = null): FlexCollectionInterface
|
||||
{
|
||||
return $this->createCollection($this->loadObjects($entries));
|
||||
return $this->createCollection($this->loadObjects($entries), $keyField);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,11 +47,15 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
|
||||
/**
|
||||
* @param array[] $entries
|
||||
* @param FlexDirectory $directory
|
||||
* @param string $keyField
|
||||
* @return static
|
||||
*/
|
||||
public static function createFromArray(array $entries, FlexDirectory $directory) : FlexCollectionInterface
|
||||
public static function createFromArray(array $entries, FlexDirectory $directory, string $keyField = null) : FlexCollectionInterface
|
||||
{
|
||||
return new static($entries, $directory);
|
||||
$instance = new static($entries, $directory);
|
||||
$instance->setKeyField($keyField);
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -427,7 +431,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
|
||||
*/
|
||||
protected function loadElements(array $entries = null) : array
|
||||
{
|
||||
return $this->_flexDirectory->loadObjects($entries ?? $this->withKeyField()->getEntries());
|
||||
return $this->_flexDirectory->loadObjects($entries ?? $this->getEntries());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -436,7 +440,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
|
||||
*/
|
||||
protected function loadCollection(array $entries = null) : CollectionInterface
|
||||
{
|
||||
return $this->_flexDirectory->loadCollection($entries ?? $this->withKeyField()->getEntries());
|
||||
return $this->_flexDirectory->loadCollection($entries ?? $this->getEntries(), $this->_keyField);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,9 +25,10 @@ interface FlexCollectionInterface extends ObjectCollectionInterface, NestedObjec
|
||||
/**
|
||||
* @param array $entries
|
||||
* @param FlexDirectory $directory
|
||||
* @param string $keyField
|
||||
* @return static
|
||||
*/
|
||||
public static function createFromArray(array $entries, FlexDirectory $directory) : FlexCollectionInterface;
|
||||
public static function createFromArray(array $entries, FlexDirectory $directory, string $keyField = null) : FlexCollectionInterface;
|
||||
|
||||
/**
|
||||
* @param array $elements
|
||||
|
||||
Reference in New Issue
Block a user