官术网_书友最值得收藏!

Summary

In this chapter, we covered a great deal of info about the things you need to know when developing Drupal 8 modules. The first thing we did was create our very own module skeleton that can be installed on a Drupal 8 site. Then, we saw how to create a new page at a specific path (route) and show some basic data on that page. Nothing too complex, but enough to illustrate one of the most common tasks you will do as a module developer. We then took that to new level and abstracted the logic for that data calculation into a service. Not only that, but we also saw how we can use that service, and, more importantly, how we should use it. Next, we saw how we can work with the Form API in Drupal 8 to allow administrators to add some configuration to the site. A very important takeaway here was also that the Form API page in Drupal 8 will prove invaluable going forward because you have many different types of form elements at your disposal. So, keep that close by. Also, since we talked about forms, we also saw how we can alter the existing forms defined by other modules--an invaluable technique for any module developer.

Next, we created our first custom block in Drupal 8, which allowed us to reuse our service and be more flexible with where we show our data.

Then, we looked at how to create URLs and links programmatically in Drupal 8. In the functionality we built in this module, we don't need any links, yet. However, it is a common practice to work with them, so we had to learn early how to generate links and work with URLs properly in Drupal 8.

In our last section, we explored the Symfony Event Dispatcher component, a bit that allows us to dispatch and subscribe to events. We saw some examples of how we can subscribe to one of the main Kernel events in order to redirect the page, but we also saw how to dispatch our own event. The latter was meant to allow subscribers to make changes to our data, but we also saw how we can invoke our own alter hooks for the same purpose.

Most of the topics we covered in this chapter were meant to give you an initial boost and the tools to start developing modules in Drupal 8. They represent the absolute most common things--I believe--any new Drupal developer encounters and has to do. You will probably find that many of the things you will learn in the rest of this book will serve you only after some of the things we covered in this chapter are done in your module.

In the next chapter, we will look at two important aspects most applications will need to use. One is logging--the better your site logs its errors and important actions, the easier it will be to debug and trace back issues. Another is mailing--websites usually need to send out emails to users in one way or another, so it's important that we see how that works in Drupal 8.

主站蜘蛛池模板: 黑河市| 瑞金市| 达日县| 左权县| 伽师县| 小金县| 中山市| 栾川县| 保定市| 察雅县| 龙南县| 苍梧县| 盘锦市| 阿图什市| 得荣县| 平度市| 乌鲁木齐市| 盐津县| 武陟县| 嘉黎县| 宣化县| 峡江县| 福泉市| 鄂尔多斯市| 灵丘县| 信阳市| 兰坪| 海门市| 雷州市| 措勤县| 达尔| 大港区| 新沂市| 南丰县| 临澧县| 驻马店市| 嘉禾县| 青田县| 瑞安市| 克山县| 通州区|