Skip to content

Commit

Permalink
RBoelter#10 Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasraoni committed Mar 27, 2024
1 parent 4254a53 commit 249d563
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 96 deletions.
144 changes: 72 additions & 72 deletions TwitterBlockPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,82 +11,82 @@

class TwitterBlockPlugin extends BlockPlugin
{
// Enables plugin site-wide or in specific context; this must return true only if the user is in the site-wide context
public function isSitePlugin()
{
return !Application::get()->getRequest()->getContext();
}
// Enables plugin site-wide or in specific context; this must return true only if the user is in the site-wide context
public function isSitePlugin()
{
return !Application::get()->getRequest()->getContext();
}

public function getDisplayName()
{
return __('plugins.blocks.twitter.title');
}
public function getDisplayName()
{
return __('plugins.blocks.twitter.title');
}


public function getDescription()
{
return __('plugins.blocks.twitter.desc');
}
public function getDescription()
{
return __('plugins.blocks.twitter.desc');
}

public function getContents($templateMgr, $request = null)
{
$context = Application::get()->getRequest()->getContext();
$contextId = ($context && $context->getId()) ? $context->getId() : Application::CONTEXT_SITE;
$templateMgr->assign('tweetTitle', $this->getSetting($contextId, 'tweetTitle'));
$templateMgr->assign('tweetUrl', $this->getSetting($contextId, 'tweetUrl'));
$templateMgr->assign('tweetColor', $this->getSetting($contextId, 'tweetColor'));
$templateMgr->assign('tweetHeight', $this->getSetting($contextId, 'tweetHeight'));
$templateMgr->assign('tweetOptions', $this->getSetting($contextId, 'tweetOptions'));
$templateMgr->assign('tweetDataLimit', $this->getSetting($contextId, 'tweetDataLimit'));
return parent::getContents($templateMgr, $request);
}
public function getContents($templateMgr, $request = null)
{
$context = Application::get()->getRequest()->getContext();
$contextId = ($context && $context->getId()) ? $context->getId() : Application::CONTEXT_SITE;
$templateMgr->assign('tweetTitle', $this->getSetting($contextId, 'tweetTitle'));
$templateMgr->assign('tweetUrl', $this->getSetting($contextId, 'tweetUrl'));
$templateMgr->assign('tweetColor', $this->getSetting($contextId, 'tweetColor'));
$templateMgr->assign('tweetHeight', $this->getSetting($contextId, 'tweetHeight'));
$templateMgr->assign('tweetOptions', $this->getSetting($contextId, 'tweetOptions'));
$templateMgr->assign('tweetDataLimit', $this->getSetting($contextId, 'tweetDataLimit'));
return parent::getContents($templateMgr, $request);
}

public function getActions($request, $actionArgs)
{
$actions = parent::getActions($request, $actionArgs);
if (!$this->getEnabled()) {
return $actions;
}
$router = $request->getRouter();
$linkAction = new LinkAction(
'settings',
new AjaxModal(
$router->url(
$request,
null,
null,
'manage',
null,
array(
'verb' => 'settings',
'plugin' => $this->getName(),
'category' => 'blocks'
)
),
$this->getDisplayName()
),
__('manager.plugins.settings'),
null
);
array_unshift($actions, $linkAction);
return $actions;
}
public function getActions($request, $actionArgs)
{
$actions = parent::getActions($request, $actionArgs);
if (!$this->getEnabled()) {
return $actions;
}
$router = $request->getRouter();
$linkAction = new LinkAction(
'settings',
new AjaxModal(
$router->url(
$request,
null,
null,
'manage',
null,
[
'verb' => 'settings',
'plugin' => $this->getName(),
'category' => 'blocks'
]
),
$this->getDisplayName()
),
__('manager.plugins.settings'),
null
);
array_unshift($actions, $linkAction);
return $actions;
}

public function manage($args, $request)
{
switch ($request->getUserVar('verb')) {
case 'settings':
$form = new SettingsForm($this);
if (!$request->getUserVar('save')) {
$form->initData();
return new JSONMessage(true, $form->fetch($request));
}
$form->readInputData();
if ($form->validate()) {
$form->execute();
return new JSONMessage(true);
}
}
return parent::manage($args, $request);
}
public function manage($args, $request)
{
switch ($request->getUserVar('verb')) {
case 'settings':
$form = new SettingsForm($this);
if (!$request->getUserVar('save')) {
$form->initData();
return new JSONMessage(true, $form->fetch($request));
}
$form->readInputData();
if ($form->validate()) {
$form->execute();
return new JSONMessage(true);
}
}
return parent::manage($args, $request);
}
}
47 changes: 23 additions & 24 deletions classes/SettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

class SettingsForm extends Form
{


public $plugin;

public function __construct($plugin)
Expand All @@ -32,9 +30,9 @@ public function __construct($plugin)
*/
public function initData()
{
$request = Application::get()->getRequest();
$context = $request->getContext();
$contextId = ($context && $context->getId()) ? $context->getId() : Application::CONTEXT_SITE;
$request = Application::get()->getRequest();
$context = $request->getContext();
$contextId = ($context && $context->getId()) ? $context->getId() : Application::CONTEXT_SITE;
$this->setData('tweetTitle', $this->plugin->getSetting($contextId, 'tweetTitle'));
$this->setData('tweetUrl', $this->plugin->getSetting($contextId, 'tweetUrl'));
$this->setData('tweetColor', $this->plugin->getSetting($contextId, 'tweetColor'));
Expand All @@ -53,34 +51,35 @@ public function readInputData()
parent::readInputData();
}

/**
* Fetch any additional data needed for your form.
*
* Data assigned to the form using $this->setData() during the
* initData() or readInputData() methods will be passed to the
* template.
* @param $request
* @param null $template
* @param bool $display
* @return string|null
*/
/**
* Fetch any additional data needed for your form.
*
* Data assigned to the form using $this->setData() during the
* initData() or readInputData() methods will be passed to the
* template.
*
* @param null $template
* @param bool $display
*
* @return string|null
*/
public function fetch($request, $template = null, $display = false)
{
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign('pluginName', $this->plugin->getName());
return parent::fetch($request, $template, $display);
}

/**
* Save the settings
* @param mixed ...$functionArgs
* @return mixed|null
*/
/**
* Save the settings
*
* @return mixed|null
*/
public function execute(...$functionArgs)
{
$request = Application::get()->getRequest();
$context = $request->getContext();
$contextId = ($context && $context->getId()) ? $context->getId() : Application::CONTEXT_SITE;
$request = Application::get()->getRequest();
$context = $request->getContext();
$contextId = ($context && $context->getId()) ? $context->getId() : Application::CONTEXT_SITE;
$this->plugin->updateSetting($contextId, 'tweetTitle', $this->getData('tweetTitle'));
$this->plugin->updateSetting($contextId, 'tweetUrl', $this->getData('tweetUrl'));
$this->plugin->updateSetting($contextId, 'tweetColor', $this->getData('tweetColor'));
Expand Down

0 comments on commit 249d563

Please sign in to comment.