From f7ff5a6379c036d1533da282125373528829e9b4 Mon Sep 17 00:00:00 2001 From: protitude Date: Mon, 2 Jan 2023 19:09:39 +0000 Subject: [PATCH] src: adding plugin AddToRobots so I can run in drush --- oit_dev.install | 18 +++--------------- src/Plugin/AddToRobots.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 src/Plugin/AddToRobots.php diff --git a/oit_dev.install b/oit_dev.install index e55199f..86deb42 100644 --- a/oit_dev.install +++ b/oit_dev.install @@ -6,6 +6,7 @@ */ use Drupal\servicenow\Plugin\ServicenowUserLookup; +use Drupal\oit_dev\Plugin\AddToRobots; /** * Implements hook_install(). @@ -38,21 +39,8 @@ function oit_dev_install() { $this_user->set('field_service_meow_dds_pod_group', $pod_group); $this_user->save(); } - // Pull in archived news to add to add to robots.txt - $news_archive = \Drupal::entityQuery('node'); - $news_archive->condition('field_news_archive', 3); - $news_results = $news_archive->execute(); - $news_archive_string = "# Paths OIT\n"; - $news_archive_string .= "Disallow: /taxonomy/term/*\n"; - $news_archive_string .= "Disallow: /node?page=*\n"; - $news_archive_string .= "Disallow: /tutorial/hotmail-configure-outlook-windows?page=2\n"; - $news_archive_string .= "Disallow: /tutorial/hotmail-configure-outlook-windows?page=3\n"; - $news_archive_string .= "Disallow: /it-security/email-phishing/*\n"; - $news_archive_string .= "# Archived news nodes\n"; - foreach ($news_results as $news_result) { - $news_archive_string .= "Disallow: /node/$news_result\n"; - } - file_put_contents('../add-to-robots.txt', $news_archive_string); + // Pull in archived news to add to add to robots.txt. + new AddToRobots(); } /** diff --git a/src/Plugin/AddToRobots.php b/src/Plugin/AddToRobots.php new file mode 100644 index 0000000..3752c5c --- /dev/null +++ b/src/Plugin/AddToRobots.php @@ -0,0 +1,31 @@ +condition('field_news_archive', 3); + $news_results = $news_archive->execute(); + $news_archive_string = "# Paths OIT\n"; + $news_archive_string .= "Disallow: /taxonomy/term/*\n"; + $news_archive_string .= "Disallow: /node?page=*\n"; + $news_archive_string .= "Disallow: /tutorial/hotmail-configure-outlook-windows?page=2\n"; + $news_archive_string .= "Disallow: /tutorial/hotmail-configure-outlook-windows?page=3\n"; + $news_archive_string .= "Disallow: /it-security/email-phishing/*\n"; + $news_archive_string .= "# Archived news nodes\n"; + foreach ($news_results as $news_result) { + $news_archive_string .= "Disallow: /node/$news_result\n"; + } + file_put_contents('../add-to-robots.txt', $news_archive_string); + return 'Created maybe'; + } + +}