Skip to content

Commit

Permalink
Merge pull request #520 from rainlab/next
Browse files Browse the repository at this point in the history
[2.x] Major Upgrade for Compatibility with Snippets
  • Loading branch information
daftspunk authored Jul 7, 2023
2 parents 2163711 + 2bcf2f7 commit 06f29ae
Show file tree
Hide file tree
Showing 58 changed files with 2,877 additions and 5,024 deletions.
652 changes: 405 additions & 247 deletions docs/documentation.md → DOCS.md

Large diffs are not rendered by default.

65 changes: 5 additions & 60 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
use RainLab\Pages\Classes\Controller;
use RainLab\Pages\Classes\Page as StaticPage;
use RainLab\Pages\Classes\Router;
use RainLab\Pages\Classes\Snippet;
use RainLab\Pages\Classes\SnippetManager;
use Cms\Classes\Theme;
use Cms\Classes\Snippet;
use Cms\Classes\Controller as CmsController;
use Cms\Classes\SnippetManager;
use System\Classes\PluginBase;

class Plugin extends PluginBase
Expand Down Expand Up @@ -51,11 +51,6 @@ public function registerPermissions()
'tab' => 'rainlab.pages::lang.page.tab',
'order' => 200,
'label' => 'rainlab.pages::lang.page.manage_content'
],
'rainlab.pages.access_snippets' => [
'tab' => 'rainlab.pages::lang.page.tab',
'order' => 200,
'label' => 'rainlab.pages::lang.page.access_snippets'
]
];
}
Expand Down Expand Up @@ -93,13 +88,6 @@ public function registerNavigation()
'url' => 'javascript:;',
'attributes' => ['data-menu-item'=>'content'],
'permissions' => ['rainlab.pages.manage_content']
],
'snippets' => [
'label' => 'rainlab.pages::lang.snippet.menu_label',
'icon' => 'icon-newspaper-o',
'url' => 'javascript:;',
'attributes' => ['data-menu-item'=>'snippet'],
'permissions' => ['rainlab.pages.access_snippets']
]
]
]
Expand All @@ -121,26 +109,18 @@ public function boot()
});

Event::listen('cms.page.beforeRenderPage', function($controller, $page) {
/*
* Before twig renders
*/
// Before twig renders
$twig = $controller->getTwig();
$loader = $controller->getLoader();
Controller::instance()->injectPageTwig($page, $loader, $twig);

/*
* Get rendered content
*/
// Get rendered content
$contents = Controller::instance()->getPageContents($page);
if (strlen($contents)) {
return $contents;
}
});

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

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

Expand Down Expand Up @@ -184,45 +164,10 @@ public function boot()
}
});

Event::listen('backend.form.extendFieldsBefore', function($formWidget) {
if ($formWidget->model instanceof \Cms\Classes\Partial) {
Snippet::extendPartialForm($formWidget);
}
});

Event::listen('cms.template.getTemplateToolbarSettingsButtons', function($extension, $dataHolder) {
// Running v3.4 with native snippets
if (class_exists('System') && version_compare(\System::VERSION, '3.4', '>=')) {
return;
}

if ($dataHolder->templateType === 'partial') {
Snippet::extendEditorPartialToolbar($dataHolder);
}
});

Event::listen('cms.template.save', function($controller, $template, $type) {
Plugin::clearCache();
});

Event::listen('cms.template.processSettingsBeforeSave', function($controller, $dataHolder) {
// Running v3.4 with native snippets
if (class_exists('System') && version_compare(\System::VERSION, '3.4', '>=')) {
return;
}

$dataHolder->settings = Snippet::processTemplateSettingsArray($dataHolder->settings);
});

Event::listen('cms.template.processSettingsAfterLoad', function($controller, $template, $context = null) {
// Running v3.4 with native snippets
if (class_exists('System') && version_compare(\System::VERSION, '3.4', '>=')) {
return;
}

Snippet::processTemplateSettings($template, $context);
});

Event::listen('cms.template.processTwigContent', function($template, $dataHolder) {
if ($template instanceof \Cms\Classes\Layout) {
$dataHolder->content = Controller::instance()->parseSyntaxFields($dataHolder->content);
Expand Down Expand Up @@ -270,6 +215,6 @@ public static function clearCache()
$router->clearCache();

StaticPage::clearMenuCache($theme);
SnippetManager::clearCache($theme);
// SnippetManager::clearCache($theme);
}
}
44 changes: 27 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Pages plugin
# Pages Plugin

This plugin allows end users to create and edit static pages and menus with a simple WYSIWYG user interface.

## Managing static pages
## Managing Static Pages

Static pages are managed on the Pages tab of the Static Pages plugin. Static pages have three required parameters - **Title**, **URL** and **Layout**. The URL is generated automatically when the Title is entered, but it could be changed manually. URLs must start with the forward slash character. The Layout drop-down allows to select a layout created with the CMS. Only layouts that include the `staticPage` component are displayed in the drop-down.

Expand All @@ -18,19 +18,13 @@ If a static layout contains [placeholders](https://octobercms.com/docs/cms/layou

## Snippets

Snippets are elements that can be added by a Static Page, in the rich text editor. They allow to inject complex (and interactive) areas to pages. There are many possible applications and examples of using Snippets:

* Google Maps snippet - outputs a map centered on specific coordinates with predefined zoom factor. That snippet would be great for static pages that explain directions.
* Universal commenting system - allows visitors to post comments to any static page.
* Third-party integrations - for example with Yelp or TripAdvisor for displaying extra information on a static page.

Snippets are displayed in the sidebar list on the Static Pages and can be added into a rich editor with a mouse click. Snippets are configurable and have properties that users can manage with the Inspector.
Snippets is a [featured included with October CMS](https://docs.octobercms.com/3.x/cms/themes/snippets.html), with elements that can be added by a Static Page, in the rich text editor. They allow you to inject complex (and interactive) areas to pages. Snippets are configurable and have properties that users can manage with the Inspector.

![image](https://raw.githubusercontent.com/rainlab/pages-plugin/master/docs/images/snippets-backend.png)

![image](https://raw.githubusercontent.com/rainlab/pages-plugin/master/docs/images/snippets-frontend.png)

## Managing menus
## Managing Menus

You can manage menus on the Menus tab of the Static Pages plugin. A website can contain multiple menus, for example the main menu, footer menu, sidebar menu, etc. A theme developer can include menus on a page layout with the `staticMenu` component.

Expand All @@ -42,50 +36,66 @@ Menus can contain multiple **menu items**, and menu items can be nested. Each me

![image](https://raw.githubusercontent.com/rainlab/pages-plugin/master/docs/images/menu-item.png) {.img-responsive .frame}

#### Standard menu item types
#### Standard Menu Item Types

The available menu item types depend on the installed plugins, but there are three basic item types that are supported out of the box.

###### Header {.subheader}

Items of this type are used for displaying text and don't link to anything. The text could be used as a category heading for other menu items. This type will only show a title property.

###### URL {.subheader}

Items of this type are links to a specific fixed URL. That could be an URL of an or internal page. Items of this type don't have any other properties - just the title and URL.

###### Static Page {.subheader}

Items of this type refer to static pages. The static page should be selected in the **Reference** drop-down list described below.

###### All Static Pages {.subheader}

Items of this type expand to create links to all static pages defined in the theme. Nested pages are represented with nested menu items.

#### Custom menu item types
#### Custom Menu Item Types

Other plugins can supply new menu item types. For example, the [Blog plugin](https://octobercms.com/plugin/rainlab-blog) by [RainLab](https://octobercms.com/author/RainLab) supplies two more types:

###### Blog Category {.subheader}

An item of this type represents a link to a specific blog category. The category should be selected in the **Reference** drop-down. This menu type also requires selecting a **CMS page** that outputs a blog category.

###### All Blog Categories {.subheader}

An item of this time expands into multiple items representing all blog existing categories. This menu type also requires selecting a **CMS page**.

#### Menu item properties
#### Menu Item Properties

Depending on the selected menu item time you might need to provide other properties of the menu item. The available properties are described below.

###### Reference {.subheader}

A drop-down list of objects the menu item should refer to. The list content depends on the menu item type. For the **Static page** item type the list displays all static pages defined in the system. For the **Blog category** item type the list displays a list of blog categories.

###### Allow nested items {.subheader}
###### Allow Nested Items {.subheader}

This checkbox is available only for menu item types that suppose nested objects. For example, static pages are hierarchical, and this property is available for the **Static page** item type. On the other hand, blog categories are not hierarchical, and the checkbox is hidden.

###### Replace this item with its generated children {.subheader}
###### Replace This Item With Its Generated Children {.subheader}

A checkbox determining whether the menu item should be replaced with generated menu items. This property is available only for menu item types that suppose automatic item generating, for example for the **Static page** menu item type. The **Blog category** menu item type doesn't have this property because blog categories cannot be nested and menu items of this type always point to a specific blog category. This property is very handy when you want to include generated menu items to the root of the menu. For example, you can create the **All blog categories** menu item and enable the replacing. As a result you will get a menu that lists all blog categories on the first level of the menu. If you didn't enable the replacing, there would be a root menu item, with blog categories listed under it.

###### CMS Page {.subheader}

This drop-down is available for menu item types that require a special CMS page to refer to. For example, the **Blog category** menu item type requires a CMS page that hosts the `blogPosts` component. The CMS Page drop-down for this item type will only display pages that include this component.

###### Code {.subheader}

The Code field allows to assign the API code that you can use to set the active menu item explicitly in the page's `onInit()` handler described in the documentation.

## Documentation

Read the [documentation](./DOCS.md) to learn more about this plugin.

## See also

Read the [Getting started with Static Pages](https://octobercms.com/blog/post/getting-started-static-pages) tutorial in the Blog.

Read the [documentation](/docs/documentation.md).
6 changes: 0 additions & 6 deletions assets/js/pages-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
this.$sidePanel = $('#pages-side-panel')
this.$pageTree = $('[data-control=treeview]', this.$sidePanel)
this.masterTabsObj = this.$masterTabs.data('oc.tab')
this.snippetManager = new $.oc.pages.snippetManager(this.$masterTabs)

this.registerHandlers()
}
Expand Down Expand Up @@ -321,11 +320,6 @@
},
tabId = data.type + '-' + data.theme + '-' + data.path

if ($item.data('type') == 'snippet') {
this.snippetManager.onSidebarSnippetClick($item);
return;
}

/*
* Find if the tab is already opened
*/
Expand Down
Loading

0 comments on commit 06f29ae

Please sign in to comment.