Drupal views

Posted under » Drupal on 26 May 2016

I used to think Drupal's main strenght over other CMS like wordpress is the taxonomy module. However I just discovered how powerful the views module is. In version 8 it is now made into core.

Initially it's main purpose for me is to select articles by tags or taxonomy. You can then present it according the format you want ie. table or the normal format. You can also make your views into a box.

In 2016, you can also put a style to the fields that you have selected. Say you want the title to be red, just add a custom CSS. Go to your template CSS and then put in your styles.

Now you can see your sql.

SELECT "node_field_data"."title" AS "node_field_data_title", "node_field_data"."nid" AS "nid" FROM
{node_field_data} "node_field_data" LEFT JOIN {node__field_actress} "node__field_actress" ON node_field_data.nid = node__field_actress.entity_id
WHERE "node__field_actress"."field_actress_target_id" = '1'

Which is great if you are weak in SQL like me. With this info. you can use peewee to create something similar like

(node_field_data
         .select(node_field_data,node__field_actress.entity_id)
         .join(node__field_actress, on=(node_field_data.nid == node__field_actress.entity_id))
         .where(node__field_actress.field_actress_target_id == 1)).order_by(node_field_data.title.asc())

Which give

SELECT `t1`.`nid`, `t1`.`title`, `t2`.`entity_id` FROM `node_field_data` AS `t1`
LEFT JOIN `node__field_actress` AS `t2` ON (`t1`.`nid` = `t2`.`entity_id`) 
WHERE (`t2`.`field_actress_target_id` = 1);

web security linux ubuntu Raspberry   git   javascript python django Laravel drupal php apache mysql  MongoDB AWS data  ML AI