The Featured Movie component, much like the Movie Card, presents similar requirements for field collections, which we will address pretty much the same way we did for the Movie card.
Let's start by creating the usual files for building the component:
Inside nitflex_dev_theme/src/_patterns/01-patterns/ create a new directory called featured-movie
Inside the featured-movie directory create these files:
featured-movie.yml, featured-movie.scss, and featured-movie.twig
Add the following code snippet into featured-movie.yml:
cover_image:"<img src=\"/sites/default/files/action-1.jpg\" alt=\"Alt text\" />"heading:heading_level:2modifier:title:"DrupalCon Seattle 2019"url:promo_text:"Be part of the 12th season this fall"mpaa_rating:"PG-13"average_rating:"5"synopsis:"Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit."watch_button:text:"Watch now"url:"#"modifier:"button--primary"
Be sure to create the featured-movie library and attach it to the component.
Breaking it down
By now you should have a good understanding of what we are doing here.
First we built an object in YML in which we outlined each of the fields the featured movie component needs. These fields include the movie title, average rating, MPAA rating, add to favorites button as well as a watch movie button.
Next we wrote the markup in twig which makes use of the data from the YML object. Most of this data is being passed to the component in the way of twig includes which makes use of previously built components such as heading, eyebrow and button.
Finally we wrote the css styles to give the featured movie component the look and feel we want.
Compiling the style-guide
Now that we have written all the necessary code to build the Featured Movie component, it's time to see the component in the style-guide. Let's compile our project first.
In your terminal or command line, navigate to /themes/custom/nitflex_dev_theme and run the following command: