Thursday, September 18, 2014

How to show terms in a Views in its hierarchical structure or tree structure?

We can show the taxonomy terms as hierarchical structure or tree structure by using views.
For example:


Vechicle is Vocabulary

      Car
            Honda
            Audi
            BMW
            Maruthi Suzuki
                  Marithi
                  Suzuki
      Bike
            Hero Honda
                  Hero
                  Honda
            Hero
            TVS
            Bajaj
      Bus/Lorry
            Ashok Layland
            Volvo
            Benz


Answer:

We can use Views Tree or Views Field View module to handle this kind of tree structure.

Please follow the below steps to show a taxonomy terms as tree view, by using Views Field View

1. Add new view (View name, Show -> Taxonomy terms, Either Page or Block display)
2. Add Relationship for "Taxonomy term: Parent term" name as "Parent" in Advanced section
3. Add Fields : Taxonomy term: Name (without relationship), Taxonomy term: Name(Parent relationship, excluded it from display)
4. Check or Add Filter Criteria "Taxonomy vocabulary: Machine name" to vocabulary name
5. Add Filter Criteria "Taxonomy term: Parent term" (with Parent relationship) equal to 0. (show only level 2)
6. In Format settings, Grouping field Nr.1 with field (Parent) Taxonomy term: Name.(to display level 1)
7. Add Sort Criteria, "Taxonomy term: Weight" (with Parent relationship) to Asscending order
8. Save it

The above steps to show the two level tree structure. If you want to show three level tree structure, then you have to add the below steps,

Enable Views Field View module

9. Add A new display (an attachment is good)
10. Override its fields (just click any field, choose this attachment(overridden) from the select box on top, and then save the field. (this is to avoid recursion)
11. Override the attachment Contextual filters by adding Taxonomy term: Name (Parent relationship)
12. Add a view field (Global: View) to your view fields in the first first view.
13. Use the attachment in the view field config, and add the token for the term name (not the parent) as the contextual filter value sent to the attachment.
14. You can remove the relationship from the filter in step 4, this will display the top level in main display, so you can skip grouping (step 5), then add a new display for each level you want to display (control no. of levels to display)


Malformed image URL in Node Edport module in Drupal 7

If you are getting Malformed image URL in Node export. Then you have to change the code in Node Export module

Try to use image_create_url() instead of url() in node_export.module file: Line 1052

- $export_data = url($file->uri, array('absolute' => TRUE));
+ $export_data = file_create_url($file->uri, array('absolute' => TRUE));

Monday, March 17, 2014

Get the file size in Drupal

The following function is used to return the file size,

$file = file_load($fid)
echo filesize(drupal_realpath($file->uri));

url - it will return the file public url (public://filname.ext)
file_create_url() - it will return there relative url of the file (http://localhost/sites/default/files/filname.ext)
drupal_realpath() - it will return the absolute url of the file path.(sites/default/files/filename.ext)



Thursday, March 13, 2014

Find the text or value in MYSQL table using REGEXP

We can use REGEXP command to find the string value in MYSQL table.
SELECT * FROM <table> WHERE <column> REGEXP '<string>';

Ex: SELECT * FROM watchdog WHERE message REGEXP 'message'

Monday, February 24, 2014

Delete operation in Drupal 7

The following function is used to delete file and file usage in Drupal 7.
file_data($file);

The following db function is used to delete a record from a table in Drupal 7.
db_delete('table')->condition('field', $value->execute();

The following drupal function is used to delete a node in Drupal 7.
node_delete($nid);
Multiple node delete: node_multiple_delete(array($nid1, $nid2));

The following drupal function is used to delete a user in Drupal 7.
user_delete($uid);
Multiple user delete: user_multiple_delete(array($uid1, $uid2));

The following drupal function is used to delete a content type in Drupal 7.
node_type_delete($type);