Skip to content

Commit

Permalink
Apply Winter Coding Standards
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeTowers committed Jan 4, 2025
1 parent 46a1eb9 commit 332b0e4
Show file tree
Hide file tree
Showing 48 changed files with 426 additions and 390 deletions.
51 changes: 26 additions & 25 deletions Plugin.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php namespace Winter\Pages;
<?php

use Backend;
namespace Winter\Pages;

use Backend\Facades\Backend;
use Backend\Models\UserRole;
use Cms\Classes\Controller as CmsController;
use Cms\Classes\Theme;
use Config;
use Event;
use System\Classes\PluginBase;
use Winter\Pages\Classes\Controller;
use Winter\Pages\Classes\Page as StaticPage;
use Winter\Pages\Classes\Router;
use Winter\Pages\Classes\Snippet;
use Winter\Pages\Classes\SnippetManager;
use Winter\Pages\Controllers\Index;
use Winter\Storm\Support\Facades\Event;

class Plugin extends PluginBase
{
Expand All @@ -37,7 +38,7 @@ public function registerComponents(): array
\Winter\Pages\Components\ChildPages::class => 'childPages',
\Winter\Pages\Components\StaticPage::class => 'staticPage',
\Winter\Pages\Components\StaticMenu::class => 'staticMenu',
\Winter\Pages\Components\StaticBreadcrumbs::class => 'staticBreadcrumbs'
\Winter\Pages\Components\StaticBreadcrumbs::class => 'staticBreadcrumbs',
];
}

Expand All @@ -58,7 +59,7 @@ public function registerPermissions(): array
'order' => 200,
'roles' => [UserRole::CODE_DEVELOPER, UserRole::CODE_PUBLISHER],
'label' => 'winter.pages::lang.page.manage_menus',
],
],
'winter.pages.manage_content' => [
'tab' => 'winter.pages::lang.page.tab',
'order' => 200,
Expand Down Expand Up @@ -99,28 +100,28 @@ public function registerNavigation(): array
'label' => 'winter.pages::lang.page.menu_label',
'icon' => 'icon-files-o',
'url' => 'javascript:;',
'attributes' => ['data-menu-item'=>'pages'],
'attributes' => ['data-menu-item' => 'pages'],
'permissions' => ['winter.pages.manage_pages'],
],
'menus' => [
'label' => 'winter.pages::lang.menu.menu_label',
'icon' => 'icon-sitemap',
'url' => 'javascript:;',
'attributes' => ['data-menu-item'=>'menus'],
'attributes' => ['data-menu-item' => 'menus'],
'permissions' => ['winter.pages.manage_menus'],
],
'content' => [
'label' => 'winter.pages::lang.content.menu_label',
'icon' => 'icon-file-text-o',
'url' => 'javascript:;',
'attributes' => ['data-menu-item'=>'content'],
'attributes' => ['data-menu-item' => 'content'],
'permissions' => ['winter.pages.manage_content'],
],
'snippets' => [
'label' => 'winter.pages::lang.snippet.menu_label',
'icon' => 'icon-newspaper-o',
'url' => 'javascript:;',
'attributes' => ['data-menu-item'=>'snippets'],
'attributes' => ['data-menu-item' => 'snippets'],
'permissions' => ['winter.pages.access_snippets'],
],
],
Expand All @@ -146,8 +147,8 @@ public function registerMarkupTags(): array
{
return [
'filters' => [
'staticPage' => ['Winter\Pages\Classes\Page', 'url']
]
'staticPage' => ['Winter\Pages\Classes\Page', 'url'],
],
];
}

Expand Down Expand Up @@ -239,19 +240,19 @@ protected function extendBackendForms(): void
*/
protected function extendCmsTemplates(): void
{
Event::listen('cms.template.save', function($controller, $template, $type) {
Event::listen('cms.template.save', function ($controller, $template, $type) {
Plugin::clearCache();
});

Event::listen('cms.template.processSettingsBeforeSave', function($controller, $dataHolder) {
Event::listen('cms.template.processSettingsBeforeSave', function ($controller, $dataHolder) {
$dataHolder->settings = Snippet::processTemplateSettingsArray($dataHolder->settings);
});

Event::listen('cms.template.processSettingsAfterLoad', function($controller, $template) {
Event::listen('cms.template.processSettingsAfterLoad', function ($controller, $template) {
Snippet::processTemplateSettings($template);
});

Event::listen('cms.template.processTwigContent', function($template, $dataHolder) {
Event::listen('cms.template.processTwigContent', function ($template, $dataHolder) {
if ($template instanceof \Cms\Classes\Layout) {
$dataHolder->content = Controller::instance()->parseSyntaxFields($dataHolder->content);
}
Expand All @@ -263,7 +264,7 @@ protected function extendCmsTemplates(): void
*/
protected function extendCmsRouter(): void
{
Event::listen('cms.router.beforeRoute', function($url) {
Event::listen('cms.router.beforeRoute', function ($url) {
return Controller::instance()->initCmsPage($url);
});
}
Expand All @@ -273,7 +274,7 @@ protected function extendCmsRouter(): void
*/
protected function extendCmsRenderer(): void
{
Event::listen('cms.page.beforeRenderPage', function($controller, $page) {
Event::listen('cms.page.beforeRenderPage', function ($controller, $page) {
/*
* Before twig renders
*/
Expand All @@ -290,11 +291,11 @@ protected function extendCmsRenderer(): void
}
});

Event::listen('cms.page.initComponents', function($controller, $page) {
Event::listen('cms.page.initComponents', function ($controller, $page) {
Controller::instance()->initPageComponents($controller, $page);
});

Event::listen('cms.block.render', function($blockName, $blockContents) {
Event::listen('cms.block.render', function ($blockName, $blockContents) {
$page = CmsController::getController()->getPage();

if (!isset($page->apiBag['staticPage'])) {
Expand All @@ -313,24 +314,24 @@ protected function extendCmsRenderer(): void
*/
protected function registerMenuItemTypes(): void
{
Event::listen('pages.menuitem.listTypes', function() {
Event::listen('pages.menuitem.listTypes', function () {
return [
'static-page' => 'winter.pages::lang.menuitem.static_page',
'all-static-pages' => 'winter.pages::lang.menuitem.all_static_pages'
'all-static-pages' => 'winter.pages::lang.menuitem.all_static_pages',
];
});

Event::listen('pages.menuitem.getTypeInfo', function($type) {
Event::listen('pages.menuitem.getTypeInfo', function ($type) {
if ($type == 'url') {
return [];
}

if ($type == 'static-page'|| $type == 'all-static-pages') {
if ($type == 'static-page' || $type == 'all-static-pages') {
return StaticPage::getMenuTypeInfo($type);
}
});

Event::listen('pages.menuitem.resolveItem', function($type, $item, $url, $theme) {
Event::listen('pages.menuitem.resolveItem', function ($type, $item, $url, $theme) {
if ($type == 'static-page' || $type == 'all-static-pages') {
return StaticPage::resolveMenuItem($item, $url, $theme);
}
Expand Down
2 changes: 1 addition & 1 deletion assets/js/page-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
* @param {Event} event
*/
PagePreview.prototype.onDeviceClick = function (event) {
const $clicked = $(event.currentTarget)
public const $clicked = $(event.currentTarget)

// Remove active class from other options
this.$deviceSelector.find('a').removeClass('active')
Expand Down
6 changes: 4 additions & 2 deletions classes/Content.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Winter\Pages\Classes;
<?php

namespace Winter\Pages\Classes;

use Cms\Classes\Content as ContentBase;

Expand All @@ -16,7 +18,7 @@ class Content extends ContentBase
* @var array Attributes that support translation, if available.
*/
public $translatable = [
'markup'
'markup',
];

public $translatableModel = 'Winter\Translate\Classes\MLContent';
Expand Down
15 changes: 8 additions & 7 deletions classes/Controller.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php namespace Winter\Pages\Classes;
<?php

namespace Winter\Pages\Classes;

use Cache;
use Cms\Classes\CmsException;
use Cms\Classes\Page as CmsPage;
use Cms\Classes\Theme;
use Exception;
use Lang;
use Log;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Log;
use Winter\Storm\Parse\Syntax\Parser as SyntaxParser;
use Winter\Storm\Support\Str;

Expand Down Expand Up @@ -139,10 +141,9 @@ public function parseSyntaxFields($content)
try {
return SyntaxParser::parse($content, [
'varPrefix' => 'extraData.',
'tagPrefix' => 'page:'
'tagPrefix' => 'page:',
])->toTwig();
}
catch (Exception $ex) {
} catch (Exception $ex) {
return $content;
}
}
Expand Down
32 changes: 16 additions & 16 deletions classes/Menu.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php namespace Winter\Pages\Classes;
<?php

namespace Winter\Pages\Classes;

use Cms\Classes\Meta;
use Event;
use Request;
use SystemException;
use Url;
use Illuminate\Support\Facades\Request;
use Winter\Storm\Exception\SystemException;
use Winter\Storm\Support\Facades\Event;
use Winter\Storm\Support\Facades\URL;
use Winter\Storm\Support\Str;

/**
Expand Down Expand Up @@ -71,7 +73,7 @@ public function setCodeAttribute($code)
$code = trim($code);

if (strlen($code)) {
$this->fileName = $code.'.yaml';
$this->fileName = $code . '.yaml';
$this->attributes = array_merge($this->attributes, ['code' => $code]);
}

Expand Down Expand Up @@ -148,11 +150,11 @@ public function generateReferences($page)
$currentUrl = Str::lower(Url::to($currentUrl));

$activeMenuItem = $page->activeMenuItem ?: false;
$iterator = function($items) use ($currentUrl, &$iterator, $activeMenuItem) {
$iterator = function ($items) use ($currentUrl, &$iterator, $activeMenuItem) {
$result = [];

foreach ($items as $item) {
$parentReference = new MenuItemReference;
$parentReference = new MenuItemReference();
$parentReference->type = $item->type;
$parentReference->title = $item->title;
$parentReference->code = $item->code;
Expand All @@ -165,8 +167,7 @@ public function generateReferences($page)
if ($item->type == 'url') {
$parentReference->url = $item->url;
$parentReference->isActive = $currentUrl == Str::lower(Url::to($item->url)) || $activeMenuItem === $item->code;
}
else {
} else {
/*
* If the item type is not URL, use the API to request the item type's provider to
* return the item URL, subitems and determine whether the item is active.
Expand All @@ -179,11 +180,11 @@ public function generateReferences($page)
}

if (isset($itemInfo['items'])) {
$itemIterator = function($items) use (&$itemIterator, $parentReference) {
$itemIterator = function ($items) use (&$itemIterator, $parentReference) {
$result = [];

foreach ($items as $item) {
$reference = new MenuItemReference;
$reference = new MenuItemReference();
$reference->type = isset($item['type']) ? $item['type'] : null;
$reference->title = isset($item['title']) ? $item['title'] : '--no title--';
$reference->url = isset($item['url']) ? $item['url'] : '#';
Expand Down Expand Up @@ -216,8 +217,7 @@ public function generateReferences($page)

if (!$item->replace) {
$result[] = $parentReference;
}
else {
} else {
foreach ($parentReference->items as $subItem) {
$result[] = $subItem;
}
Expand All @@ -232,7 +232,7 @@ public function generateReferences($page)
/*
* Populate the isChildActive property
*/
$hasActiveChild = function($items) use (&$hasActiveChild) {
$hasActiveChild = function ($items) use (&$hasActiveChild) {
foreach ($items as $item) {
if ($item->isActive) {
return true;
Expand All @@ -245,7 +245,7 @@ public function generateReferences($page)
}
};

$iterator = function($items) use (&$iterator, &$hasActiveChild) {
$iterator = function ($items) use (&$iterator, &$hasActiveChild) {
foreach ($items as $item) {
$item->isChildActive = $hasActiveChild($item->items);

Expand Down
17 changes: 9 additions & 8 deletions classes/MenuItem.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php namespace Winter\Pages\Classes;
<?php

use Event;
namespace Winter\Pages\Classes;

use Winter\Storm\Support\Facades\Event;

/**
* Represents a menu item.
Expand Down Expand Up @@ -78,7 +80,7 @@ class MenuItem
'reference',
'cmsPage',
'replace',
'viewBag'
'viewBag',
];

/**
Expand All @@ -96,15 +98,14 @@ public static function initFromArray(array $items): array
$result = [];

foreach ($items as $itemData) {
$obj = new self;
$obj = new self();

foreach ($itemData as $name => $value) {
if ($name != 'items') {
if (property_exists($obj, $name)) {
$obj->$name = $value;
}
}
else {
} else {
$obj->items = self::initFromArray($value);
}
}
Expand Down Expand Up @@ -174,9 +175,9 @@ public static function getTypeInfo($type): array
$baseName = $page->getBaseFileName();
$pos = strrpos($baseName, '/');

$dir = $pos !== false ? substr($baseName, 0, $pos).' / ' : null;
$dir = $pos !== false ? substr($baseName, 0, $pos) . ' / ' : null;
$cmsPages[$baseName] = strlen($page->title)
? $dir.$page->title
? $dir . $page->title
: $baseName;
}

Expand Down
4 changes: 3 additions & 1 deletion classes/MenuItemReference.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Winter\Pages\Classes;
<?php

namespace Winter\Pages\Classes;

/**
* Represents a front-end menu item.
Expand Down
Loading

0 comments on commit 332b0e4

Please sign in to comment.