Automatically populate content

Rating

This contribution deals with automatically generated content.

1) Default values

Take a field (eg image field to make a banner on each node, or a piece of text) en set content default.

Drupal8_002704.png

Put this field in the form modus disabled. Done..
Drupal8_002705.png

There is a Markup module that does the same..I don't see any difference.

2) Reference fields

A refence field can give the rendered entity in the display mode. As you know, one can create display modes in Drupal 8 yourself with the fields you want. So... you can show everething you want.

Drupal8_002713.png

Here i choose the teaser mode.


Drupal8_002715.png

3) Use of Tokens

credits: https://www.ostraining.com/blog/drupal/prepopulate/

Install the Token Filter module: https://www.drupal.org/project/token_filter

Go to the text format settings and enable the filter.

Drupal8_002706.png

From now on you can use tokens in textfields.


Drupal8_002707.png

The result. I added three fields together in one field..Hide the other fields..


Drupal8_002709.png

Where can you find the tokens. Go to Help = > Token. Yes... the Help tab is usefull..


Drupal8_002708.png

Even with reference fields one can reference to fields from another content type.

I have a content type 'paintings' with  reference field 'painters'. This content type has a name and an image field of the painter.

So i can show the image field of the painter in the node of the painting.

Look for the token in the Help tab.

Drupal8_002710.png

The result.
Drupal8_002711.png

You can also switch to the source code and add some CSS classes.

Drupal8_002712.png

4) Automatic Entity label

https://drupal8.support/nl/modules/automatic-entity-label

The title field can be automatically generated with this module.

Drupal8_002299.png

Go to the settings.


Drupal8_002300.png

When the title is not filled in, the module does the job.


Drupal8_002301.png

We try..
Drupal8_002302.png

Yep...
Drupal8_002303.png

And when i fill in the title...
Drupal8_002304.png

5) Computed fields

https://www.drupal.org/project/computed_field

We are going to discuss this module with some examples..

a) Calculate a total price with a maximum of 40 €.  10 €/adults, 5€/children

Drupal8_002716.png

The result..
Drupal8_002717.png

Above the 40 €. (used to be 45€)


Drupal8_002718.png

b) Generate images depending on field values.

I have a field with 2 kinds of reduction. 10 and  20

Drupal8_002721.png

In stead of showing the numer i prefer to display an image.

Drupal8_002719.png

The 10 % choise..


Drupal8_002720.png

The computed field does the job. You need to give the images a specific name of course. 10.png and 20.png and put them in the correct folder.

Drupal8_002722.png

6) PHP field with views

Believe it or not.. one can not use a date field for dates before 1900. Day one is 1/1/1900. Before that there was the big bang according Drupal...(seems to be a php problem) I created a workaround to deal with this problem.

See the birthdates of some painters. I made a view that shows the dates and sorts them correctly. I can even generate a view field that shows a birthday.

Drupal8_002723.png

You need three separate fields. Day, month and year. 
Drupal8_002724.png

With a computed field we can make a field that looks like a date field, but is not one.. You can not sort on it.

Drupal8_002725.png

the code..
Drupal8_002726.png

For sorting i create another field. Counting the days from 1/1/0000 (you can change them if you need to deal with Greeks and romans... LOL) Mind the avarage days in a year and month.
Drupal8_002727.png

In the view i use now a PHP field: https://www.drupal.org/project/views_php
Drupal8_002728.png

With php one can now generate everething you need. Here there is a birthday anouncement, from 2 days before the birthday. PHP in views is not saved into the database. It is an 'ad hoc' value.

Drupal8_002729.png

7) Iframes

https://www.drupal.org/project/iframe

You can capture content from every site you want and add them to your content. As this method is depreciated and even blocked bij some browsers like Chrome. I only mention this possibility but i do not recommend it. You can overrule the safety settings on the server, but is stays not done...

8) Devel Generate

This module comes with the Devel module: https://www.drupal.org/project/devel

One can add dummy content.

Drupal8_002735.png

Choose your content type and do the settings.

Drupal8_002730.png

The result... Content types with images, taxonmy, reference fields... Everething is filled with content.


Drupal8_002731.png

Lorem ipsum content.
Drupal8_002733.png
9) Rules

With rules one can add content automatically. On this moment Rules is not user friendly enough to do this.

10) Feeds

CVS import not ready yet. Still waiting..

11) Node Export

Yep... not yet in Drupal 8.

12) VBO

Views Bulk Operations is built in in Drupal 8 core. One can publish, depublish, delete,... content, but not change content.

This module will change that: Bulk Update Fields (https://www.drupal.org/project/bulk_update_fields) Not ready yet...

13) Views

With Viewfield or EVA, content can be created in a node.