Making a blog part 1 Entities, entity types & permissions - CityWebConsultants/Iris GitHub Wiki

Objective

In this tutorial you will learn how to make a simple blog site and theme it.

Step 1 - Set up an Iris site

Follow the instructions on setting up an Iris site. Your site can be called whatever you want but this tutorial will refer to it as mysite.

Enable some modules

Visit /admin, log in, and go to the modules page in the admin toolbar over at /admin/modules.

Enable the following modules by ticking them and hitting save at the bottom of the form.

  • Entity UI
  • Permissions UI
  • CKeditor

Create a blog entity type

Head over to the structure tab of the administration toolbar and go to the entities page.

Press the Create new entity type button.

On the following form type blog for entity type name and add an optional description for the blog type.

Add some fields

You should be redirected to a manage fields page where you can add some fields for the blog type. Let's start with a title field.

  • On the manage fields page tap add a new field and fill in title as the field label.
  • Under field type select textfield
  • Hit save
  • On the next page you should be able to set some extra options for the field. Set the description as The title for this blog entry, tick both anonymous and authenticated on the field view permissions (we'll cover this in more detail later)
  • Tick the unique field box as you won't want two blogs to have exactly the same title.
  • Hit save field and you should be redirected back to the manage fields page, now showing your title

Now let's repeat the same steps but add the main body field for the blog.

  • Add a new field called body of type Longtext. Give it a description, don't make it unique (though you could use this to catch two blogs with exactly the same content!). Make it visible to both anonymous and authenticated users. Hit save.
  • Go back to edit the field in the list of fields and, under the widgets section at the bottom of the page you should see a CKeditor option if you enabled the CKeditor module successfully. Hit save there as well. This will make the editor a rich text area with formatting buttons rather than plain text.

Our final field (for now, you can add as many as you want later) is a path field that will allow the field to be visible at a custom URL path.

  • Add a new field of type textfield and call it path (currently Iris automatically reads entity paths from an entitiy's path textfield). Save its settings like you did for the previous fields.

Permissions

Head over to the user section of the admin toolbar and go to the permissions screen. The permissions options for your new blog type will have automatically been created. Look for the entity section and find the can view any blog permission. Tick both anonymous and authenticated (you can create more roles later but that's beyond the scope of this tutorial).

Field permissions vs entity level permissions

You may have noticed that earlier you set individual field permissions for your blog entity type's title, body and path fields. These are checked after the general entity permission. If you don't allow a user to see an entity at all from blocking it on the general permissions page, the field permissions won't matter. They serve to strip out any fields that a specific user role shouldn't see when the entity is viewed.

Write your first blog entry

Head over to structure, entities, find the blog entity type in the list and in the drop down on the right of the entity type select create new.

Fill out the title, path and body fields of your blog and hit save. For the path field, make sure to include a leading forward slash for the path (/my-first-blog for example).

If you head over to your blog entry's path at /my-first-blog you'll be faced with a basic list of all your fields without any HTML formatting. You probably want a slightly more sophisticated look for your blog. Instead of using an already downloaded theme, we're going to jump right in to making a theme from scratch so you can see how it works.