Những tips cần thiết đọc đề làm việc với Drupal 8

Những tips cần thiết đọc đề làm việc với Drupal 8

In this post, I will share my experience on trying to learn Drupal 8 during its alpha stage, talk about some of the challenges of keeping up with the ongoing changes while trying to learn it, and end with some tips and resources which proved useful for me.

How it began

During a few weeks, a group of colleagues and I embarked on a learning project to get up to speed on all things Drupal 8. We did not fully know what to expect given that we were starting this at a time when D8 was still in Alpha and changes (even big ones) kept coming daily.

So, my goals for the project were to at least gain some understanding of the new concepts while coming up with a simple "Hello World"-type module I could build on, to gather some hands-on experience with D8. Simple, right? There were certainly challenges though.

Challenges

I started by reading up on the different bits around the modern programming patterns used in D8. Even though I have not yet grasped it all (and it was a long read), it was rather straightforward.

However, it turned out that D8 was at a point in time where major changes were still occurring--every day brought small and big changes to the main branch of D8, causing some or all of these when updating D8 to the latest version:

  • Existing contrib modules would dramatically break or fail silently
  • API functions would be deprecated, changed or replaced by classes
  • Blog posts/videos/etc. to guide you on learning D8 would no longer apply to the current code

Even during writing my simple "Hello World" module proved a challenge. For example, I sought out 3 different tutorials on the web on how to write a simple module before finding one that actually worked--and even then I only got partial results.

I did not know how to quickly adapt to D8 module writing using my previous knowledge. For example, I knew of hook_menu() for D6-7, and I had added a hook_menu() to my new module... but my current code was just being ignored and I couldn't understand why.

So, some questions began to form in my head:

  • Starting from my previous knowledge of Drupal 7, how do I find out what the 'new way' of doing things is?
  • How can I keep up to date on any important changes that are introduced that I should know about?

Bit by bit, consulting with my learning partners, I learned about a few resources and tips I could use and that adapted to my "learning Drupal while it's still changing" workflow (hopefully this workflow will slow down a bit in beta)

I will now share a few of the things that worked for me, and hopefully, will also help you get up to speed in learning D8. These are not meant as a summary of things you should know, but some tips and resources that help you find out what you don't know.

Change records

D.O keeps a list of all Change Records at https://drupal.org/list-changes/drupal, each of which summarizes any major change as it makes it into core, such as an API or other. Each record also indicates the work to be done post-change, e.g. whether the change now needs patches to the Examples project, requires additional documentation, etc.

A nice thing is that you can run searches across the change records, for example, for a particular function or topic. I also found it useful to add the RSS feed at https://drupal.org/changes/drupal/rss.xml to my feed reader so I can get an idea of the ongoing changes.

Contrib D8 modules

A good source of examples of how to code for D8 are any of the available D8 modules; especially any you already know from D7, or that are simple enough to follow (and, also, that you are lucky enough to have actually work the moment you install them on a current D8 setup).

A great resource for beginners learning any version of Drupal is the Examples project (https://drupal.org/project/examples). Thoroughly-documented, it contains a set of modules that you can read and hack on. Even though some of the submodules were broken under the latest D8 code, they still taught me a lot.

Using api.drupal.org

http://api.drupal.org , being generated from the codebase itself, contains the most up-to-date documentation. It's so useful, I have a Firefox keyword set up to find stuff in the site (This blog explains more here!).

One useful thing during my D8 learning that I came across is that you can find out whether a certain function has 'gone away' or has been replaced by something else in D8.

For example, the change record at https://drupal.org/node/2259297 mentions "form_options_flatten() is replaced by \Drupal\Core\Form\OptGroup::flattenOptions". If you then look at https://api.drupal.org/api/drupal/core!includes!form.inc/function/form_options_flatten/8 you can see the API docs mention this as well--at least for now! (I don't know if there is a transition period at the end of which this will disappear from api.drupal.org).

Diffing code

I downloaded the latest stable D7 and the latest D8 HEAD and compared a few of the core files using a diff viewer (my favorite is Meld). For example, comparing D7 and D8 versions of bootstrap.inc and common.inc gave me a good idea of some general changes in programming patterns:

  • Changes around modern PHP patterns like namespaces, using const instead of define().
  • Usage of Symphony Request objects, avoiding any references to $_GET or other webserver environment variables.
  • Code that is on the way out during the D8 dev cycle is marked with @deprecated within the function’s PHPDoc block.
  • Some families of functions are now grouped into utility classes. E.g., D7's timer_start() and timer_end() are now inside the D8 Drupal\Component\Utility\Timer class as Timer::start() and Timer::end().
  • Reading some function PHPDoc comments side-by-side on a diff viewer sometimes lets you know what changed at a glance. One thing that jumps out is that PHPDoc blocks now specify the argument types, allowing IDEs to check whether you're calling a function using the correct argument types.

All of these I had probably read about and had the general idea, but seeing the actual changes flagged via the diff viewer onscreen helped me understand them.

Using an honest-to-goodness IDE

I've grown amazingly fond of PHPStorm as a Drupal IDE. It offers code completion, code inspection (e.g. "Hey, you defined this variable which you are not using anywhere!") and other features which makes you question How You Ever Got Along Without It.

And now, with D8 and all those classes extending classes, interfaces and whatnot, you can very easily:

  • know if a class extends another, and lets you easily navigate in/out of the class hierarchies.

Những tips cần thiết đọc đề làm việc với Drupal 8

d8 photo 2

  • find out whether any functions/methods in use that been marked as deprecated (the editor nicely highlights things for you)

d8 photo 3

  • search all your code's functions, classes, variables, constants, etc. for anything:

d8 photo 4

Conclusion

I hope the above gives you some ideas on how to use a few of the mentioned resources to help you learn D8. Even though you might feel overwhelmed at first, keep going! You will eventually start grasping the new patterns and will start coming up with your own workflow to deal with learning it.

 

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Khanh Hoang

Khanh Hoang - Kenn

Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Những phụ kiện công nghệ tuyệt nhất 2011

Những phụ kiện công nghệ tuyệt nhất 2011

Vòng tay theo dõi sức khỏe, tai nghe chống ồn, chuột cảm ứng,..những phụ kiện cực kì xinh xắn nhưng cũng không kém phần thông minh.

Updating Drupal core automatically

Demo chưa hoàn chỉnh: Updating Drupal core phiên bản 8.x tự động

Last week Drupalcon North America was held in Seattle, where Dries opened the conference with the traditional "Driesnote"

Số tiền nặng tới 3.700 tấn của Apple sẽ mua được những gì?

Số tiền nặng tới 3.700 tấn của Apple sẽ mua được những gì?

Xem số tiền của Apple có thể mua được những gì khi song sánh với các ngành công nghiệp khác.

Công ty diệt chuột T&C

 

Diet con trung