diff --git a/usermanual/UserManualPlugin.php b/usermanual/UserManualPlugin.php old mode 100755 new mode 100644 index fa1bfcc..c1e0c53 --- a/usermanual/UserManualPlugin.php +++ b/usermanual/UserManualPlugin.php @@ -1,77 +1,104 @@ getSettings()->pluginNameOverride; - function getName() - { - return Craft::t('User Manual'); - } + return ($pluginNameOverride) ? $pluginNameOverride : $pluginName; + } - function getVersion() - { - return '1.0.0'; - } + public function getVersion() + { + return '1.0.0'; + } - function getDeveloper() - { - return 'Hill Holliday'; - } + public function getDeveloper() + { + return 'Hill Holliday'; + } - function getDeveloperUrl() - { - return 'http://hhcc.com'; - } + public function getDeveloperUrl() + { + return 'http://hhcc.com'; + } - function hasCpSection() + public function hasCpSection() { return true; } - public function addTwigExtension() - { - Craft::import('plugins.usermanual.twigextensions.UserManualTwigExtension'); - return new UserManualTwigExtension(); - } + public function addTwigExtension() + { + Craft::import('plugins.usermanual.twigextensions.UserManualTwigExtension'); - public function registerCpRoutes() { - return array( - 'usermanual/(?P[a-zA-Z0-9\-\_\/]+)' => 'usermanual/index' - ); - } + return new UserManualTwigExtension(); + } + public function registerCpRoutes() + { + return [ + 'usermanual/(?P[a-zA-Z0-9\-\_\/]+)' => 'usermanual/index', + ]; + } protected function defineSettings() { - return array( - 'channels' => array(AttributeType::Mixed, 'default' => ""), - ); + return [ + 'pluginNameOverride' => AttributeType::String, + 'templateOverride' => AttributeType::Template, + 'section' => AttributeType::Number, + ]; } - public function getSettingsHtml(){ - - $options= [[ - 'label' => 'Please select', - 'value' => '' - ]]; - - foreach(craft()->sections->getAllSections() as $section){ - $options[] = [ - 'label' => $section['name'], - 'value' => $section['handle'] - ]; - } - - return craft()->templates->render('UserManual/settings',array( - 'settings' => $this->getSettings(), - 'options' => $options - )); - } + public function getSettingsHtml() + { + $options = [[ + 'label' => '', + 'value' => '', + ]]; + + foreach (craft()->sections->getAllSections() as $section) { + if (!$section->hasUrls) { + continue; + } + $options[] = [ + 'label' => $section['name'], + 'value' => $section['id'], + ]; + } + + return craft()->templates->render('usermanual/settings', [ + 'settings' => $this->getSettings(), + 'options' => $options, + 'siteTemplatesPath' => craft()->path->getSiteTemplatesPath(), + ]); + } public function onAfterInstall() { craft()->request->redirect(UrlHelper::getCpUrl('settings/plugins/usermanual/')); } + public function getSettings() + { + $settings = parent::getSettings(); + foreach ($settings as $name => $value) { + $configValue = craft()->config->get($name, 'usermanual'); + $settings->$name = is_null($configValue) ? $value : $configValue; + } + + // Allow handles from config + if (!is_numeric($settings->section)) { + $section = craft()->sections->getSectionByHandle('homepage'); + if ($section) { + $settings->section = $section->id; + } + } + return $settings; + } } diff --git a/usermanual/config.php b/usermanual/config.php new file mode 100644 index 0000000..b48b76f --- /dev/null +++ b/usermanual/config.php @@ -0,0 +1,6 @@ + null, + 'templateOverride' => null, + 'section' => null, +]; diff --git a/usermanual/services/UserManual_SettingsService.php b/usermanual/services/UserManual_SettingsService.php deleted file mode 100755 index 4fbd7a5..0000000 --- a/usermanual/services/UserManual_SettingsService.php +++ /dev/null @@ -1,15 +0,0 @@ -plugins->getPlugin('UserManual'); - $settings = $plugin->settings; - - return $settings->channels; - } - - public function getCp(){ - return craft()->config->get('cpTrigger'); - } -} \ No newline at end of file diff --git a/usermanual/templates/_body.html b/usermanual/templates/_body.html new file mode 100644 index 0000000..3d1db9d --- /dev/null +++ b/usermanual/templates/_body.html @@ -0,0 +1,12 @@ +{# Using bracket notation for an accurate test, due to + a Twig bug: http://craftcms.stackexchange.com/questions/2116/twig-is-defined-always-returning-true/2117#2117 #} + +{% if entry['body'] is defined %} + {{ entry.body }} +{% else %} +

+ Create a field with the handle of body + or + use the Template Override option to define your own fields. +

+{% endif %} diff --git a/usermanual/templates/index.html b/usermanual/templates/index.html old mode 100755 new mode 100644 index b7d47db..a64f39c --- a/usermanual/templates/index.html +++ b/usermanual/templates/index.html @@ -1,20 +1,23 @@ {% extends "_layouts/cp" %} - -{% set channelSelected = (craft.userManual.getSettings() is defined) ? craft.userManual.getSettings() : "Homepage" %} -{% set title = "User Manual"|t %} +{% set sectionSelected = (craft.userManual.settings.section is defined) ? craft.userManual.settings.section : "Homepage" %} +{% set title = craft.userManual.name|t %} {% set sidebar %}