In this exercise you will add an Image media field to a content type and learn how to configure it. There are four steps involved:
Create an image style
Configure an Image Media entity view mode to use an Image style
Check permissions
Add image field to content type
Image styles are set and configured in the Image styles admin page.
Go to Configuration → Media → Image styles.
To create our new image style, click on the Add image style button at the top of the page.
Name it Job Posting Image (given the image style will be applied to the “Job posting” Featured Image field.)
Click the Create new style button to save the new image style. You’ll then be taken to the Edit style Job Posting Image page as seen below.
The next step is to add the Scale effect. Under Effect select Scale from the dropdown menu.
Click Add. You’ll then be taken to the Add scale effect page.
Enter the following settings:
Width: 1200
Height: leave empty This allows you to have a flexible image height and keep the original proportions of the image.
Leave the Allow Upscaling checkbox unselected Image upscaling usually leads to poor image quality.
Click Add effect.
Your image style has been saved. You can make additional changes and then click the Save button to save those changes.
Navigate to the Structure → Media types → Image → Manage display (/admin/structure/media/manage/image/display). You should see some out-of-the-box available view modes.
Scroll to the bottom of the page and expand the Custom display settings pane. You can see a few View modes preselected by default. Each selected checkbox here represents an enabled View mode at the top of the page.
Since we need to apply our custom Image style, we have to create a new View mode so that we don’t affect the display of existing images that are configured to display with other View modes.
Click on the Manage view modes link (see the previous screenshot) in a new tab/browser window.
Click the Add view mode button.
Select Media from the list.
Give it a name “Job Posting featured” and click the Save button.
Return to the previous browser tab/window - go back to step 2b above and refresh the page to get the updated list of View modes.
Repeat step 2b above by scrolling down and expanding the Custom display settings pane. You should now see the Job Posting featured view mode as a checkbox option. Select it and save the page.
Note, that the Job Posting featured tab is now available at the top. Click it to navigate to the view mode configuration page.
At the moment, the Image field is the only one available for display and it is set to show as the originally uploaded image, without any image style. We need to change it to apply our custom Image style.
Click the gear link on the right to change from the Original image to the image style Job Posting Image.. Press the Update button to save the changes.
Confirm the image style option has changed:
Press the Save button to save the changes.
Go to People → Permissions and double check the permissions for the content type: Job posting.
Make sure the Content Author role has permissions to Create, Edit any and Delete any Job posting.
Click Save permissions
Go to Structure → Content types → Job Posting → Manage fields page. Add a field following these steps:
Click the Add field button.
In the “Reuse an existing field” selector, choose Entity reference: field_featured_image.
Ensure the label reads “Featured Image”.
Click the Save and continue button.
In the next page, select the Create referenced entities if they don't already exist toggle in the Reference type fieldset.
Select Image as Media type.
Leave the remaining values to their defaults and Save settings. This will take you back to the Manage fields page.
Navigate to the Manage form display (secondary tabs).
Locate the Featured image field, set the Widget to Entity Browser.
Click on the cogs icon to configure the Entity Browser.
Change the Widget for the field as displayed below, then click on Update.