Problem/Motivation

The admin page provided by this module is not linked from any existing page. This page is not reachable from any navigation. So admin users who don't know the exact page path won't know the existence of the setting page of this module.

Proposed resolution

Add a menu item in hook_menu() to make the existing page "File system" /admin/config/media/file-system a tab.

Remaining tasks

Make a patch
Review the patch

User interface changes

A tab menu is added in the admin page "File sytem".

API changes

None.

Data model changes

None.

I'm not sure if this is a bug. If it's not a bug, please feel free to change the Category. Thanks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hgoto created an issue. See original summary.

hgoto’s picture

oadaeh’s picture

I found that adding the MENU_DEFAULT_LOCAL_TASK menu item was unnecessary and produced a superfluous Defaults tab.
Also, the description for the field on the admin page needs some correcting.
Attached is a patch that addresses both of those.

hgoto’s picture

@oadaeh thank you for joining this thread.

I tested your patch. It cleanly applies but doesn't add any link, I see. Don't we need to have at least one MENU_DEFAULT_LOCAL_TASK when we want to use MENU_LOCAL_TASK?

If you don't mind, I'd like you to share the capture of the page you realised. Thank you.

hgoto’s picture

loopduplicate’s picture

The way to render tabs is documented here:
https://api.drupal.org/api/drupal/modules!system!system.api.php/function...

The MENU_DEFAULT_LOCAL_TASK entry is needed. Here's an updated patch and interdiffs, with the hook_menu item indentation formatted for Drupal code standards. It also includes the description fix and end of file line break fix that was included in #3. I've also included a description, adapted from the module description, "Configure improved Token based file sorting and renaming functionality."

loopduplicate’s picture

OK, this conflicts with Transliteration. I'll update the patch.

loopduplicate’s picture

Here's a patch which checks to see if other modules have included a default. I used hook_menu_alter(), which was already implemented in an include file. I moved the hook to the main module file and broke out the functionality into two separate functions. I wish there was a way to check for default tasks.

The other option I thought of was to not create a tab, but instead create another main menu entry at admin/config/media/, "admin/config/media/filefield-paths". This would ensure that we don't conflict with other contrib modules and would simplify the code quite a bit. Anyway, that's just something to chew on.

loopduplicate’s picture

oadaeh’s picture

Okay, I see how Transliteration was causing me to incorrectly evaluate the situation.

However, the patch that @loopduplicate provided did not work correctly for me. I still had both a Defaults tab and a Settings tab, both of which were pointing to the same page. The reason is because $file_system_menu_items = $items['admin/config/media/file-system']; is specifying a single path, and it is not the path the Transliterate module uses, so the path the Transliterate module uses is not be found. I understand the path the Transliterate module uses cannot be specified explicitly, as that might include some other module doing the same thing.

It took me a while, but I was finally able to update the patch so that was fixed for me.

I also made a few other changes:

1. I moved the location in the file of filefield_paths_menu_alter_image(), because I didn't feel like the function I added to address the multiple tabs had a "proper" place, so I ordered the relevant functions based on execution order, beginning with filefield_paths_menu_alter().

2.

       // And if a type was specified...
-      && !empty($file_system_menu_item['type'])
+      && isset($file_system_menu_item['type'])
       // And if the type is a default menu local task...
       && $file_system_menu_item['type'] === MENU_DEFAULT_LOCAL_TASK

Technically speaking, MENU_CALLBACK evaluates to empty:

/**
 * Menu type -- A hidden, internal callback, typically used for API calls.
 *
 * Callbacks simply register a path so that the correct function is fired
 * when the URL is accessed. They do not appear in menus or breadcrumbs.
 */
define('MENU_CALLBACK', 0x0000);

Since the code really only cares about MENU_DEFAULT_LOCAL_TASK, this could be reverted, if desired, but the comment should be modified.

3.

-      'title' => 'Defaults',
+      'title' => 'Settings',

I think "Settings" is a more appropriate label for the tab.

4. I made a few other changes to comply with Drupal Coding Standards, but only to the code related to this patch.

oadaeh’s picture

@loopduplicate and I had a conversation out of the issue queue, and we believe that rather than jumping through all the hoops we are trying to get through, it would be easier to just place the menu item one level up the chain on the Configuration page.

I've attached a patch that does that, but also keeps the description fix on the admin page itself.

loopduplicate’s picture

The patch failed testing but I think it was a problem with the testbot. So, I re-queued the test.

loopduplicate’s picture

Status: Needs review » Reviewed & tested by the community

The patch in #11 looks good to me. What do you think, @hgoto? RTBC?

loopduplicate’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/filefield_paths.module
@@ -20,18 +20,14 @@
+    'type'             => MENU_NORMAL_ITEM,

MENU_NORMAL_ITEM is the default if type is not specified so we can omit this line. See https://api.drupal.org/api/drupal/modules!system!system.api.php/function... . "If the "type" element is omitted, MENU_NORMAL_ITEM is assumed."

oadaeh’s picture

Here's an updated patch without the menu type specification.

The last submitted patch, 16: filefield_paths-admin_page_visibility-2895026-16.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

loopduplicate’s picture

It makes no sense that the pathauto test would fail after this commit, but that's what the testbot says. Oye... re-requeueing :)

loopduplicate’s picture

Status: Needs review » Reviewed & tested by the community

OK, tests are passing. Marking as RTBC now.

hgoto’s picture

@oadaeh @loopduplicate thanks. I agree completely with you :)

+1 to RTBC.

DamienMcKenna’s picture