dmstr / yii2-pages-module
Application sitemap and navigation manager module for Yii 2.0 Framework
Installs: 66 491
Dependents: 3
Suggesters: 1
Security: 0
Stars: 31
Watchers: 11
Forks: 12
Open Issues: 4
Type:yii2-extension
Requires
- 2amigos/yii2-translateable-behavior: ^1.1.0
- bedezign/yii2-audit: ^1.1
- dmstr/yii2-active-record-permissions: ^1.1.0
- dmstr/yii2-backend-module: ^2.0.0
- dmstr/yii2-json-editor: ^1.0.0
- dmstr/yii2-web: ^1.0.0
- insolita/yii2-adminlte-widgets: ^1.1.4
- justinrainbow/json-schema: ^5.2.0
- kartik-v/yii2-tree-manager: >=1.0.3 <=1.0.5
- kartik-v/yii2-widget-select2: ^2.0.1
- mikehaertl/php-shellcommand: ^1.2.4
- pheme/yii2-settings: ^0.5.0 || ^0.7.0
- rmrevin/yii2-fontawesome: ~2.9
- yiisoft/yii2: *
Requires (Dev)
- codeception/codeception: ^2.2
- dev-master
- 2.5.8
- 2.5.7
- 2.5.6
- 2.5.5
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.0
- 2.1.0
- 2.1.0-rc2
- 2.1.0-rc1
- 2.0.0
- 2.0.0-rc7
- 2.0.0-rc6
- 2.0.0-rc5
- 2.0.0-rc4
- 2.0.0-rc3
- 2.0.0-rc2
- 2.0.0-rc1
- 2.0.0-beta2
- 2.0.0-beta1
- 2.0.0-alpha7
- 2.0.0-alpha6
- 2.0.0-alpha5
- 2.0.0-alpha4
- 2.0.0-alpha3
- 2.0.0-alpha2
- 2.0.0-alpha1
- 0.23.1
- 0.23.0
- 0.22.3
- 0.22.2
- 0.22.1
- 0.22.0
- 0.21.10
- 0.21.10-rc1
- 0.21.9
- 0.21.8
- 0.21.7
- 0.21.6
- 0.21.5
- 0.21.4
- 0.21.3
- 0.21.2
- 0.21.1
- 0.21.0
- 0.20.14
- 0.20.13
- 0.20.12
- 0.20.11
- 0.20.10
- 0.20.9.3
- 0.20.9.2
- 0.20.9.1
- 0.20.9
- 0.20.8
- 0.20.7
- 0.20.6
- 0.20.5
- 0.20.4
- 0.20.3
- 0.20.2
- 0.20.1
- 0.20.0
- 0.20.0-rc2
- 0.20.0-rc1
- 0.20.0-beta6
- 0.20.0-beta5
- 0.20.0-beta4
- 0.20.0-beta3
- 0.20.0-beta2
- 0.20.0-beta1
- 0.19.1
- 0.19.1-rc1
- 0.19.0
- 0.19.0-beta1
- 0.19.0-alpha2
- 0.19.0-alpha1
- 0.18.0
- 0.18.0-beta4
- 0.18.0-beta3
- 0.18.0-beta2
- 0.17.0
- 0.17.0-beta1
- 0.16.0
- 0.16.0-beta1
- 0.15.2
- 0.15.1
- 0.15.0
- 0.15.0-rc1
- 0.15.0-beta3
- 0.15.0-beta2
- 0.15.0-beta1
- 0.14.5
- 0.14.4
- 0.14.3
- 0.14.2
- 0.14.1
- 0.14.0
- 0.13.0
- 0.12.0-beta2
- 0.12.0-beta1
- 0.11.3
- 0.11.2
- 0.11.1
- 0.11.0
- 0.10.0
- 0.9.4
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
- 0.9.0-beta1
- 0.8.1
- 0.8.0
- 0.7.0
- 0.6.3
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.0
- 0.4.0
- 0.3.1
- 0.3.0
- 0.2.0
- 0.1.9
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- 0.0.9
- 0.0.8
- 0.0.7
- 0.0.6
- 0.0.5
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
- dev-feature/fix-ref-page-return
- dev-dev/default-page-checks
- dev-feature/fix-migration
- dev-feature/fix-composer-output
- dev-feature/access_owner_uuid
- dev-release/2.x
- dev-feature/remove-deprecated-code
- dev-dev/fix-request-param-action-trait
- dev-feature/actionRefPage
- dev-feature/split-fat-methods
- dev-feature/postgres-support
- dev-feature/menu-remove-hidden-childs
- dev-dev/upgrade
- dev-feature/remove-page-related-stuff
- dev-develop
- dev-feature/updated-styles
- dev-feature/copy-page-plus-widget
- dev-feature/2.x-testing
This package is auto-updated.
Last update: 2024-10-26 11:55:15 UTC
README
Application sitemap and navigation manager module for Yii 2.0 Framework
- ⚠️ Breaking changes in 0.14.0 and 0.18.0
- ⚠️ copy pages is removed in versions > 2.5.0
data structure
and public properties
are updated and query menu items from now on via domain_id
Requirements
- URL manager from codemix/yii2-localeurls configured in application
- role based access control;
auth_items
for everymodule_controller_action
Installation
The preferred way to install this extension is through composer.
Either run
composer require dmstr/yii2-pages-module "*"
or add
"dmstr/yii2-pages-module": "*"
to the require section of your composer.json
file.
Setup
Run migrations
./yii migrate \
--disableLookup=1 \
--migrationPath=@vendor/dmstr/yii2-pages-module/migrations
Configuration
Enable module in application configuration
// module configuration
'pages' => [
'class' => 'dmstr\modules\pages\Module',
'layout' => '@admin-views/layouts/main',
'roles' => ['Admin', 'Editor'],
'defaultPageLayout' => '@app/modules/frontend/layouts/main',
'availableRoutes' => [
'site/index' => 'Index Route',
],
'availableViews' => [
'@app/views/site/index.php' => 'Index View',
],
],
// if used want a url suffix, e.g. '.html', add Url rules for that
'urlManager' => [
...
'rules' => [
'<pagePath:[a-zA-Z0-9_\-\./\+]*>/<pageSlug:[a-zA-Z0-9_\-\.]*>-<pageId:[0-9]*>.html' => 'pages/default/page',
'<pageSlug:[a-zA-Z0-9_\-\.]*>-<pageId:[0-9]*>.html' => 'pages/default/page',
],
...
],
// register frontend asset for hiding pages via CookieButton
'on '. \yii\web\Application::EVENT_BEFORE_ACTION => function () {
\dmstr\modules\pages\assets\PagesFrontendAsset::register(Yii::$app->controller->view);
},
Use settings module to configure additional controllers
- Add one controller route per line to section
pages
, keyavailableRoutes
Settings
pages.availableRoutes
- routes per access_domain (for non-admin users)pages.availableViews
- views per access_domain (for non-admin users)pages.availableGlobalRoutes
- global routes (for admin users)pages.availableGlobalViews
- global views(for admin users)
Usage
Navbar (eg. layouts/main
)
find a root node / leave node
by domain_id
i.e. root
$menuItems = \dmstr\modules\pages\models\Tree::getMenuItems('root');
use for example with bootstrap Navbar
echo yii\bootstrap\Nav::widget(
[
'options' => ['class' => 'navbar-nav navbar-right'],
'activateItems' => false,
'encodeLabels' => false,
'activateParents' => true,
'items' => Tree::getMenuItems('root'),
]
);
Backend
- visit
/pages
to create a root-node for your current application language. - click the tree icon
- enter
name identifier (no spaces and special chars)
as Domain ID and Menu name and save - create child node
- assign name, title, language and route/view
- save
Now you should be able to see the page in your Nav
widget in the frontend of your application.
Traits
We use the \dmstr\activeRecordPermissions\ActiveRecordAccessTrait
to have a check access behavior on active record level
- Owner Access
- Read Access
- Update Access
- Delete Access
Anchors
available since 0.12.0-beta1
👷 A workaround for creating anchor links is to define a route, like /en/mysite-2
in the settings module.
On a node you can attach an anchor by using Advanced URL settings, with {'#':'myanchor'}
.
It is recommended to create a new entry in Tree mode.
i18n - sibling pages
Find sibling page in target language
/**
* Find the sibling page in target language if exists
*
* @param string $targetLanguage
* @param integer $sourceId
* @param string $route
*
* @return Tree|null
* @throws \yii\console\Exception
*/
public function sibling($targetLanguage, $sourceId = null, $route = self::DEFAULT_PAGE_ROUTE);
Example 1:
---
// page id 12 is a node in language 'en'
$sourcePage = Tree::findOne(12);
// returns corresponding page object in language 'de' or null if not exists
$targetPage = $sourcePage->sibling('de');
Example 2:
---
// find by params
$targetPage = (new Tree())->sibling('de', 12, '/pages/default/page')
Testing
Requirements:
- docker >=1.9.1
- docker-compose >= 1.6.2
Codeception is run via "Potemkin"-Phundament.
cd tests
Start test stack
make all
Run tests
make run-tests
Ressources
tbd