Skip to content

Commit

Permalink
Fix ConditionalizableTrait resolution
Browse files Browse the repository at this point in the history
Fixed:
- Method `resolveConditionalLogic()` calling `form()` when it might be undefined
  • Loading branch information
mcaskill committed Oct 2, 2019
1 parent ff69f6c commit dcdcb32
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/Charcoal/Ui/ConditionalizableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

use InvalidArgumentException;

// From 'charcoal-view'
use Charcoal\View\ViewableInterface;
use Charcoal\View\ViewInterface;

/**
* Provides an entity with a condition.
*
Expand Down Expand Up @@ -108,10 +112,22 @@ protected function resolveConditionalLogic($condition)
{
if (is_callable([ $this, $condition ])) {
return !!$this->{$condition}();
} elseif (is_callable($condition)) {
}

if (is_callable($condition)) {
return !!$condition();
} elseif ($this->form()->obj()->view()) {
return !!$this->form()->obj()->renderTemplate($condition);
}

if (is_callable([ $this, 'form' ])) {
$form = $this->form();

if (is_callable([ $form, 'obj' ])) {
$obj = $form->obj();

if (($obj instanceof ViewableInterface) && ($obj->view() instanceof ViewInterface)) {
return !!$obj->renderTemplate($condition);
}
}
}

return !!$condition;
Expand Down

0 comments on commit dcdcb32

Please sign in to comment.