Skip to content

Commit

Permalink
Fix issue where the wrong presenter was being passed back
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanThompson committed Jun 16, 2016
1 parent d58cf22 commit 34418da
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/Preference/Command/GetPreference.php
@@ -0,0 +1,45 @@
<?php namespace Anomaly\PreferencesModule\Preference\Command;

use Anomaly\PreferencesModule\Preference\Contract\PreferenceRepositoryInterface;
use Illuminate\Contracts\Bus\SelfHandling;

/**
* Class GetPreference
*
* @link http://pyrocms.com/
* @author PyroCMS, Inc. <support@pyrocms.com>
* @author Ryan Thompson <ryan@pyrocms.com>
* @package Anomaly\PreferencesModule\Preference\Command
*/
class GetPreference implements SelfHandling
{

/**
* The preference key.
*
* @var string
*/
protected $key;

/**
* Create a new GetPreference instance.
*
* @param $key
* @param null $default
*/
public function __construct($key)
{
$this->key = $key;
}

/**
* Handle the command.
*
* @param PreferenceRepositoryInterface $preferences
* @return mixed
*/
public function handle(PreferenceRepositoryInterface $preferences)
{
return $preferences->get($this->key);
}
}
16 changes: 16 additions & 0 deletions src/PreferencesModulePlugin.php
@@ -1,7 +1,11 @@
<?php namespace Anomaly\PreferencesModule;

use Anomaly\PreferencesModule\Preference\Command\GetPreference;
use Anomaly\PreferencesModule\Preference\Command\GetPreferenceValue;
use Anomaly\PreferencesModule\Preference\Command\GetValueFieldType;
use Anomaly\PreferencesModule\Preference\Contract\PreferenceInterface;
use Anomaly\Streams\Platform\Addon\Plugin\Plugin;
use Anomaly\Streams\Platform\Support\Decorator;

/**
* Class PreferencesModulePlugin
Expand All @@ -27,6 +31,18 @@ public function getFunctions()
function ($key) {
return $this->dispatch(new GetPreferenceValue($key));
}
),
new \Twig_SimpleFunction(
'preference',
function ($key) {

/* @var PreferenceInterface $preference */
if (!$preference = $this->dispatch(new GetPreference($key))) {
return null;
}

return (new Decorator())->decorate($this->dispatch(new GetValueFieldType($preference)));
}
)
];
}
Expand Down

0 comments on commit 34418da

Please sign in to comment.