Skip to content

Commit

Permalink
Fix to allow formSideBarWidget creation without supplying any "form".
Browse files Browse the repository at this point in the history
Found many calls to form() which isn't set nor required to be set when using "widgetFactory"
  • Loading branch information
JoelAlphonso committed May 24, 2017
1 parent bae5278 commit 30637f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/Charcoal/Admin/Ui/ActionContainerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,11 @@ protected function resolveActionType($action)
*/
protected function getActionRenderer()
{
$obj = null;
if ($this instanceof FormSidebarInterface) {
$obj = $this->form()->obj();
if ($this->form()) {
$obj = $this->form()->obj();
}
}

if ($this instanceof ObjectContainerInterface) {
Expand Down
38 changes: 22 additions & 16 deletions src/Charcoal/Admin/Widget/FormSidebarWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,17 @@ protected function parseAsSidebarActions(array $actions)
protected function defaultSidebarActions()
{
if ($this->defaultSidebarActions === null) {
$save = [
'label' => $this->form()->submitLabel(),
'ident' => 'save',
'buttonType' => 'submit',
'priority' => 90
];
$this->defaultSidebarActions = [ $save ];
$this->defaultSidebarActions = [];

if ($this->form()) {
$save = [
'label' => $this->form()->submitLabel(),
'ident' => 'save',
'buttonType' => 'submit',
'priority' => 90
];
$this->defaultSidebarActions[] = $save;
}
}

return $this->defaultSidebarActions;
Expand All @@ -448,7 +452,7 @@ public function jsActionPrefix()
public function isObjDeletable()
{
// Overridden by permissions
if (!$this->checkPermission('delete')) {
if (!$this->checkPermission('delete') || !$this->form()) {
return false;
}

Expand All @@ -474,7 +478,7 @@ public function isObjDeletable()
public function isObjResettable()
{
// Overridden by permissions
if (!$this->checkPermission('reset')) {
if (!$this->checkPermission('reset') || !$this->form()) {
return false;
}

Expand All @@ -499,7 +503,7 @@ public function isObjResettable()
public function isObjSavable()
{
// Overridden by permissions
if (!$this->checkPermission('save')) {
if (!$this->checkPermission('save') || !$this->form() ) {
return false;
}

Expand All @@ -524,7 +528,7 @@ public function isObjSavable()
public function isObjViewable()
{
// Overridden by permissions
if (!$this->checkPermission('view')) {
if (!$this->checkPermission('view') || !$this->form()) {
return false;
}

Expand Down Expand Up @@ -692,11 +696,13 @@ public function setShowFooter($showFooter)
*/
public function showLanguageSwitch()
{
$locales = count($this->translator()->availableLocales());
if ($locales > 1) {
foreach ($this->form()->formProperties() as $formProp) {
if ($formProp->property()->l10n()) {
return true;
if ($this->form()) {
$locales = count($this->translator()->availableLocales());
if ($locales > 1) {
foreach ($this->form()->formProperties() as $formProp) {
if ($formProp->property()->l10n()) {
return true;
}
}
}
}
Expand Down

0 comments on commit 30637f4

Please sign in to comment.