

Each have their own controller actions, so let's create them: So, we have already defined those as: Deleting, Enabling and Disabling posts. Now we have all our files required to make the grid page work, you should now be able to clear cache and access the grid page! Huzzah!

Ui/Component/Listing/Column/PostActions.php: This is another source for available actions to do to a single blog post The last class we're missing is the one we defined for our 'actions' column. The next missing class was define on our last column is_active we defined a custom class for outputting the options available! This is a new class: Ashsmith\Blog\Model\Post\Source\IsActive. These are just aliases to other classes, both UI Components on which we need to customise the arguments passed (we provide PostGridDataProvider with our resource collection for example) Simple! After that we define two virtual types. just implementing the interfaces and then using our di.xml to switch out the class. This is essentially how we can implement our own logic into core Magento. The first is the node, this essentially when Ashsmith\Blog\Api\Data\PostInterface is a dependency, use Ashsmith\Blog\Model\Post. In our di.xml we have made 3 declarations. So let's create our DI configuration file: etc/di.xml We'll setup a virtual type, which is an alias to our resource collection. Don't worry though, this is where Dependency Injection comes in. Under our node we defined the class: PostGridDataProvider. Our last column is an 'actions' column, allowing you to edit or delete from a little dropdown menu.Define our columns for the grid component.Setup and configure our JS, and data sources.Let's quickly cover what we've done here: Views/adminhtml/ui_component/blog_post_listing.xml It's fairly beefy, as this controls adding all the components that make up our grid view. We've registered our component, so lets create it, again this is just another XML based configuration file. In here we simply register our UI Component! If you want to learn more about UI Components, head to the Magento 2 dev docs: īefore we dive in with our UI Components, we'll need to create our layout file: view/adminhtml/layout/blog_post_index.xml Now that we have our controller setup we need to setup the UI components that will make up our admin grid. On top of this we have set a constant named ADMIN_RESOURCE this is what we defined in our ACL for whether or not a user is allowed access to this page. Much like a standard controller actions, but instead of extending \Magento\Framework\App\Action\Action we now extend \Magento\Backend\App\Action. * \ Magento \ Backend \ Model \ View \ Result \ Page */ public function execute ( ) resultPageFactory = $resultPageFactory } /** Start by creating: etc/adminhtml/routes.xml As we have already specified a path for our menu link we'll need to use that same convention within our routes configuration.

Let's move onwards by defining our admin routes.

So we now have our menu, and ACL configured. We'll be making use of these in our controllers and block to change how the page looks for certain users. Finally, we have our save and delete resources. That will handle displaying/hiding the links within the menu based on the users access rights. Then using the same resource identifiers we used in our menu.xml we can define the access. Because our blog belongs under the Magento_Backend::content in our menu, we need to embed our resources within there. The ACL may feel familiar to that of Magento 1.x. Next, let's define some ACL rules so that admins can give fine grain control over other admin users! action - If you want your link to be clickable specify the path: i.e.parent - The ability to specify what node this belongs to, or where to nest the menu item.sortOrder - Ordering within the list of items.Namespace it with your module name to avoid conflicts. id - A unique id to give to the menu item.First, is simply a heading, the next is our main item which will link to the blog posts grid! I wanted to nest the blog under it's own section in case I decide to add Categories, tags or other common blog features in the future! within the node we instruct magento to add two new items.
