From fafade6a8a5d54e025935156e4119b4dcf1a84e3 Mon Sep 17 00:00:00 2001 From: twistor <twistor@473738.no-reply.drupal.org> Date: Tue, 29 Mar 2016 10:37:39 +0200 Subject: [PATCH] Issue #2382245 by MegaChriz, twistor: Added import links to the admin menu. --- feeds.module | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/feeds.module b/feeds.module index 41122b4f..27b69fd7 100644 --- a/feeds.module +++ b/feeds.module @@ -845,6 +845,69 @@ function feeds_flush_caches() { return array(); } +/** + * Implements hook_admin_menu_output_build(). + * + * Shows available importers in the "Content" section of the admin menu. + * Requires the "admin_menu" module to be enabled. + */ +function feeds_admin_menu_output_build(array &$content) { + // Add new top-level item to the menu. + if (!isset($content['menu'])) { + return; + } + $access = FALSE; + foreach (feeds_enabled_importers() as $importer_id) { + if (user_access('administer feeds') || user_access("import $importer_id feeds")) { + $access = TRUE; + break; + } + } + + if (!$access) { + return; + } + + $content['menu']['admin/content']['admin/content/feeds_import'] = array( + '#title' => t('Import'), + '#href' => 'import', + ); + + foreach (feeds_importer_load_all() as $importer) { + $content['menu']['admin/content']['admin/content/feeds_import'][$importer->id] = array( + '#title' => t($importer->config['name']), + '#href' => !empty($importer->config['content_type']) ? 'node/add/' . $importer->config['content_type'] : 'import/' . check_plain($importer->id), + '#access' => user_access('administer feeds') || user_access("import $importer->id feeds"), + ); + } +} + +/** + * Implements hook_menu_local_tasks_alter(). + * + * Adds "Import" link as local action on content overview page. + */ +function feeds_menu_local_tasks_alter(&$data, $router_item, $root_path) { + if ($root_path == 'admin/content') { + $data['actions']['output'][] = array( + '#theme' => 'menu_local_task', + '#link' => array( + 'title' => t('Import'), + 'href' => 'import', + 'localized_options' => array( + 'attributes' => array( + 'title' => t('Import'), + ), + ), + ), + '#access' => feeds_page_access(), + // Add weight so it appears after the local action "Add content". + '#weight' => 1, + ); + } +} + + /** * @} */ -- GitLab