kopia lustrzana https://github.com/wagtail/wagtail
				
				
				
			Add construct_page_action_menu hook
							rodzic
							
								
									6adf7c8423
								
							
						
					
					
						commit
						2a477c8e79
					
				|  | @ -533,6 +533,20 @@ Hooks for customising the way users are directed through the process of creating | |||
|         return GuacamoleMenuItem(order=10) | ||||
| 
 | ||||
| 
 | ||||
| .. _construct_page_action_menu: | ||||
| 
 | ||||
| ``construct_page_action_menu`` | ||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||
| 
 | ||||
|   Modify the final list of action menu items on the page creation and edit views. The callable passed to this hook receives a list of ``ActionMenuItem`` objects, a request object and a context dictionary as per ``register_page_action_menu_item``, and should modify the list of menu items in-place. | ||||
| 
 | ||||
|   .. code-block:: python | ||||
| 
 | ||||
|     @hooks.register('construct_page_action_menu') | ||||
|     def remove_submit_to_moderator_option(menu_items, request, context): | ||||
|         menu_items[:] = [item for item in menu_items if item.name != 'action-submit'] | ||||
| 
 | ||||
| 
 | ||||
| .. _construct_wagtail_userbar: | ||||
| 
 | ||||
| ``construct_wagtail_userbar`` | ||||
|  |  | |||
|  | @ -410,6 +410,9 @@ def page_action_menu(context, menu_items, **kwargs): | |||
|     ] | ||||
|     visible_menu_items.sort(key=lambda item: item.order) | ||||
| 
 | ||||
|     for hook in hooks.get_hooks('construct_page_action_menu'): | ||||
|         hook(visible_menu_items, context['request'], menu_item_context) | ||||
| 
 | ||||
|     return { | ||||
|         'show_menu': bool(visible_menu_items), | ||||
|         'rendered_menu_items': [ | ||||
|  |  | |||
|  | @ -665,6 +665,8 @@ class TestPageCreation(TestCase, WagtailTestUtils): | |||
|         self.assertContains(response, '<a href="#tab-promote" class="">Promote</a>') | ||||
|         # test register_page_action_menu_item hook | ||||
|         self.assertContains(response, '<input type="submit" name="action-panic" value="Panic!" class="button" />') | ||||
|         # test construct_page_action_menu hook | ||||
|         self.assertContains(response, '<input type="submit" name="action-relax" value="Relax." class="button" />') | ||||
| 
 | ||||
|     def test_create_multipart(self): | ||||
|         """ | ||||
|  | @ -1279,6 +1281,9 @@ class TestPageEdit(TestCase, WagtailTestUtils): | |||
|         # test register_page_action_menu_item hook | ||||
|         self.assertContains(response, '<input type="submit" name="action-panic" value="Panic!" class="button" />') | ||||
| 
 | ||||
|         # test construct_page_action_menu hook | ||||
|         self.assertContains(response, '<input type="submit" name="action-relax" value="Relax." class="button" />') | ||||
| 
 | ||||
|     def test_edit_draft_page_with_no_revisions(self): | ||||
|         # Tests that the edit page loads | ||||
|         response = self.client.get(reverse('wagtailadmin_pages:edit', args=(self.unpublished_page.id, ))) | ||||
|  |  | |||
|  | @ -115,3 +115,13 @@ class PanicMenuItem(ActionMenuItem): | |||
| @hooks.register('register_page_action_menu_item') | ||||
| def register_panic_menu_item(): | ||||
|     return PanicMenuItem() | ||||
| 
 | ||||
| 
 | ||||
| class RelaxMenuItem(ActionMenuItem): | ||||
|     label = "Relax." | ||||
|     name = 'action-relax' | ||||
| 
 | ||||
| 
 | ||||
| @hooks.register('construct_page_action_menu') | ||||
| def register_relax_menu_item(menu_items, request, context): | ||||
|     menu_items.append(RelaxMenuItem()) | ||||
|  |  | |||
		Ładowanie…
	
		Reference in New Issue
	
	 Matt Westcott
						Matt Westcott