📜 ⬆️ ⬇️

Import views from module


The thing is very convenient, because it allows you to push everything you need into the module for work; you do not need to manually run, export / import views.

The implementation of mega is simple, although for me it was not obvious. I am sure someone will also be interested / useful how to do it.


')
A view has an “Export” button that allows you to copy the text of the exported view.


Now in the folder with the module you need to create the file module_name.views_default.inc and write the following to it:
<?php
/**
* Implementation of hook_views_default_views().
*/
function module_name_views_default_views() {
// ,

$views[$view->name] = $view;

return $views;
}

this way you can insert any number of nodes into the $ views array.

In the module file itself, it is now necessary to describe hook_views_api ()
/**
* Implementation of hook_views_api().
*/
function module_name_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'module_name'),
);
}


Everything, we activate the module and we rejoice.

ps I hope everyone will guess instead of module_name you need to insert the name of your module.

Source: https://habr.com/ru/post/108990/


All Articles