-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi page types #16
Open
rupertj
wants to merge
14
commits into
1.x
Choose a base branch
from
feature/1.x/2-multi-page-types
base: 1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Multi page types #16
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
08b3567
Moved special handling for directories out to a hook so other modules…
rupertj bc3c9e7
Updated services.yml to pass the new params.
rupertj 63cfb42
Made arg to alter hook nullable.
rupertj 4812935
Merge branch '1.x' into feature/1.x/2-multi-page-types
rupertj a9111c3
Code style fixes.
rupertj 47c403d
Added test coverage for support for multi-page content types, using l…
rupertj 1dfc083
phpcs
rupertj b0b0235
Added api.php to document the new hook.
rupertj 668d869
phpcs
rupertj 8581591
Moved to constructor property promotion.
rupertj 0c1a671
Better handling of menu items whose parent isn't a node. Added type h…
rupertj 6ca7f08
Renamed hook from hook_subsites_extra_current_node() to hook_localgov…
rupertj bf16040
Moved hooks implemented on behalf of other modules to their own file,…
rupertj 7dbdcc8
Merge branch '1.x' into feature/1.x/2-multi-page-types
rupertj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Hooks provided by the Locagov Subsites Extras module. | ||
*/ | ||
|
||
use Drupal\node\NodeInterface; | ||
|
||
/** | ||
* @addtogroup hooks | ||
* @{ | ||
*/ | ||
|
||
/** | ||
* Alter the current node, before subsite determination. | ||
* | ||
* This alter hook is called before we walk the menu tree to determine if we're | ||
* looking at a page in a subsite or not. | ||
* | ||
* It'll be passed the current node, acquired from routeMatch. If no node is | ||
* found there, this hook will be passed null. This gives the opportunity to | ||
* include non-node pages in a subsite if you wish. | ||
* | ||
* If you want to indicate that a subsite is not being viewed, set $node to | ||
* NULL. | ||
* | ||
* Usually, this hook will be used to use a property of the node passed, such as | ||
* a reference to another node (such as the parent node field for guides, | ||
* directories, etc) to swop out the current node for a different node, which is | ||
* in the menu and therefore part of a subsite. | ||
*/ | ||
function hook_localgov_subsites_extras_current_node_alter(?NodeInterface &$node) { | ||
if ($node instanceof NodeInterface && $node->hasField('field_parent')) { | ||
$parent = $node->field_parent->entity; | ||
if ($parent instanceof NodeInterface) { | ||
$node = $parent; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @} End of "addtogroup hooks". | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
services: | ||
localgov_subsites_extras.service: | ||
class: Drupal\localgov_subsites_extras\Service\SubsiteService | ||
arguments: ['@entity_type.manager', '@plugin.manager.menu.link', '@current_route_match', '@config.factory'] | ||
arguments: ['@config.factory', '@entity_type.manager', '@plugin.manager.menu.link', '@module_handler', '@current_route_match'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it better to make the code meet Drupal standards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drupal's code style rules don't let you implement hooks for other modules like I've done here, as they insist on the function prefix being the module name. This is just a temporary thing anyway, as I'd like to move those hooks to the modules that provide those types & fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just taking a quick look, would an event and event subscriber be better here? And then the module can provide appropriate events for known localgov drupal content types until we can agree on a place to move it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved the hooks to their own file. Putting them there instead of in the module means that phpcs doesn't enforce the "function names must start with the module name rule", so I can re-enable phpcs on them.
I'm not against moving from hooks to an event. I don't think it's obviously better though. What do you reckon @Polynya?