Skip to content

Commit

Permalink
Merge pull request #40 from muskie9/pull/emptyRelationLists
Browse files Browse the repository at this point in the history
BUGFIX if RecipePage does not exist it errors when creating new in some cases
  • Loading branch information
muskie9 authored Aug 30, 2021
2 parents 79668c3 + e872975 commit 0c41f92
Showing 1 changed file with 53 additions and 52 deletions.
105 changes: 53 additions & 52 deletions src/Page/RecipePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,70 +136,71 @@ public function getCMSFields()
TextField::create('Difficulty')
->setTitle('Difficulty'),
]
)->setTitle('Info')
)->setTitle('Info'),
],
'Content'
);

$fields->addFieldToTab(
'Root.Ingredients',
$ingredients = GridField::create(
'Ingredients',
'Ingredients',
$this->Ingredients(),
$ingredientsConfig = GridFieldConfig_RelationEditor::create()
)
);

$fields->addFieldToTab(
'Root.Directions',
$directions = GridField::create(
'Directions',
'Directions',
$this->Directions(),
$directionsConfig = GridFieldConfig_RelationEditor::create()
)
);
if ($this->exists()) {
$fields->addFieldToTab(
'Root.Ingredients',
$ingredients = GridField::create(
'Ingredients',
'Ingredients',
$this->Ingredients(),
$ingredientsConfig = GridFieldConfig_RelationEditor::create()
)
);

$fields->addFieldsToTab(
'Root.Categories',
[
ReadonlyField::create('PrimaryCategoryDisplay')
->setTitle('Primary Category')
->setValue($this->getPrimaryCategory()->Title),
$categories = GridField::create(
'Categories',
'Additional Categories',
$this->Categories()->exclude('ID', $this->ParentID)->sort('SortOrder'),
$catConfig = GridFieldConfig_RelationEditor::create()
$fields->addFieldToTab(
'Root.Directions',
$directions = GridField::create(
'Directions',
'Directions',
$this->Directions(),
$directionsConfig = GridFieldConfig_RelationEditor::create()
)
]
);
);

$ingredientsConfig
->addComponent(new GridFieldOrderableRows('Sort'))
->removeComponentsByType(GridFieldAddExistingAutocompleter::class);

$directionsConfig
->addComponent(new GridFieldOrderableRows('Sort'))
->removeComponentsByType(GridFieldAddExistingAutocompleter::class);

$catConfig
->removeComponentsByType([
GridFieldAddExistingAutocompleter::class,
GridFieldArchiveAction::class,
GridFieldEditButton::class,
])
->addComponents(
new GridFieldOrderableRows('SortOrder'),
$list = new GridFieldAddExistingSearchButton()
$fields->addFieldsToTab(
'Root.Categories',
[
ReadonlyField::create('PrimaryCategoryDisplay')
->setTitle('Primary Category')
->setValue($this->getPrimaryCategory()->Title),
$categories = GridField::create(
'Categories',
'Additional Categories',
$this->Categories()->exclude('ID', $this->ParentID)->sort('SortOrder'),
$catConfig = GridFieldConfig_RelationEditor::create()
),
]
);

$list->setSearchList(RecipeCategoryPage::get()->exclude('ID', $this->ParentID));
$ingredientsConfig
->addComponent(new GridFieldOrderableRows('Sort'))
->removeComponentsByType(GridFieldAddExistingAutocompleter::class);

$directionsConfig
->addComponent(new GridFieldOrderableRows('Sort'))
->removeComponentsByType(GridFieldAddExistingAutocompleter::class);

$catConfig
->removeComponentsByType([
GridFieldAddExistingAutocompleter::class,
GridFieldArchiveAction::class,
GridFieldEditButton::class,
])
->addComponents(
new GridFieldOrderableRows('SortOrder'),
$list = new GridFieldAddExistingSearchButton()
);

$list->setSearchList(RecipeCategoryPage::get()->exclude('ID', $this->ParentID));
}
});

return parent::getCMSFields();
;
}

/**
Expand Down

0 comments on commit 0c41f92

Please sign in to comment.