📜 ⬆️ ⬇️

Bulk import of panels from the module

It has long been taken as a rule to make all changes to the site through the code. Now I got to the panels (module panels ).
If you need to import a large number of panels, you can use the features module. The only thing that is not convenient is that this module exports all panels to one file, and then it is rather difficult to work with this file.

It is much more convenient to have a certain import / folder and add panels there, each in its own file. In this case, if necessary, it is very easy to edit any panels, as well as track changes (if you of course use a version control system, such as SVN or GIT).

I could not find anything like this, so I wrote my own little module with blackjack and import.

First you need to create all the files for the module. It looks like this:

Now using the mechanism of the Features module, we import all panels from the folder.
')
panels_import.module:
/** * Implementation of hook_ctools_plugin_directory(). */ function panels_import_ctools_plugin_directory($module, $plugin) { if ($module == 'panels_import' && !empty($plugin)) { return $plugin; } } /** * Implement hook_ctools_plugin_api(). */ function panels_import_ctools_plugin_api($module, $api) { if ($module == 'page_manager' && $api == 'pages_default') { return array('version' => 1); } } 


panels_import.pages_default.inc:
 function panels_import_default_page_manager_pages() { $pages = array(); // scan directory for imports files $dir = drupal_get_path('module', 'panels_import') .'/import'; $files = file_scan_directory($dir, '.*', array('.', '..', 'CVS', 'README.txt'), 0, FALSE); foreach ($files as $file) { // load each one files $export_data = file_get_contents($file->filename); eval($export_data); // and add to array $pages[$page->name] = $page; } return $pages; } 


Now you can export any panels and save them to files inside the import / folder.


Download the working version of the module here .

I will be glad to read your comments. Thank.

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


All Articles