diff --git a/entity_operations.api.php b/entity_operations.api.php index 46f5256382a76e37226b3943a6b40da1c5e61182..7a5f23ffb17e4d09ebf7c987f5dff904eea3b0c2 100644 --- a/entity_operations.api.php +++ b/entity_operations.api.php @@ -74,6 +74,18 @@ function entity_operations_hook_entity_info() { * one operation may be the default. This causes it to respond to the * base URI of the entity, ie 'base_path/%wildcard'. For nodes, the * 'view' operation would be the default. + * - 'default secondary': (optional) If the operation name contains a + * '/', the setting this to TRUE causes this operation to be the + * default in the secondary tab set implicitly formed by the first + * part of the name. For example, 'foo/bar' and 'foo/biz' form a + * secondary tab set at the subpath 'foo', and one of the two should + * be marked as default secondary, so that it is output at 'foo' (and + * thus there should be no operation defined for 'foo'). + * Note that it is possible for one such secondary item to also be + * marked as 'default', in which case the entity URI will output it. + * - 'parent tab title': (optional) Can be set on a secondary-level + * operation which has 'default' set to define the tab title for the + * containing primary-level tab that is automatically created. * - 'menu item': (optional) An array of properties suitable for * hook_menu(), to use for this operation's menu item. These override * those provided by the handler. diff --git a/includes/entity.operations.inc b/includes/entity.operations.inc index 80f179079b997f18bc9af2ffc349527180de9e90..c09948d3fc26008289663987c32e349c4c2ac67b 100755 --- a/includes/entity.operations.inc +++ b/includes/entity.operations.inc @@ -79,7 +79,7 @@ class EntityOperationsDefaultUIController { $menu_item += array( 'title' => $title, - 'type' => isset($operation_definition['provision']['menu']['default']) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK, + 'type' => MENU_LOCAL_TASK, 'load arguments' => array($this->entityType), 'weight' => $this->weight, // Very rarely, handlers may wish to set this (such as 'add'), so we @@ -97,14 +97,45 @@ class EntityOperationsDefaultUIController { // Increase the weight for the next menu item. $this->weight++; + // Handle default tabs. // The default operation also gets to be the parent tab. if (!empty($operation_definition['provision']['menu']['default'])) { + // Copy the item to make the base item. $base_item = $menu_item; - $base_item['title'] = 'View'; // Won't get used. + + // The item itself is made the default tab. + $items[$path]['type'] = MENU_DEFAULT_LOCAL_TASK; + + $base_item['title'] = 'View'; // Won't get used. TODO $base_item['type'] = MENU_NORMAL_ITEM; $items[$this->base_path] = $base_item; } + + // Secondary parent tabs, which are themselves a primary tab. + if (!empty($operation_definition['provision']['menu']['default secondary'])) { + // Copy the item to make the base item. + $base_item = $menu_item; + + // The item itself is made the default tab. + $items[$path]['type'] = MENU_DEFAULT_LOCAL_TASK; + + list($root, ) = explode('/', $operation_path); + $expected_parent_path = $this->base_path . '/' . $root; + + // The parent item takes the default tab's title, unless something else + // is specified in the operation definition. + if (!empty($operation_definition['provision']['menu']['parent tab title'])) { + $base_item['title'] = $operation_definition['provision']['menu']['parent tab title']; + } + + // The base item can itself be a default tab in the primary tabs. + if (!empty($operation_definition['provision']['menu']['default'])) { + $base_item['type'] = MENU_DEFAULT_LOCAL_TASK; + } + + $items[$expected_parent_path] = $base_item; + } } return $items;