Skip to content

Commit

Permalink
Use state to avoid infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Jun 18, 2020
1 parent 47c8f40 commit 96890a9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
4 changes: 0 additions & 4 deletions src/Action/RetrieveAutocompleteItemsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ private function retrieveFilterFieldDescription(
AdminInterface $admin,
string $field
): FieldDescriptionInterface {
$admin->getFilterFieldDescriptions();

$fieldDescription = $admin->getFilterFieldDescription($field);

if (!$fieldDescription) {
Expand All @@ -208,8 +206,6 @@ private function retrieveFormFieldDescription(
AdminInterface $admin,
string $field
): FieldDescriptionInterface {
$admin->getFormFieldDescriptions();

$fieldDescription = $admin->getFormFieldDescription($field);

if (!$fieldDescription) {
Expand Down
27 changes: 21 additions & 6 deletions src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,14 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A
* @var array<string, bool>
*/
protected $loaded = [
'view_fields' => false,
'view_groups' => false,
'view_fields' => false, // NEXT_MAJOR: Remove this unused value.
'view_groups' => false, // NEXT_MAJOR: Remove this unused value.
'routes' => false,
'tab_menu' => false,
'show' => false,
'list' => false,
'form' => false,
'datagrid' => false,
];

/**
Expand Down Expand Up @@ -845,12 +849,17 @@ public function getFilterParameters()
return $parameters;
}

/**
* NEXT_MAJOR: Change the visibility to protected (similar to buildShow, buildForm, ...).
*/
public function buildDatagrid()
{
if ($this->datagrid) {
if ($this->loaded['datagrid']) {
return;
}

$this->loaded['datagrid'] = true;

$filterParameters = $this->getFilterParameters();

// transform _sort_by from a string to a FieldDescriptionInterface for the datagrid.
Expand Down Expand Up @@ -3255,10 +3264,12 @@ protected function configureTabMenu(ItemInterface $menu, $action, ?AdminInterfac
*/
protected function buildShow()
{
if ($this->show) {
if ($this->loaded['show']) {
return;
}

$this->loaded['show'] = true;

$this->show = $this->getShowBuilder()->getBaseList();
$mapper = new ShowMapper($this->getShowBuilder(), $this->show, $this);

Expand All @@ -3274,10 +3285,12 @@ protected function buildShow()
*/
protected function buildList()
{
if ($this->list) {
if ($this->loaded['list']) {
return;
}

$this->loaded['list'] = true;

$this->list = $this->getListBuilder()->getBaseList();
$mapper = new ListMapper($this->getListBuilder(), $this->list, $this);

Expand Down Expand Up @@ -3333,10 +3346,12 @@ protected function buildList()
*/
protected function buildForm()
{
if ($this->form) {
if ($this->loaded['form']) {
return;
}

$this->loaded['form'];

// append parent object if any
// todo : clean the way the Admin class can retrieve set the object
if ($this->isChild() && $this->getParentAssociationMapping()) {
Expand Down

0 comments on commit 96890a9

Please sign in to comment.