How to add About author block to News article

Exercise 8.5: Create the author block

In this exercise we’ll create an author block.
  1. 1.
    Prepare the site
To maximise this exercise, make sure user accounts have profile images. Out-of-the-box, GovCMS8 does not have a profile image available. Let’s add it.
  1. 1.
    Navigate to ConfigurationPeopleAccount settingsManage fields. You’ll notice that this interface is exactly the same as for content types.
  2. 2.
    Add an Image field, using your previous experience adding fields. Make the Image field match the following criteria:
  • Field type: Reference > Image
  • Label: Profile Image
  • Machine name: field_profile_image
  • File system type: Public files
  • Upload a default generic profile image (you may Google for “user profile placeholder” and get an image you like) --------->
  • Allowed number of values: 1
  • Required field: yes
  • File directory: profile_photos
  • Minimum image resolution: 150x150px
  • Maximum upload size: 1MB
  1. 1.
    Configure Manage Display:
    1. 1.
      Place the Profile Image above all fields
    2. 2.
      Hide the field label
    3. 3.
      Apply Image style: Medium
Add images to the profile of some website users. Alternatively use the Generate users function (ConfigurationDevelopmentGenerate users).
Next, change the authors of existing content so we have a variety of authors. Edit the “Authoring information” tab in the existing News and Media and Job postings.
Alternatively use the Generate content function (ConfigurationDevelopmentGenerate content). Select News and Media, Job posting content types.
Note: If the Generate content function was used, make sure you publish your News and media posts. Remember, they’re not published by default due to the Moderation workflow in place.
Add a new View
    1. 1.
      Go to Structure → Views and click + Add new View
    2. 2.
      Use the following information to fill out the form:
  • View name: About the author
  • Show “Users” sorted by “Unsorted”
  • Select “Create a block”
  • Ensure display format is Unformatted list or Fields.
  • Change items per page to 1. Use the defaults for everything else (ensure the settings are as shown in the image below)
  • Click Save and edit
This loads the full Views editing screen. This illustration correlates to the steps outlined below.
Add fields to the View Notice the “Advanced” options available in Views.
    1. 1.
      In the left column, find and edit fields by clicking Add
    2. 2.
      Select User: Profile image
    3. 3.
      Apply the changes
    4. 4.
      On the next configuration popup screen, apply the Image style Medium (220x220).
    5. 5.
      Make the image linking to Content.
    6. 6.
      Apply your changes.
    7. 7.
      Rearrange the User: Profile Image field to stay above the User: Name field
Make display dependent on author of content (contextual filter)
  1. 1.
    On the right-hand side, click Advanced to expand the settings.
  • Next to Contextual filters click Add
  1. 1.
    In the next screen, type “ID” into the search field
  • Select “User ID”
  • Click Add and configure filter
  1. 1.
    In the next screen, select “Provide default value”. This opens extra options.
  • Under type: Select “User ID from route context”
  • Select “Also look for a node and use the node author”
  1. 1.
    Select Specify validation criteria under “When the filter value IS available or a default is provided” and select User ID as Validator.
  2. 2.
    Click Apply. The window will close.
Check the preview When you check the preview you’ll notice nothing is displaying. To fix this:
  1. 1.
    Type 1 and click Update preview. This pulls in the profile of user/1
  2. 2.
    Click Save at the top of the Views editing screen
  3. 3.
    Place the block and test
Now we can configure the block to display on News and Media articles. The News and Media content type is set up by default to use Panelizer view. The Panelizer view replaces the default GovCMS page layout and provides a way to build a “layout within layout”.
Check the Manage Display page of the News and media content type:
You’ll see that the page has multiple View modes activated. The Full content view mode overrides the page display for our content type. Let’s explore it.
Notice that this display configuration page looks completely different to our Job posting content type. Instead of fields and display modes we see Displays here. By default, the Sidebar right display is used to render our News and Media content.
You may also notice that the Content Editors are allowed to select which display to use. This flexibility provides alternative display options for showing our News and Media articles, but introduces some extra complexity in configuring it.
Let’s review how the panelizer content is configured. We’ll practice placing the Content Author block in our News and Media articles.
  1. 1.
    Click the Edit button in the Sidebar Right (2:1) row
Click the Content vertical tab on the left:
Explore the Content page. See how it has their own regions defined
Click the Add new block button at the top of the page
Under the Lists (Views), locate the block we prepared earlier:
Select Sidebar region and Add block
Position the About the author block below other blocks within the Sidebar region
Click Update and Save
Test it by navigating to a published News and Media article. You may update the content of the page and the Authoring information, to check how the display changes.
Logout and test: Can anonymous users see the block?
At the moment, anonymous users can’t see the block. The final step is to set up permissions so anonymous users can see user profiles.
    1. 1.
      Go to People → Permissions
    2. 2.
      Scroll down to “View user information”
    3. 3.
      Select to allow Anonymous and Authenticated users to View user information
    4. 4.
      Scroll down and click Save permissions
Now when you go back and check the site as an anonymous user you’ll see the author information.
Export as PDF
Copy link