Skip to content

Commit

Permalink
Merge pull request #7 from SU-SWS/8.1.0-release
Browse files Browse the repository at this point in the history
8.1.0
  • Loading branch information
sherakama authored Oct 30, 2019
2 parents bd7d9ae + 8e7e36b commit 07fb758
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Nobots

8.x-1.0 2019-10-30
--------------------------------------------------
- Initial release.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[No Bots](https://github.com/SU-SWS/nobots)
##### Version: 8.x-1.0-dev
# [No Bots](https://github.com/SU-SWS/nobots)
##### Version: 8.x

Maintainers: [jbickar](https://github.com/jbickar), [sherakama](https://github.com/sherakama), [pookmish](https://github.com/pookmish)
[Changelog.txt](CHANGELOG.txt)
Expand Down Expand Up @@ -29,6 +29,8 @@ You can set the `nobots` variable to **FALSE** to leave the module enabled, yet

An example use-case would be to set `$settings['nobots'] = FALSE;` in settings.php for the production environment, and `TRUE` for all other environments.

You can also set the state `nobots` to **FALSE**. `drush state:set nobots 0` would set this state to false.

Troubleshooting
---

Expand Down
3 changes: 2 additions & 1 deletion nobots.info.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: No Bots
type: module
description: 'Blocks (well-behaved) search engine robots from crawling, indexing, or archiving your site.'
version: 8.x-1.0-dev
version: 8.x-1.0
core: 8.x
core_version_requirement: ^8 || ^9
package: Stanford
1 change: 1 addition & 0 deletions nobots.services.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
services:
nobots.finish_response_subscriber:
class: Drupal\nobots\EventSubscriber\FinishResponseSubscriber
arguments: ['@state']
tags:
- { name: event_subscriber }
20 changes: 19 additions & 1 deletion src/EventSubscriber/FinishResponseSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\nobots\EventSubscriber;

use Drupal\Core\State\StateInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
Expand All @@ -12,6 +13,23 @@
*/
class FinishResponseSubscriber implements EventSubscriberInterface {

/**
* State service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;

/**
* FinishResponseSubscriber constructor.
*
* @param \Drupal\Core\State\StateInterface $state
* State service.
*/
public function __construct(StateInterface $state) {
$this->state = $state;
}

/**
* {@inheritdoc}
*/
Expand All @@ -27,7 +45,7 @@ public static function getSubscribedEvents() {
* The event to process.
*/
public function onRespond(FilterResponseEvent $event) {
if (Settings::get('nobots', TRUE)) {
if (Settings::get('nobots', TRUE) && $this->state->get('nobots', TRUE)) {
$response = $event->getResponse();
$response->headers->set('X-Robots-Tag', 'noindex,nofollow,noarchive', FALSE);
}
Expand Down

0 comments on commit 07fb758

Please sign in to comment.