Skip to content

Commit

Permalink
changed: moved start.php to Bootstrap and elgg-plugin.php
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Jan 29, 2020
1 parent 7f2e4bb commit 9ce1ab1
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 35 deletions.
15 changes: 15 additions & 0 deletions classes/ColdTrick/TargetBlank/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace ColdTrick\TargetBlank;

use Elgg\DefaultPluginBootstrap;

class Bootstrap extends DefaultPluginBootstrap {

/**
* {@inheritDoc}
*/
public function init() {
elgg_require_js('target_blank/target_blank');
}
}
21 changes: 21 additions & 0 deletions classes/ColdTrick/TargetBlank/Javascript.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace ColdTrick\TargetBlank;

class Javascript {

/**
* Add the link suffix to the global JS data
*
* @param \Elgg\Hook $hook 'elgg.data', 'page'
*
* @return array
*/
public function setLinkSuffix(\Elgg\Hook $hook) {
$result = $hook->getValue();

$result['target_blank']['link_suffix'] = elgg_get_plugin_setting('link_suffix', 'target_blank');

return $result;
}
}
28 changes: 28 additions & 0 deletions classes/ColdTrick/TargetBlank/PluginSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace ColdTrick\TargetBlank;

class PluginSettings {

/**
* Save the unfilterd input of the link suffix input
*
* @param \Elgg\Hook $hook 'setting', 'plugin'
*
* @return void|string
*/
public static function saveLinkSuffix(\Elgg\Hook $hook) {
if ($hook->getParam('plugin_id') !== 'target_blank') {
return;
}

if ($hook->getParam('name') !== 'link_suffix') {
return;
}

// get unfiltered input
$params = (array) get_input('params', [], false);

return elgg_extract('link_suffix', $params);
}
}
15 changes: 15 additions & 0 deletions elgg-plugin.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
<?php

use ColdTrick\TargetBlank\Bootstrap;

return [
'bootstrap' => Bootstrap::class,
'hooks' => [
'elgg.data' => [
'page' => [
'\ColdTrick\TargetBlank\Javascript::setLinkSuffix' => [],
],
],
'setting' => [
'plugin' => [
'\ColdTrick\TargetBlank\PluginSettings::saveLinkSuffix' => [],
],
],
],
'routes' => [
'target_blank:test' => [
'path' => '/target_blank/test',
Expand Down
35 changes: 0 additions & 35 deletions start.php

This file was deleted.

0 comments on commit 9ce1ab1

Please sign in to comment.