diff --git a/CHANGELOG.txt b/CHANGELOG.txt new file mode 100644 index 0000000..159bb96 --- /dev/null +++ b/CHANGELOG.txt @@ -0,0 +1,5 @@ +Nobots + +8.x-1.0 2019-10-30 +-------------------------------------------------- +- Initial release. diff --git a/README.md b/README.md index 3df73cf..3526cf5 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 --- diff --git a/nobots.info.yml b/nobots.info.yml index 8c5cb40..58201bb 100644 --- a/nobots.info.yml +++ b/nobots.info.yml @@ -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 diff --git a/nobots.services.yml b/nobots.services.yml index 1b0e2c7..aab06e9 100644 --- a/nobots.services.yml +++ b/nobots.services.yml @@ -1,5 +1,6 @@ services: nobots.finish_response_subscriber: class: Drupal\nobots\EventSubscriber\FinishResponseSubscriber + arguments: ['@state'] tags: - { name: event_subscriber } diff --git a/src/EventSubscriber/FinishResponseSubscriber.php b/src/EventSubscriber/FinishResponseSubscriber.php index 60df1f1..0ac2ddc 100644 --- a/src/EventSubscriber/FinishResponseSubscriber.php +++ b/src/EventSubscriber/FinishResponseSubscriber.php @@ -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; @@ -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} */ @@ -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); }