DefaultResourceGroup Plugin Tutorial
If you use this extra and like it, please consider donating. The suggested donation for this extra is $5.00, but any amount you want to give is fine (really). For a one-time donation of $50.00 you can use all of my non-premium extras with a clear conscience.
DefaultResourceGroup is a plugin for MODX Revolution. It automatically places newly created Resources into one or more designated Resource Groups.
Fully updated for MODX 3
Upgrading may disable the plugin. If so, edit the plugin, set the plugin as active, and save it.
If you have not created your own property set for the plugin and attached it to the plugin, you will need to edit the plugin's properties with your values.
The DefaultResourceGroup plugin places all new resources into a default Resource Group or groups. It will not change the Resource Group settings of existing resources when you edit them. If the user checks certain Resource Groups when creating the resource, those selections will be honored, but the plugin will also add the resource to the specified default Resource Groups.
If, for example, you want to give users other than the admin Super User (or users who are not members of the Administrator User Group) access to only a small subset of the resources on a site, you could create a Resource Group called AllDocs and connect that Resource Group to the Administrator group with a Resource Group Access ACL entry. Then, tell the plugin to put all new resources in the AllDocs Resource Group. That way, every resource on the site will be hidden from other users. You can then give those users access to specific resources and the rest will remain hidden.
The plugin will work on new resources created on the Create/Edit Resource panel, or resources created using the "Quick Create" option when you right-click in the tree. It will have no effect when editing existing resources, or when duplicating existing resources. The plugin will not affect resources created in code or by extras such as NewsPublisher.
Go to Extras -> Installer on the main menu in the MODX Manager and click on the "Download Extras" button. That will take you to the Revolution Repository. Put DefaultResourceGroup in the search box and press Enter. Click on the "Download" button, and once the package is downloaded, click on the "Back to Package Manager" button. That should bring you back to your Package Management grid. Click on the "Install" button next to DefaultResourceGroup in the grid. The DefaultResourceGroup package should now be installed.
There is only one property for the plugin, it is the drg_groups property. It contains either the name of a specific Resource Group to put new resources in, or a comma-separated list of group names (use no spaces). If the property is set to Parent, new resources will inherit the parent's resource groups.
Rather than changing the default property of the plugin to set drg_groups, you should always create a Property Set.
Important: Be sure to clear the site cache after setting or changing the property.
Creating a Property Set for the Plugin
If a plugin has default properties, you can set those properties on the Properties tag when editing the plugin. This is a bad practice, however, because the values you set may be overwritten when the plugin is upgraded. Instead, you should create your own Property Set for the plugin and then attach it to the plugin.
Creating the Property Set
- Right-click on the plugin in the Element tree and select "Edit Plugin"
- On the right panel, click on the "Properties" tab
- Click on the "Add Property Set" button
- Check the "Create New Property Set" checkbox
- Give the Property set a unique name (e.g., MyPluginNameProperties)
- Click on the "Save" button
- You should see the Property Set name above the grid
- (If you see 'Default' instead of your property set name, click on it and select your Property Set from the drop-down list)
- Note that your Property Set has not been saved
- Set property values by double-clicking in the "Value" column or right-clicking on the property and selecting "Update Property"
- When finished setting values, click on the "Save Property Set" button at the upper right
As you edit plugin values, you will see the default properties in the grid, but they are not really "in" your Property Set. They're just there for your information. The only properties truly in your set are the ones you change. After you save the Property Set, the properties you've changed will be in a different color (usually green). If you add new properties to your Property Set that are not in the default properties (using the "Create Property" button), they will be in yet another color (usually purple).
Important! Whenever you go back to edit the Property Set in the future, select it from the drop-down list above the grid (where it says 'default'). Don't forget to save your changes by clicking on the "Save Property Set" button.
Attaching the Property Set to the Plugin
The values in your Property Set will have no effect until you attach them to your plugin. To attach them, follow these steps:
- While still editing the plugin, click on the "System Events" tab
- Scroll down to see which System Events the plugin is connected to
- In the row of the System Event, you should see two numbers on the right
- The left number (in the "Property Set" column) specifies the Property Set
- Often, you will see a 0 there, which tells the plugin to use the default properties
- If you double-click on the number, you should see a drop-down list
- Select your Property Set from the list
- If the plugin listens to multiple events, be sure to set the Property Set on all of them
- Click on the "Save" button at the upper right to save the plugin and the Property Set specification
If the plugin listens to more than one event, you can have a different Property Set for each event, but it's also fine to put all the properties in one Property Set and specify that set for all events.
Enabling the DefaultResourceGroup Plugin
When installed or updated, the plugin is disabled. You can enable it by editing the plugin, setting it to active, and saving the plugin.
If you have the book and would like to download the code, you can find it here.
If you have the book and would like to see the updates and corrections page, you can find it here.
MODX: The Official Guide is 772 pages long and goes far beyond this web site in explaining beginning and advanced MODX techniques. It includes detailed information on:
- Installing MODX
- How MODX Works
- Working with MODX resources and Elements
- Using Git with MODX
- Using common MODX add-on components like SPForm, Login, getResources, and FormIt
- MODX security Permissions
- Customizing the MODX Manager
- Using Form Customization
- Creating Transport Packages
- MODX and xPDO object methods
- MODX System Events
- Using PHP with MODX
Go here for more information about the book.
Thank you for visiting BobsGuides.com
— Bob Ray