-
Notifications
You must be signed in to change notification settings - Fork 2
Developing the local site
First of all install Drupal on your localhost by following this Drupal Installation Guide . I will recommend you to use latest Drupal 8 alpha 11. After successful installation you have to create a site which will have “tip” as its content type. “tip” content type has 3 fields title, body and tag. The ‘tag’ field uses taxonomy term as it value. So we have to develop taxonomy vocabulary first. To develop the vocabulary follow steps given below:
Step 1 Login to administrative account on your site and than navigate to Manage -> Structure -> Taxonomy as shown in figure.
Step 2 On next page click on “Add Vocabulary” button now give name and description for new vocabulary and then save.
Step 3 Now on next page under “List” tab click on “Add Term” button and in next page give name and description for new term. For our purpose I have added 2 terms “Linux” and “Drupal”. So after that your vocabulary overview page will look like this. Now save it.
Ok now we have created our “FOSS” taxonomy vocabulary. Next we create “tip” content type.
Step 1 Navigate to Manage -> Structure -> Content Type
Step 2 On next page click on “Add Content Type” , on next page give name and description for new “tip” content type and click “Save and Manage Fields”. You will get manage tab on your screen. Here note that “Body” field is already added now you have to add 1 more field one for “Tag”. “Title” will also there for your content type.
Step 3 Add “Tag” field and set it Filed Type to “Term Reference” and click Save. On field setting page set 1 for allowed number of values and chose vocabulary which we have created before. Then click “save field setting”. On next page check required field and click “Save Field”.
Now you get 2 fields for your “tip” content type. And you get “Title” by default. Now click on “Save”.
Now let’s try to add a node of type “tip” on our site.
Step 1 Navigate to “manage” -> “content” and click on “add content”.
Step 2 Select “tip” content type and on next page fill title , body and select tag for “tip”. and then click “Save and Publish”.
Ok we are done with custom content type called “Tip”. Now add 2 - 3 tips for both topics “Linux” and “Drupal”.
Next We will create view for these tips. But before we create view let’s enable REST web service first on our Drupal 8 installation. Navigate to “Manage” -> “Extend” In that page at bottom you will find WEB SERVICE section in that enable all module and then click on “Save Configuration”. I will also recommend you to install “REST UI”. It is contribute module to manage settings for REST services. After enabling that services your extend page will look like this.
Now let us create view that shows tips related to specific tag.
Step 1 Navigate to “Manage” -> “Structure” and click on “Views”. On next page click on “Add new view” . On next page you will find a form to create view.
Step 2 Now in this form give name to view, optional description and in “view setting” row select “Content” of type “Tip” . Now check on “Create a page”. Now give suitable title and path for the page and also choose display format then click on “Save and Edit”.
Step 3 Now you can configure more options for this view. On next page click on “add” button in “Filter Criteria” section and add filter called “has taxonomy term” . Now configure this filter to display only tips related to one tag. To do so follow as show in images given below.
NEXT
NEXT
NEXT
Step 4 Now click on “add” button at right side of the “page” section and select “REST Export”.
Now in this page select serializer setting first and set it so that it can export in json and hal_json format. Now instead of “Entity” select “Fields” in show row for Format section and add “body” and “Post date” fields.
Now click on setting for Fileds and check “raw output” for “title” and “created” field. Because we don’t want any mark up around the value. Step 5 Next add path for this REST Export page. You can give path like /drupalTips/rest and remember this path because it will be used in application to connect to site. Now save the configuration and try to access path for REST Export in your browser it will give you JSON object for tips for specific Tags. Here note that access permission for this page is “View publish content” so we don’t require username password to see this content. If every thing goes perfect you should see following out for tips which are added by you.
Ok great so we are done with Drupal set up for now.