-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace AlterPHP\EasyAdminExtensionBundle\Configuration; | ||
|
||
use EasyCorp\Bundle\EasyAdminBundle\Configuration\ConfigPassInterface; | ||
|
||
/** | ||
* Initializes the configuration for all the views of each entity, which is | ||
* needed when some entity relies on the default configuration for some view. | ||
*/ | ||
class EmbeddedListSortConfigPass implements ConfigPassInterface | ||
{ | ||
public function process(array $backendConfig) | ||
{ | ||
$backendConfig = $this->processSortingConfig($backendConfig); | ||
|
||
return $backendConfig; | ||
} | ||
|
||
/** | ||
* @param array $backendConfig | ||
* | ||
* @return array | ||
*/ | ||
private function processSortingConfig(array $backendConfig) | ||
{ | ||
foreach ($backendConfig['entities'] as $entityName => $entityConfig) { | ||
if ( | ||
!isset($entityConfig['embeddedList']['sort']) | ||
&& isset($entityConfig['list']['sort']) | ||
) { | ||
$backendConfig['entities'][$entityName]['embeddedList']['sort'] = $entityConfig['list']['sort']; | ||
} elseif (isset($entityConfig['embeddedList']['sort'])) { | ||
$sortConfig = $entityConfig['embeddedList']['sort']; | ||
if (!is_string($sortConfig) && !is_array($sortConfig)) { | ||
throw new \InvalidArgumentException(sprintf('The "sort" option of the "embeddedList" view of the "%s" entity contains an invalid value (it can only be a string or an array).', $entityName)); | ||
} | ||
|
||
if (is_string($sortConfig)) { | ||
$sortConfig = array('field' => $sortConfig, 'direction' => 'DESC'); | ||
} else { | ||
$sortConfig = array('field' => $sortConfig[0], 'direction' => strtoupper($sortConfig[1])); | ||
} | ||
|
||
$backendConfig['entities'][$entityName]['embeddedList']['sort'] = $sortConfig; | ||
} | ||
} | ||
|
||
return $backendConfig; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters