OctoberCMS change backend menu organization - menu

I want to change OctoberCMS backend menu organization.
Example:
I want to move from sidebar of Rainlab Plugin Static Pages - Menus to OctoberCMS CMS SideBar or it can be possible to add Rainlab Plugin Static Pages - Menus to main menu.

You can do this in your plugin.php file with registerNavigation function. For example this code define top menu and sidebar menu:
return [
'title' => [
'label' => 'title',
'url' => Backend::url('...'),
'icon' => 'icon-cube',
'permissions' => ['access.*'],
'order' => 501,
'sideMenu' => [
'title' => [
'label' => '....',
'url' => Backend::url('....'),
'icon' => 'icon-slack',
'permissions' => ['access'],
'order' => 500,
],
Also in your controller you must define this:
BackendMenu::setContext('Author.Plugin Name', 'plugin', 'model');

I know this might be really obvious but I'll still say it just to be sure. If you are looking at changing the appearance or location of Backend Menu Items provided by plugins you did not author, don't make any changes to those files yourself. You would just loose all such custom changes everytime you update that plugin.
A better idea would be to create your own plugin that uses the 3rd-party plugin as a dependency and then make required changes to this new plugin.
Example Case: You wish to alter the display of the RainLab.User plugin backend menu item.
Create a new plugin and name it as needed. For ex: Acme.UserExtension.
Now in the plugin.php file of this new plugin you can add a dependency on the RainLab.User plugin and then hide it's menu item like so:
public $require = ['RainLab.User'];
public function boot()
{
/** Add a side-menu item */
Event::listen('backend.menu.extendItems', function($manager) {
$manager->addSideMenuItem('RainLab.User', 'user', [
'payments' => [
'label' => '...'
]
]);
});
/** Add a custom main-menu item */
Event::listen('backend.menu.extendItems', function($manager) {
$manager->addMainMenuItem('Acme.UserExtension', 'user');
});
/** Remove the original main-menu item */
Event::listen('backend.menu.extendItems', function($manager) {
$manager->removeMainMenuItem('RainLab.User', 'user');
});
}
As you can see you can completely remove a menu item for a plugin you dont own if you want. You could just extend it like shown above and just use the registerNavigation() method to do what you need for this extension plugin. You might have to replicate some of the menu items you do want to retain from the original parent plugin but now you have the ability to add some of your own or remove the items you don't need.
More details on how you can do this are here -> http://octobercms.com/docs/plugin/extending#extending-backend-menu
Hopefully this isn't too convoluted and helps you out.

While extending standard October backend controllers is very easy and described in documentation (mentioned in answers above), manipulations with Static Pages by RainLab are more complicated as "side navigation" (tabs) is handled with JavaScript. It's not possible to add a new item to this plugin navigation through the methods from the October CMS docs or to add "menu" sidemenu item to another plugin. With standard extend it's possible to show only one tab (you were asking about menu) but this won't set it as default and "pages" will still be shown as default.
If you are using only Static Menu my solution is to rename top menu Pages -> Menus and hide all tabs except "menu" with permissions (they will still be visible for admin but at least won't confuse backend editor). Will be happy if someone will share a better solution.
The code to place in your custom plugin, in boot() + don't forget to set permissions while creating a backend user for the client.
// Rename rainlab.menu pages to menu
Event::listen('backend.menu.extendItems', function($manager)
{
$manager->addMainMenuItems('RainLab.Pages', [
'pages' => [
'label' => 'Menu',
'url' => Backend::url('rainlab/pages'),
'icon' => 'icon-align-justify',
'sideMenu' => [
'menus' => [
'label' => 'rainlab.pages::lang.menu.menu_label',
'icon' => 'icon-sitemap',
'url' => 'javascript:;',
'attributes' => ['data-menu-item'=>'menus'],
'permissions' => ['rainlab.pages.manage_menus']
],
]
],
]);
});

Related

is there any easy way to get any changes of tabs, groups, windows of chrome for extension?

is there any easy way to get any changes of tabs, groups, windows of chrome for extension?
when one of these behavios :
create or close or moved a tab
or changed the url of the tab
or add in or out from a tabgroup
or create or close or release a tabgroup
or change the color or title of the tabgroup
or move the tabgroup
i know i could judage one by one by chrome.tabs.oncreate & chorme.tabs.onupdate etc.
but i wanna know weather is there a one action could judge all the changes one times?
thank you
No there isn't. But really I dont see why just not pick all the events you want and then call query
const listen = (events, callback) =>
events.forEach((event) =>
chrome.tabs[event].addListener(() => chrome.tabs.query({}, callback))
);
listen(
[
"onCreated",
"onAttached",
"onDetached",
"onHighlighted",
"onDetached",
"onMoved",
"onRemoved",
"onReplaced",
"onActivated",
"onUpdated",
],
(tabs) => {
console.log(tabs); // all tabs here
}
);

shopware 6: how can I get a price rule ID at updating productrepository

I have a question about programmatically updating a product via the Shopware 6 ProductRepository. I will update actionprices for my product.
But then rule Id is a required field. But how can I get this Rule ID field?
$price = [[
'linked' => false,
'net' => (float)$netPrice,
'gross' => (float)$grossPrice,
'currencyId' => Defaults::CURRENCY,
]];
$prices = [
[
'quantityStart' => 1,
'ruleId' => '???', // How can I get this???
'quantityEnd' => 10,
'price' => [
[
'currencyId' => Defaults::CURRENCY,
'gross' => $actionGrossPrice,
'net' => $actionNetPrice,,
'linked' => false
]
]
]
];
So how can I get this rule ID field?
Unfortunately you did not post the full code, especially the portion where you call the update function. I am assuming, that you are trying to set the "advanced pricing" of a product.
Before doing something programmatically, it might be a good idea to check how it's done manually.
In the admin panel (Shopware v6.4.3.0), creating advanced price rules also needs a rule id:
This refers to a rule created before unter Settings -> Shop -> Rule Builder.
There are some rules created by default, for example "all customers":
You can pick the rule ID from the URL when clicking that rule and use this in your code.
This might be fine if you write a plugin for one specific shop. But the rule would differ in other shops.
In case you are writing a plugin for a broader audience, I recommend to make the rule to be applied configurable in the plugin configuration.
You could of course also search programmatically for a rule "All customers" - but it might have been deleted by the shop owner.

Multiselect rendered as tags in documents

In Data Objects we have the possibility to render multiselects as tags. Is it possible to achieve the same functionality in documents?
We have tried the following but nothing seems to change:
<?= $this->multiselect($filter, [
"width" => 200,
"height" => 150,
'renderType' => 'tags',
"store" => \InteliveBundle\Model\Utils::getSelectOptions($filter),
"reload" => false,
'class' => "editmode-cssid",
'htmlspecialchars' => false,
]); ?>
According to the documentation you have the following configuration options:
store array Key/Value pairs for the available options.
width integer Width of a generated block in editmode
height integer Height of a generated block in editmode
class string A CSS class that is added to the surrounding container
of this element in editmode
https://pimcore.com/docs/6.x/Development_Documentation/Documents/Editables/Multiselect.html
Therefore this feature seems not to be implemented. You can make a feature request in https://github.com/pimcore/pimcore or even better you fork the project, implement this feature and make a merge request.

Removing the number of first page in Yii2 Pagination from the URL

For SEO purposes I need to remove the first page number from the URL. i.e I have the following:
example.com/pages/view/1 and example.com/pages/view the two URLs points to the same contents of the view action. I want to make the pagination free from 1 in the URL. i.e first Page link and Page Number 1 should be linked to pages/view.
I tried to deal with the $pagination object like the following:
$pages = new Pagination(['totalCount' => $books['booksCount'], 'pageParam' => 'start', 'defaultPageSize' => 10,]);
$pagingLinks = $pages->getLinks();
$pagingLinks['first'] = '/';
$pages->links = $pagingLinks;
However, the last line causing error:
Setting read-only property: yii\data\Pagination::links
So I have a problem to modify the links property. Is there any other solution to get this task done?!
According to docs you should set yii\data\Pagination::forcePageParam to false by passing it in Pagination constructor
$pages = new Pagination([
'totalCount' => $books['booksCount'],
'pageParam' => 'start',
'defaultPageSize' => 10,
'forcePageParam' => false,
]);
The above answer may works for direct use of Pagination but remain an issue if it was used from another widget such as ListView.
I found the solution from a comment on an issue report on Yii2 repository on github
The solution is just define proper route in config/web.php. Suppose here we have a controller called Suras and we use the ListView widget on its action's view called view. So placing rule array with defaults has value 'page' => 1 will prevent adding the page parameter to the link's URL of the first page. Also notice the first rule 'view/<id:\d+>/1' => 'Error404', is placed in-order to prevent any access to the first page using page=1 parameter, for example, trying to access mysite.com/view/20/1 will invoke 404 error, because there is no controller called Error404.
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'view/<id:\d+>/1' => 'Error404',
['pattern' => 'view/<id:\d+>/<page:\d+>', 'route' => 'suras/view', 'defaults' => ['page' => 1]],
'view/<id:\d+>/<page:\d+>' => 'suras/view',
'view/<id:\d+>' => 'suras/view',
],
],
],

How to integrate a non-node module into Open Atrium as a feature

I have built a non-node module and I wish to integrate it with Open Atrium as a feature.
I've experimented with a test feature to try "crack the code" of features, spaces, and open atrium, as the documentation does not cover this topic and I'm new to features, spaces, and open atrium.
I created a feature using features and then customised the info and module files.
Info file:
core = "6.x"
description = "A test feature"
name = "Test Feature"
package = "Features"
spaces[types][] = "og"
features[][] = ""code here
Module file:
function test_feature_menu()
{
$items['ftest'] = array(
'title' => 'Test Feature',
'page callback' => 'test_feature_page',
'access callback' => 'spaces_menu_access',
'type' => MENU_NORMAL_ITEM,
'menu_name' => 'features'
);
}
function test_feature_page()
{
$output = 'test';
return $output;
}
The feature appears in the features section, and when enabled, appears in the features menu regardless of what group I am in. Further, the groups have the feature set as disabled, but the item still appears in the menu.
Can anyone shed some light on this?
Thanks,
Greg.
Ok, I figured it out:
The access callback should be 'spaces_access_feature', and the access arguments should be array('view', 'test_feature');

Resources