Re-implement hook_requirements

Created on 5 April 2023, over 1 year ago
Updated 6 April 2023, over 1 year ago

Problem/Motivation

In 📌 Fix coding standards Needs work it was found the implementation of hook_requirements is responsible for a lot of code style violations. However, it does basically nothing, with the meat of the function commented out. We need to assess whether we need anything from this and re-implement it; doing this is outside the scope of 📌 Fix coding standards Needs work , where wil will simply remove it for now.

/**
 * Implements hook_requirements().
 */
function flag_requirements($phase) {

  $requirements = [];
  /*
  if ($phase == 'runtime') {
    if (\Drupal::moduleHandler()->moduleExists('translation') && !\Drupal::moduleHandler()->moduleExists('translation_helpers')) {
      $requirements['flag_translation'] = array(
        'title' => t('Flag'),
        'severity' => REQUIREMENT_ERROR,
        'description' => t('To have the flag module work with translations, you need to install and enable the <a href="http://drupal.org/project/translation_helpers">Translation helpers</a> module.'),
        'value' => t('Translation helpers module not found.'),
      );
    }
    if (\Drupal::moduleHandler()->moduleExists('session_api')) {
      if (file_exists('./robots.txt')) {
        $flag_path = url('flag') . '/';
        // We don't use url() because this may return an absolute URL when
        // language negotiation is set to 'domain'.
        $flag_path = parse_url($flag_path, PHP_URL_PATH);
        $robots_string = 'Disallow: ' . $flag_path;
        $contents = file_get_contents('./robots.txt');
        if (strpos($contents, $robots_string) === FALSE) {
          $requirements['flag_robots'] = array(
            'title' => t('Flag robots.txt problem'),
            'severity' => REQUIREMENT_WARNING,
            'description' => t('Flag module may currently be used with anonymous users, however the robots.txt file does not exclude the "@flag-path" path, which may cause search engines to randomly flag and unflag content when they index the site. It is highly recommended to add "@robots-string" to your robots.txt file (located in the root of your Drupal installation).', array('@flag-path' => $flag_path, '@robots-string' => $robots_string)),
            'value' => t('Search engines flagging content'),
          );
        }
      }
    }
  }
  */
  return $requirements;
}

Proposed resolution

Assess whether we still need anything from this implementation and if so, re-implement it. In the current version of the module, it does nothing.

Remaining tasks

  • Assess what we need from a hook_requirements(), if anything
  • Make the necessary changes
  • Review
  • Merge

User interface changes

Requirements checks listed in site status report (?)

API changes

None.

Data model changes

None.

📌 Task
Status

Needs work

Version

4.0

Component

Miscellaneous

Created by

🇳🇱Netherlands eelkeblok Netherlands 🇳🇱

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024