No port yet, sorry ;)

Just a quick information for whoever wants to try and port this module to Drupal 8.

It is no longer possible to redirect within hook_node_view().

Instead, a event listener on request, that comes immediately after the routing happened (REQUEST event, prio > 32), then, do something like this:

if ($request->attributes->has('_route') && $request->attributes->get('_route') == 'entity.node.canonical') {
  $node = $request->attributes->get('node');
  if ($node instanceof NodeInterface && $node->getType() == $node_type) {
    $event->setResponse(new RedirectResponse($url)
  }
}

404 and 403 should also be possible with this.

This has the advantage to be much more reliable than the hook and faster, because the check happens right after the route was identified, and the node does not need to be built at all

CommentFileSizeAuthor
#25 interdiff.txt362 bytesdylan donkersgoed
#25 port_rabbit_hole_to-2387673-25.patch167.3 KBdylan donkersgoed
#24 interdiff.txt1.87 KBdylan donkersgoed
#24 port_rabbit_hole_to-2387673-24.patch167.75 KBdylan donkersgoed
#23 interdiff.txt24.22 KBdylan donkersgoed
#23 port_rabbit_hole_to-2387673-23.patch168.54 KBdylan donkersgoed
#22 interdiff.txt1.84 KBdylan donkersgoed
#22 port_rabbit_hole_to-2387673-22.patch171.28 KBdylan donkersgoed
#21 interdiff-21-21.txt756 bytesvasi1186
#21 port_rabbit_hole_to-2387673-21.patch169.26 KBvasi1186
#20 interdiff.txt11.87 KBdylan donkersgoed
#20 port_rabbit_hole_to-2387673-20.patch169.24 KBdylan donkersgoed
#19 interdiff.txt1.12 KBdylan donkersgoed
#19 port_rabbit_hole_to-2387673-19.patch168.2 KBdylan donkersgoed
#18 interdiff.txt634 bytesdylan donkersgoed
#18 port_rabbit_hole_to-2387673-18.patch168.11 KBdylan donkersgoed
#17 interdiff.txt6.12 KBdylan donkersgoed
#17 port_rabbit_hole_to-2387673-17.patch168.08 KBdylan donkersgoed
#16 interdiff.txt2.8 KBdylan donkersgoed
#16 port_rabbit_hole_to-2387673-15.patch164.35 KBdylan donkersgoed
#14 interdiff.txt21.46 KBmparker17
#14 port_rabbit_hole_to-2387673-14.patch164.29 KBmparker17
#13 port_rabbit_hole_to-2387673-13.patch163.35 KBmparker17
#13 interdiff.txt26.92 KBmparker17
#12 interdiff.txt2.48 KBmparker17
#12 port_rabbit_hole_to-2387673-12.patch162.4 KBmparker17
#11 port_rabbit_hole_to-2387673-11.patch162.7 KBmparker17
#11 interdiff.txt58.42 KBmparker17
#10 interdiff.txt20.19 KBmparker17
#10 port_rabbit_hole_to-2387673-10.patch161.2 KBmparker17
#4 port_rabbit_hole_to-2387673-4.patch71.08 KBmparker17
#5 port_rabbit_hole_to-2387673-5.patch71.61 KBmparker17
#5 interdiff.txt17.44 KBmparker17
#6 port_rabbit_hole_to-2387673-6.patch79.83 KBdylan donkersgoed
#6 interdiff.txt7.62 KBdylan donkersgoed
#7 port_rabbit_hole_to-2387673-7.patch126.83 KBdylan donkersgoed
#7 interdiff.txt60.38 KBdylan donkersgoed
#8 port_rabbit_hole_to-2387673-8.patch153.82 KBdylan donkersgoed
#8 interdiff.txt40.28 KBdylan donkersgoed
#9 port_rabbit_hole_to-2387673-9.patch173.32 KBdylan donkersgoed
#9 interdiff.txt38.59 KBdylan donkersgoed

Comments

olofbokedal’s picture

Nice with some initial information! I'm planning on starting the 8.x version somewhere in january/february, if no one else starts before.

I'm guessing that the entire module will need a huge overhaul.

ttamniwdoog’s picture

Has anyone started this? I have interest and am working on a lite version of this for D8 now.

francewhoa’s picture

Title: Drupal 8 » Port Rabbit Hole to Drupal 8
Issue tags: +Drupal 8

We would be happy to contribute testing patch, quality assurance, documentation, and agile project management services if needed

Any additional volunteers to join the efforts to port Rabbit Hole module from Drupal 7 to 8?

Related pages

mparker17’s picture

StatusFileSize
new71.08 KB

I've started porting the module, but it's HIGHLY incomplete (at this point, it doesn't even pass it's own tests and there's no real functionality).

I plan to continue working on this, but progress will be slow (as I can only work on this during the weekends)

***

My basic design goals here are:

  1. Make the different behaviors into plugins - this differs from the D7 version, where they're not defined by hooks, but I figured they are simple enough that I could start learning plugins (in progress)
  2. Make the different entities which can be rabbit-holed into plugins - this matches the D7 version which defines them by hooks (not started)
  3. Make a 7.x-3.x patch that's structured similarly to the Drupal 8 version, so features added to D8 can be backported relatively easily (not started, optional)
mparker17’s picture

StatusFileSize
new71.61 KB
new17.44 KB

Still highly incomplete, but at least I can get tests to pass and the behavior plugins to work properly.

dylan donkersgoed’s picture

StatusFileSize
new79.83 KB
new7.62 KB

I'm adding a small continuation of mparker17's work. This patch starts converting the old variable system to Drupal 8's new configuration management API.

dylan donkersgoed’s picture

StatusFileSize
new126.83 KB
new60.38 KB

I've added a significant chunk of new work to improve the configuration and get the forms working for nodes for basic actions. The redirect options aren't fully configured yet. Most of the infrastructure for the entity plugin system doesn't exist yet. A couple lines are just hardcoded for nodes at the moment.

Next I plan to tie together the form and mparker17's behavior plugins to get something actually functional (i.e. visit a node and have a behavior plugin run based on which action is selected). This is the bit mentioned in the description of the issue. After that I plan on getting the redirect options working. At that point I'll likely post another update to this issue.

dylan donkersgoed’s picture

StatusFileSize
new153.82 KB
new40.28 KB

Sorry about the long delay for this one.

What's New
Some simple behaviors are actually invoked now - access denied, display page, page not found, and redirects (kinda) can be configured for nodes (including content type defaults) and will actually be invoked.

The redirect code is necessarily very different from the Drupal 7 code. You can see it hooks into the request in src/EventSubscriber/RabbitHoleSubscriber, how the plugins are loaded and invoked in src/BehaviorInvoker.php and what actually happens in the src/Plugin/PageRedirect.php. There's some stuff in there that I'm not 100% sure of (especially regarding 304 and 305 redirects) and I'd be interested in opinions on it/alternate suggestions.

mparker17: I modified/expanded your plugin system in this patch. Notably the redirect plugin has been changed significantly and there are some new methods + new arguments in many of the method headers. I'd be interested in hearing your thoughts on that. There are some parts that I'm not certain I did in the way you originally intended with your plugin system.

What's Next

Next I plan to get the plugin system for adding rabbit hole to different entity types working. Likely my next patch will have the basic structure of it, a node implementation and probably one other entity implementation or partial implementation to make sure it works properly.

Other Stuff To Do

There are some other things that need to be done that probably won't be done in my next patch, including:

  • Redirects need to have support added for tokens and PHP code
  • No permissions/security checks have been implemented
  • The rabbit hole config entities associated with the bundles aren't influenced by the plugins (they always have the redirect info) whereas the entity schema is - probably both should be
dylan donkersgoed’s picture

StatusFileSize
new38.59 KB
new173.32 KB

New patch. The entity plugin system is now more functional with implementations for node and user. Nodes work pretty much the same as before but now they use the entity plugin system more. There's a related new feature in the entity plugin system which is used by the user implementation - a global configuration form for all entities of a type, accessible from the account settings form like in Drupal 7.

Next I'm planning to set up the permissions and security checks that used to exist. I'm hoping that won't take too long but I'm not sure when I'll get to it. That should bring the module to a usable state I think, though of course it won't have all the features the Drupal 7 version does yet.

mparker17’s picture

StatusFileSize
new161.2 KB
new20.19 KB

Removed most code which has been commented-out.

mparker17’s picture

StatusFileSize
new58.42 KB
new162.7 KB

Run phpcbf --standard=Drupal . and phpcbf --standard=DrupalPractice . to fix the easiest coding-standards violations.

mparker17’s picture

StatusFileSize
new162.4 KB
new2.48 KB

phpcs --standard=DrupalPractice . identified a bunch of variables that were being assigned to but never used; and also an instance where we were checking isset($x) ? $x : $y when $x had never been assigned and thus could never exist.

mparker17’s picture

StatusFileSize
new26.92 KB
new163.35 KB

Started fixing issues identified by phpcs --standard=Drupal .

(still more to do, I just ran out of time).

mparker17’s picture

StatusFileSize
new164.29 KB
new21.46 KB

Finished fixing issues identified by phpcs --standard=Drupal .

rooby’s picture

Is there a todo list for what is remaining to complete this patch or is it ready for review?

dylan donkersgoed’s picture

StatusFileSize
new164.35 KB
new2.8 KB

There were some renaming issues with the standards compliance fixes, adding a patch to fix those.

dylan donkersgoed’s picture

StatusFileSize
new168.08 KB
new6.12 KB

Adding a patch with the per-entity rabbit hole permissions now. I think it may work a little differently than the Drupal 7 version - it's based on the entity types covered by the plugin. This should be functionally the same for the bundled modules but I'm not sure if it might have other implications.

dylan donkersgoed’s picture

StatusFileSize
new168.11 KB
new634 bytes

Adding a patch to fix a bug in a test related to the previous patch.

dylan donkersgoed’s picture

StatusFileSize
new168.2 KB
new1.12 KB

Adding a patch to fix a bug that could cause uninstall to fail.

dylan donkersgoed’s picture

StatusFileSize
new169.24 KB
new11.87 KB

Adding a patch to make entities respect redirect configuration of bundles when configured to use bundle action with bundle action being redirect.

The module should currently technically be functional. Here's a summary of what I think the status is:

  • Plugins can be created to implement rabbit hole settings for entities, entity bundles and entity types globally
  • A submodule (with plugin) is implemented that allows configuration of nodes and node types
  • A submodule (with plugin) is implemented that allows configuration of users and global user settings
  • Submodules need to be added for taxonomy terms and file entities still, but a taxonomy term one will probably be pushed up pretty soon
  • Permissions are implemented
  • Support for tokens in redirects is NOT implemented
  • Some of the plugin-ish functionality from the Drupal 7 rabbit hole is not yet implemented - e.g. plugins can't add their own submit handlers via the plugin itself
  • There are some things about the code that are functional but I think could be improved (e.g .configuration entities aren't changed by behaviour plugins but entity schema is)
  • Test coverage could be greatly improved and some of it should probably be shifted to proper unit testing
  • There are some coding standards issues that should be fixed
vasi1186’s picture

StatusFileSize
new169.26 KB
new756 bytes

I had some issue when trying to redirect to the frontpage. I attached a new patch which should solve this.

dylan donkersgoed’s picture

StatusFileSize
new171.28 KB
new1.84 KB

I'm attaching a patch to add a rh_taxonomy module, courtesy of one of my co-workers who declined to upload it/be tagged on it. This is a good example of a simple implementation of submodules for new entities. File entity support still needs to be implemented.

dylan donkersgoed’s picture

StatusFileSize
new168.54 KB
new24.22 KB

I'm attaching a patch with some Drupal standards and best practices fixes.

dylan donkersgoed’s picture

StatusFileSize
new167.75 KB
new1.87 KB

Another quick patch to remove some done TODOs and move the token TODO to a more appropriate place in the code.

dylan donkersgoed’s picture

StatusFileSize
new167.3 KB
new362 bytes

I'm adding a simple patch that brings in the README from the D7 repo. I haven't made any changes to the actual file as there's not really anything Drupal 8 specific in there. There's definitely room for improvement, but I think the module is ready for some wider usage/testing.

olofjohansson: If you think it's ready, could you please create an 8.x branch for this port?

itsekhmistro’s picture

Priority: Normal » Critical

Please create 8.x branch from the Patch attached in comment #25.

The patch has been tested and works pretty well as for me. It will be much easier to continue development in git branch.

  • olofjohansson committed e6628d4 on 8.x-1.x
    Issue #2387673 by Dylan Donkersgoed, mparker17: Port Rabbit Hole to...
olofbokedal’s picture

Hey guys!

Sorry for my absence and late response, but I'd just wanted to let you know that I've created a branch for 8.x where I applied the patch from #25. I've also added Dylan and mparker17 as co-maintainers (based on number of patches) with permissions to write to VCS, maintain issues and releases. Please let me know if there's someone else that should get access. I've just created an initial dev release of 8.x-1.x, should be visible on the project page soon enough.

Great work guys! The community really appreciates your effort :)

Feel free to close this issue whenever you're satisfied with the initial port.

mparker17’s picture

Cool! Thanks! I think @Dylan Donkersgoed deserves most of the credit though; I just helped clean up a bit.

luksak’s picture

Works great so far. Should we close this an start creating separate issues?

temkin’s picture

Status: Active » Closed (fixed)

I think it's fair to say that the module was successfully ported to D8. Me and a few other people are already using it in production mode. Therefore I'm closing this ticket and we can have separate issues for all other bugfixes and changes.

Thanks everyone!