- Drupal 8 Module Development
- Daniel Sipos
- 230字
- 2021-07-02 15:45:18
Which way to link?
As we saw, we have a number of ways to create links and URL representations, but when it comes to creating a link, which method should we use? There are advantages and disadvantages for each one.
When it comes to URL, as mentioned, it's a good idea to stick to hardcoding routes rather than URIs. However, if you are working with dynamic data, such as user input or stored strings, the other methods are perfectly valid. I recommend that you look at the Url class in detail because you will be using it quite a bit as you develop Drupal 8 modules.
Regarding the actual links, using the service to generate a link means that you are creating a string at your point in the code. This means that it cannot be altered later in the process. On the other hand, using the Link class falls nicely in line with the entire render array rationale of delaying the actual generation to the last possible moment. We will talk more about render arrays later on. So, the choice you make depends on the link you need to generate and your answer to the following question: is the link something that might have to be alterable by other modules/themes? If so, proceed with the render array. Otherwise, you might consider generating if you can inject the service properly.
- 前端跨界開發指南:JavaScript工具庫原理解析與實戰
- JIRA 7 Administration Cookbook(Second Edition)
- 大學計算機基礎(第2版)(微課版)
- Unreal Engine 4 Shaders and Effects Cookbook
- Java程序設計
- H5頁面設計:Mugeda版(微課版)
- Visual FoxPro程序設計習題集及實驗指導(第四版)
- STM8實戰
- Hack與HHVM權威指南
- 軟件測試分析與實踐
- Microsoft HoloLens By Example
- Raspberry Pi Blueprints
- Web前端測試與集成:Jasmine/Selenium/Protractor/Jenkins的最佳實踐
- 軟技能2:軟件開發者職業生涯指南
- 樹莓派開發從零開始學:超好玩的智能小硬件制作書